-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from matobet/v2v-network-automate
v2v: Add automate methods for post-import network configuration (cherry picked from commit 4167dfa) https://bugzilla.redhat.com/show_bug.cgi?id=1459996
- Loading branch information
1 parent
13d9967
commit 3863ee5
Showing
6 changed files
with
112 additions
and
5 deletions.
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
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