-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2v: Add automate methods for post-import network configuration #123
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...astructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# | ||
# Description: This method initiates post-import configuration of VM network interfaces. | ||
# | ||
|
||
module ManageIQ | ||
module Automate | ||
module Infrastructure | ||
module VM | ||
module Transform | ||
module StateMachines | ||
class ConfigureVmNetworks | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def main | ||
validate_root_args %w(provider_id) | ||
|
||
provider = @handle.vmdb(:ext_management_system, @handle.root['provider_id']) | ||
vm_id = @handle.get_state_var('imported_vm_id') | ||
@handle.log(:info, "Configuring VM ID: #{vm_id} Networks") | ||
provider.submit_configure_imported_vm_networks(@handle.root['user'].userid, vm_id) | ||
end | ||
|
||
def validate_root_args(arg_names) | ||
arg_names.each do |name| | ||
next if @handle.root[name].present? | ||
msg = "Error, required root attribute: #{name} not found" | ||
@handle.log(:error, msg) | ||
raise msg | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if __FILE__ == $PROGRAM_NAME | ||
ManageIQ::Automate::Infrastructure::VM::Transform::StateMachines::ConfigureVmNetworks.new.main | ||
end |
12 changes: 12 additions & 0 deletions
12
...tructure/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
object_type: method | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: configure_vm_networks | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
inputs: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ def main | |
status = vm.custom_get(:import_status) | ||
case status | ||
when 'success' | ||
@handle.set_state_var('imported_vm_id', vm.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matobet, can we update the spec test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tinaafitz done |
||
@handle.root['ae_result'] = 'ok' | ||
when 'failure' | ||
@handle.root['ae_result'] = 'error' | ||
|
29 changes: 29 additions & 0 deletions
29
...cture/VM/Transform/StateMachines/VmImport.class/__methods__/configure_vm_networks_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require_domain_file | ||
|
||
describe ManageIQ::Automate::Infrastructure::VM::Transform::StateMachines::ConfigureVmNetworks do | ||
let(:user) { FactoryGirl.create(:user_admin) } | ||
let(:provider) { FactoryGirl.create(:ems_redhat) } | ||
|
||
let(:svc_model_user) { MiqAeMethodService::MiqAeServiceUser.find(user.id) } | ||
let(:svc_model_provider) { MiqAeMethodService::MiqAeServiceManageIQ_Providers_Redhat_InfraManager.find(provider.id) } | ||
|
||
let(:root_object) do | ||
Spec::Support::MiqAeMockObject.new( | ||
:user => svc_model_user, | ||
:name => 'my_vm', | ||
:provider_id => provider.id | ||
) | ||
end | ||
|
||
let(:vm_id) { 42 } | ||
|
||
let(:ae_service) { Spec::Support::MiqAeMockService.new(root_object, 'imported_vm_id' => vm_id) } | ||
|
||
it 'Calls :submit_import_vm on the provider object with correct params' do | ||
allow(ae_service).to receive(:vmdb).with(:ext_management_system, provider.id).and_return(svc_model_provider) | ||
|
||
expect(svc_model_provider).to receive(:submit_configure_imported_vm_networks).with(user.userid, vm_id) | ||
|
||
described_class.new(ae_service).main | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matobet Can we add a test for this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tinaafitz done