forked from ManageIQ/manageiq-content
-
Notifications
You must be signed in to change notification settings - Fork 0
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 ManageIQ#36 from matobet/v2v-automate
Add automate methods for VM import between providers
- Loading branch information
Showing
35 changed files
with
1,164 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
content/automate/ManageIQ/Infrastructure/VM/Transform/Import.class/__class__.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,53 @@ | ||
--- | ||
object_type: class | ||
version: 1.0 | ||
object: | ||
attributes: | ||
description: | ||
display_name: | ||
name: Import | ||
type: | ||
inherits: | ||
visibility: | ||
owner: | ||
schema: | ||
- field: | ||
aetype: attribute | ||
name: vm_id | ||
display_name: | ||
datatype: string | ||
priority: 1 | ||
owner: | ||
default_value: | ||
substitute: true | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: | ||
on_exit: | ||
on_error: | ||
max_retries: | ||
max_time: | ||
- field: | ||
aetype: method | ||
name: execute | ||
display_name: | ||
datatype: string | ||
priority: 2 | ||
owner: | ||
default_value: create_vm_import_request | ||
substitute: true | ||
message: create | ||
visibility: | ||
collect: | ||
scope: | ||
description: | ||
condition: | ||
on_entry: | ||
on_exit: | ||
on_error: | ||
max_retries: | ||
max_time: |
57 changes: 57 additions & 0 deletions
57
...ManageIQ/Infrastructure/VM/Transform/Import.class/__methods__/create_vm_import_request.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,57 @@ | ||
# | ||
# Description: This method initiates VM import to given infra provider | ||
# | ||
|
||
module ManageIQ | ||
module Automate | ||
module Infrastructure | ||
module VM | ||
module Transform | ||
module Import | ||
class CreateVmImportRequest | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def main | ||
validate_root_args %w(vm dialog_name dialog_provider dialog_cluster dialog_storage dialog_sparse) | ||
|
||
options = { | ||
:namespace => 'Infrastructure/VM/Transform/StateMachines', | ||
:class_name => 'VmImport', | ||
:instance_name => 'default', | ||
:message => 'create', | ||
:attrs => { | ||
'Vm::vm' => @handle.root['vm'].id, | ||
'name' => @handle.root['dialog_name'], | ||
'provider_id' => @handle.root['dialog_provider'], | ||
'cluster_id' => @handle.root['dialog_cluster'], | ||
'storage_id' => @handle.root['dialog_storage'], | ||
'sparse' => @handle.root['dialog_sparse'], | ||
}, | ||
:user_id => @handle.root['user'].id | ||
} | ||
|
||
auto_approve = true | ||
@handle.execute('create_automation_request', options, @handle.root['user'].userid, auto_approve) | ||
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::Import::CreateVmImportRequest.new.main | ||
end |
12 changes: 12 additions & 0 deletions
12
...nageIQ/Infrastructure/VM/Transform/Import.class/__methods__/create_vm_import_request.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: create_vm_import_request | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
inputs: [] |
45 changes: 45 additions & 0 deletions
45
...t/automate/ManageIQ/Infrastructure/VM/Transform/Import.class/__methods__/list_clusters.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,45 @@ | ||
module ManageIQ | ||
module Automate | ||
module Infrastructure | ||
module VM | ||
module Transform | ||
module Import | ||
class ListClusters | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def main | ||
values_hash = {} | ||
values_hash[nil] = '-- select cluster from list --' | ||
|
||
provider_id = @handle.root['dialog_provider'] | ||
if provider_id.present? && provider_id != '!' | ||
provider = @handle.vmdb(:ext_management_system, provider_id) | ||
if provider.nil? | ||
values_hash[nil] = 'None' | ||
else | ||
provider.ems_clusters.each do |cluster| | ||
values_hash[cluster.id] = cluster.name | ||
end | ||
end | ||
end | ||
list_values = { | ||
'sort_by' => :description, | ||
'data_type' => :string, | ||
'required' => true, | ||
'values' => values_hash | ||
} | ||
list_values.each { |key, value| @handle.object[key] = value } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if __FILE__ == $PROGRAM_NAME | ||
ManageIQ::Automate::Infrastructure::VM::Transform::Import::ListClusters.new.main | ||
end |
12 changes: 12 additions & 0 deletions
12
...automate/ManageIQ/Infrastructure/VM/Transform/Import.class/__methods__/list_clusters.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: list_clusters | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
inputs: [] |
38 changes: 38 additions & 0 deletions
38
...ate/ManageIQ/Infrastructure/VM/Transform/Import.class/__methods__/list_infra_providers.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,38 @@ | ||
module ManageIQ | ||
module Automate | ||
module Infrastructure | ||
module VM | ||
module Transform | ||
module Import | ||
class ListInfraProviders | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def main | ||
values_hash = {} | ||
values_hash[nil] = '-- select target infrastructure provider from list --' | ||
|
||
managers = @handle.vmdb('ManageIQ_Providers_Redhat_InfraManager').all.select(&:validate_import_vm) | ||
managers.each do |manager| | ||
values_hash[manager.id] = manager.name | ||
end | ||
list_values = { | ||
'sort_by' => :description, | ||
'data_type' => :string, | ||
'required' => true, | ||
'values' => values_hash | ||
} | ||
list_values.each { |key, value| @handle.object[key] = value } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if __FILE__ == $PROGRAM_NAME | ||
ManageIQ::Automate::Infrastructure::VM::Transform::Import::ListInfraProviders.new.main | ||
end |
12 changes: 12 additions & 0 deletions
12
...e/ManageIQ/Infrastructure/VM/Transform/Import.class/__methods__/list_infra_providers.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: list_infra_providers | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
inputs: [] |
46 changes: 46 additions & 0 deletions
46
...t/automate/ManageIQ/Infrastructure/VM/Transform/Import.class/__methods__/list_storages.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,46 @@ | ||
module ManageIQ | ||
module Automate | ||
module Infrastructure | ||
module VM | ||
module Transform | ||
module Import | ||
class ListStorages | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
def main | ||
values_hash = {} | ||
values_hash[nil] = '-- select storage from list --' | ||
|
||
provider_id = @handle.root['dialog_provider'] | ||
@handle.log(:info, "Selected provider: #{provider_id}") | ||
if provider_id.present? && provider_id != '!' | ||
provider = @handle.vmdb(:ext_management_system, provider_id) | ||
if provider.nil? | ||
values_hash[nil] = 'None' | ||
else | ||
provider.storages.each do |storage| | ||
values_hash[storage.id] = storage.name | ||
end | ||
end | ||
end | ||
list_values = { | ||
'sort_by' => :description, | ||
'data_type' => :string, | ||
'required' => true, | ||
'values' => values_hash | ||
} | ||
list_values.each { |key, value| @handle.object[key] = value } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if __FILE__ == $PROGRAM_NAME | ||
ManageIQ::Automate::Infrastructure::VM::Transform::Import::ListStorages.new.main | ||
end |
12 changes: 12 additions & 0 deletions
12
...automate/ManageIQ/Infrastructure/VM/Transform/Import.class/__methods__/list_storages.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: list_storages | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
inputs: [] |
10 changes: 10 additions & 0 deletions
10
content/automate/ManageIQ/Infrastructure/VM/Transform/Import.class/import_vm.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,10 @@ | ||
--- | ||
object_type: instance | ||
version: 1.0 | ||
object: | ||
attributes: | ||
display_name: | ||
name: ImportVm | ||
inherits: | ||
description: | ||
fields: [] |
12 changes: 12 additions & 0 deletions
12
content/automate/ManageIQ/Infrastructure/VM/Transform/Import.class/list_clusters.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: instance | ||
version: 1.0 | ||
object: | ||
attributes: | ||
display_name: | ||
name: list_clusters | ||
inherits: | ||
description: | ||
fields: | ||
- execute: | ||
value: list_clusters |
12 changes: 12 additions & 0 deletions
12
content/automate/ManageIQ/Infrastructure/VM/Transform/Import.class/list_infra_providers.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: instance | ||
version: 1.0 | ||
object: | ||
attributes: | ||
display_name: | ||
name: list_infra_providers | ||
inherits: | ||
description: | ||
fields: | ||
- execute: | ||
value: list_infra_providers |
12 changes: 12 additions & 0 deletions
12
content/automate/ManageIQ/Infrastructure/VM/Transform/Import.class/list_storages.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: instance | ||
version: 1.0 | ||
object: | ||
attributes: | ||
display_name: | ||
name: list_storages | ||
inherits: | ||
description: | ||
fields: | ||
- execute: | ||
value: list_storages |
Oops, something went wrong.