jellyfish-manageiq 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +202 -0
  3. data/README.md +109 -0
  4. data/Rakefile +25 -0
  5. data/app/assets/images/jellyfish_manageiq/products/apache.png +0 -0
  6. data/app/assets/images/jellyfish_manageiq/products/aws_ec2.png +0 -0
  7. data/app/assets/images/jellyfish_manageiq/products/aws_rds.png +0 -0
  8. data/app/assets/images/jellyfish_manageiq/products/aws_s3.png +0 -0
  9. data/app/assets/images/jellyfish_manageiq/products/bugzilla.png +0 -0
  10. data/app/assets/images/jellyfish_manageiq/products/confluence.png +0 -0
  11. data/app/assets/images/jellyfish_manageiq/products/database.png +0 -0
  12. data/app/assets/images/jellyfish_manageiq/products/dna.png +0 -0
  13. data/app/assets/images/jellyfish_manageiq/products/exchange.png +0 -0
  14. data/app/assets/images/jellyfish_manageiq/products/f5.png +0 -0
  15. data/app/assets/images/jellyfish_manageiq/products/firewall.png +0 -0
  16. data/app/assets/images/jellyfish_manageiq/products/hadoop.png +0 -0
  17. data/app/assets/images/jellyfish_manageiq/products/java.png +0 -0
  18. data/app/assets/images/jellyfish_manageiq/products/jira.png +0 -0
  19. data/app/assets/images/jellyfish_manageiq/products/kb.png +0 -0
  20. data/app/assets/images/jellyfish_manageiq/products/man.png +0 -0
  21. data/app/assets/images/jellyfish_manageiq/products/mean.png +0 -0
  22. data/app/assets/images/jellyfish_manageiq/products/mssql.png +0 -0
  23. data/app/assets/images/jellyfish_manageiq/products/netapp.png +0 -0
  24. data/app/assets/images/jellyfish_manageiq/products/oracle.png +0 -0
  25. data/app/assets/images/jellyfish_manageiq/products/php.png +0 -0
  26. data/app/assets/images/jellyfish_manageiq/products/postgresql.png +0 -0
  27. data/app/assets/images/jellyfish_manageiq/products/rails.png +0 -0
  28. data/app/assets/images/jellyfish_manageiq/products/redhat.png +0 -0
  29. data/app/assets/images/jellyfish_manageiq/products/teradata.png +0 -0
  30. data/app/assets/images/jellyfish_manageiq/products/ubuntu.png +0 -0
  31. data/app/assets/images/jellyfish_manageiq/products/windows.png +0 -0
  32. data/app/assets/images/jellyfish_manageiq/products/woman.png +0 -0
  33. data/app/assets/javascripts/jellyfish_manageiq/application.js +13 -0
  34. data/app/assets/javascripts/jellyfish_manageiq/products_admin_controller.js +63 -0
  35. data/app/assets/stylesheets/jellyfish_manageiq/application.css +15 -0
  36. data/app/controllers/manageiq/automate_controller.rb +61 -0
  37. data/app/controllers/manageiq/order_items_controller.rb +64 -0
  38. data/app/helpers/application_helper.rb +2 -0
  39. data/app/models/manage_iq_client.rb +12 -0
  40. data/app/models/manage_iq_client/base.rb +61 -0
  41. data/app/models/manage_iq_client/cluster.rb +9 -0
  42. data/app/models/manage_iq_client/datastore.rb +9 -0
  43. data/app/models/manage_iq_client/host.rb +9 -0
  44. data/app/models/manage_iq_client/policy.rb +9 -0
  45. data/app/models/manage_iq_client/policy_profile.rb +9 -0
  46. data/app/models/manage_iq_client/provider.rb +9 -0
  47. data/app/models/manage_iq_client/resource.rb +82 -0
  48. data/app/models/manage_iq_client/resource_pool.rb +9 -0
  49. data/app/models/manage_iq_client/server.rb +34 -0
  50. data/app/models/manage_iq_client/service.rb +9 -0
  51. data/app/models/manage_iq_client/service_catalog.rb +9 -0
  52. data/app/models/manage_iq_client/service_template.rb +9 -0
  53. data/app/models/manage_iq_client/template.rb +25 -0
  54. data/app/models/manage_iq_client/virtual_machine.rb +27 -0
  55. data/app/models/manage_iq_client/zone.rb +9 -0
  56. data/app/policies/manageiq/order_item_policy.rb +16 -0
  57. data/app/views/manageiq/automate/catalog_item_initialization.html.erb +0 -0
  58. data/app/views/manageiq/automate/create_chef_node.html.erb +97 -0
  59. data/app/views/manageiq/automate/create_ec2.html.erb +140 -0
  60. data/app/views/manageiq/automate/create_rds.html.erb +146 -0
  61. data/app/views/manageiq/automate/create_s3.html.erb +100 -0
  62. data/app/views/manageiq/automate/create_ses.html.erb +114 -0
  63. data/app/views/manageiq/automate/create_vmware_vm.html.erb +102 -0
  64. data/app/views/manageiq/automate/provision_rds.html.erb +130 -0
  65. data/app/views/manageiq/automate/retire_ec2.html.erb +96 -0
  66. data/app/views/manageiq/automate/retire_rds.html.erb +117 -0
  67. data/app/views/manageiq/automate/retire_s3.html.erb +93 -0
  68. data/app/views/manageiq/automate/retire_ses.html.erb +98 -0
  69. data/app/views/manageiq/automate/retire_vmware_vm.html.erb +70 -0
  70. data/app/views/manageiq/automate/update_servicemix_and_chef.html.erb +364 -0
  71. data/config/initializers/manage_iq_client.rb +9 -0
  72. data/config/initializers/product_types.rb +6 -0
  73. data/config/initializers/provisioners.rb +9 -0
  74. data/config/initializers/task_scheduler.rb +12 -0
  75. data/config/product_questions/big_data.json +50 -0
  76. data/config/product_questions/database.json +79 -0
  77. data/config/product_questions/infrastructure.json +49 -0
  78. data/config/product_questions/storage.json +57 -0
  79. data/config/provisioners.json +6 -0
  80. data/config/routes.rb +38 -0
  81. data/db/migrate/20150513221625_create_jellyfish_manageiq_database_products.rb +16 -0
  82. data/db/migrate/20150513221938_create_jellyfish_manageiq_big_data_products.rb +14 -0
  83. data/db/migrate/20150513222020_create_jellyfish_manageiq_infrastructure_products.rb +13 -0
  84. data/db/migrate/20150513222056_create_jellyfish_manageiq_storage_products.rb +13 -0
  85. data/lib/jellyfish/manageiq.rb +34 -0
  86. data/lib/jellyfish/manageiq/big_data.rb +6 -0
  87. data/lib/jellyfish/manageiq/databases.rb +6 -0
  88. data/lib/jellyfish/manageiq/engine.rb +19 -0
  89. data/lib/jellyfish/manageiq/infrastructure.rb +6 -0
  90. data/lib/jellyfish/manageiq/provisioner.rb +115 -0
  91. data/lib/jellyfish/manageiq/storage.rb +6 -0
  92. data/lib/jellyfish/manageiq/version.rb +5 -0
  93. data/lib/tasks/pollvms.rake +42 -0
  94. metadata +360 -0
@@ -0,0 +1,100 @@
1
+ # This script provisions a new S3 instance
2
+ # Based off of the criteria selected in the marketplace
3
+
4
+ # For use in MIQ under the
5
+ # /Provisioning/StateMachines/Methods/CreateS3
6
+
7
+ require 'aws-sdk'
8
+ require 'net/http'
9
+ require 'uri/http'
10
+ require 'json'
11
+
12
+ def send_order_status(referer, headers, status, order_id, information, message = '')
13
+ path = "/order_items/#{order_id}/provision_update"
14
+ host = URI.parse(referer).host
15
+ url = "http://#{host}#{path}"
16
+ uri = URI.parse(url)
17
+
18
+ information = information.merge('provision_status' => status.downcase)
19
+ $evm.log('info', "send_order_status: Information: #{information}")
20
+ json = {
21
+ status: "#{status}",
22
+ message: "#{message}",
23
+ info: information
24
+ }
25
+ $evm.log('info', "send_order_status: Information #{json}")
26
+ begin
27
+ http = Net::HTTP.new(uri.host, uri.port)
28
+ request = Net::HTTP::Put.new(uri.path)
29
+ request.add_field('X-Staff-Email', "#{headers[0]}")
30
+ request.add_field('X-Staff-Token', "#{headers[1]}")
31
+ request.content_type = 'application/json'
32
+ request.body = json.to_json
33
+ response = http.request(request)
34
+ $evm.log('info', "send_order_status: HTTP Response code: #{response.code}")
35
+ $evm.log('info', "send_order_status: HTTP Response message: #{response.message}")
36
+ rescue StandardError => e
37
+ $evm.log('error', "send_order_status: Exception caught while sending response back to core: #{e.message}")
38
+ end
39
+ end # End of function
40
+
41
+ $evm.log('info', 'CreateS3: Entering method')
42
+
43
+ # MIQ makes dialog_product_details into a string.
44
+ # Must convert to a hash.
45
+ product_details = $evm.root['dialog_order_item']
46
+ order_item_hash = JSON.parse(product_details.gsub("'", '"').gsub('=>', ':'))
47
+ product_hash = order_item_hash['product_details']
48
+ order_id = order_item_hash['id']
49
+ uuid = order_item_hash['uuid']
50
+ access_key_id = product_hash['access_key_id']
51
+ secret_access_key = product_hash['secret_access_key']
52
+ bucket_name = "id-#{uuid[0..9]}"
53
+ host = $evm.root['dialog_referer']
54
+ headers = [$evm.root['dialog_email'], $evm.root['dialog_token']]
55
+
56
+ S3 = AWS::S3.new(
57
+ access_key_id: access_key_id,
58
+ secret_access_key: secret_access_key)
59
+
60
+ begin
61
+ info = {
62
+ 'id' => order_id,
63
+ 'uuid' => uuid
64
+ }
65
+ if !S3.buckets[bucket_name].exists?
66
+ S3.buckets.create(bucket_name)
67
+ else
68
+ $evm.log('error', 'CreateS3: Bucket name already exists.')
69
+ send_order_status(host, headers, 'CRITICAL', order_id, info, 'Bucket already exists.')
70
+ exit
71
+ end
72
+ rescue AWS::S3::Errors::InvalidClientTokenId => e
73
+ $evm.log('error', "CreateS3: Invalid client token exception caught: #{e.message}.")
74
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
75
+ exit
76
+ rescue AWS::S3::Errors::InvalidParameterValue => e
77
+ $evm.log('error', "CreateS3: Invalid parameter exception caught: #{e.message}")
78
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
79
+ exit
80
+ rescue AWS::S3::Errors => e
81
+ $evm.log('error', "Create S3: AWS Exception caught: #{e.message}")
82
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
83
+ exit
84
+ rescue StandardError => e
85
+ $evm.log('error', "CreateS3: General exception caught: #{e.message}")
86
+ $evm.log('error', "CreateS3: General exception back trace: #{e.backtrace}")
87
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
88
+ exit
89
+ end
90
+
91
+ $evm.log('info', 'CreateS3: Bucket created.')
92
+ # TODO: Send back successful response if the bucket was created
93
+
94
+ info = {
95
+ 'id' => "#{order_id}",
96
+ 'uuid' => "#{uuid}",
97
+ 'bucket_name' => "#{bucket_name}"
98
+ }
99
+
100
+ send_order_status(host, headers, 'OK', order_id, info)
@@ -0,0 +1,114 @@
1
+ # # Description: This MIQ Method configures an
2
+ # existing Simple Email Service
3
+ # It will set the region, as well as set a verified sender
4
+ # If a verified sender is chosen
5
+
6
+ # For use in MIQ under the
7
+ # /Provisioning/StateMachines/Methods/CreateSES
8
+
9
+ require 'aws-sdk'
10
+ require 'net/http'
11
+ require 'uri/http'
12
+
13
+ def send_order_status(referer, headers, status, order_id, information, message = '')
14
+ path = "/order_items/#{order_id}/provision_update"
15
+ host = URI.parse(referer).host
16
+ url = "http://#{host}#{path}"
17
+ uri = URI.parse(url)
18
+
19
+ information = information.merge('provision_status' => status.downcase)
20
+ $evm.log('info', "send_order_status: Information: #{information}")
21
+ json = {
22
+ status: "#{status}",
23
+ message: "#{message}",
24
+ info: information
25
+ }
26
+ $evm.log('info', "send_order_status: Information #{json}")
27
+ begin
28
+ http = Net::HTTP.new(uri.host, uri.port)
29
+ request = Net::HTTP::Put.new(uri.path)
30
+ request.add_field('X-Staff-Email', "#{headers[0]}")
31
+ request.add_field('X-Staff-Token', "#{headers[1]}")
32
+ request.content_type = 'application/json'
33
+ request.body = json.to_json
34
+ response = http.request(request)
35
+ $evm.log('info', "send_order_status: HTTP Response code: #{response.code}")
36
+ $evm.log('info', "send_order_status: HTTP Response message: #{response.message}")
37
+ rescue StandardError => e
38
+ $evm.log('error', "send_order_status: Exception caught while sending response back to core: #{e.message}")
39
+ end
40
+ end # End of function
41
+
42
+ $evm.log('info', 'CreateSES: Entering method')
43
+
44
+ # Retrieve properties from request
45
+ # MIQ makes product_details into a string.
46
+ # Must make into a hash
47
+ product_details = $evm.root['dialog_order_item']
48
+ order_item_hash = JSON.parse(product_details.gsub("'", '"').gsub('=>', ':'))
49
+ product_hash = order_item_hash['product_details']
50
+ order_id = order_item_hash['id']
51
+ uuid = order_item_hash['uuid']
52
+ access_key = product_hash['access_key_id']
53
+ secret_access_key = product_hash['secret_access_key']
54
+ region = product_hash['region']
55
+ email = product_hash['email']
56
+ host = $evm.root['dialog_referer']
57
+ headers = [$evm.root['dialog_email'], $evm.root['dialog_token']]
58
+
59
+ # Setup the SES Region if region was chosen
60
+ if region != ''
61
+ AWS.config(
62
+ access_key_id: access_key,
63
+ secret_access_key: secret_access_key,
64
+ ses: { region: region }
65
+ )
66
+ else
67
+ AWS.config(
68
+ access_key_id: access_key,
69
+ secret_access_key: secret_access_key
70
+ )
71
+ end
72
+
73
+ $evm.log('info', 'CreateSES: create service')
74
+ ses = AWS::SimpleEmailService.new
75
+
76
+ # Setup a verified sender if a sender was chosen
77
+ if email != ''
78
+ begin
79
+ info = {
80
+ 'id' => order_id,
81
+ 'uuid' => uuid
82
+ }
83
+ email_identities = email.split(',')
84
+ email_identities.each do |e|
85
+ $evm.log('info', "CreateSES: E-mail Identity: #{e}")
86
+ ses.identities.verify(e)
87
+ end
88
+ rescue AWS::SimpleEmailService::Errors::InvalidClientTokenId => e
89
+ $evm.log('error', "CreateSES: Exception caught when creating instance: #{e.message}")
90
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
91
+ exit
92
+ rescue AWS::RDS::Errors::InvalidParameterValue => e
93
+ $evm.log('error', "CreateSES: Invalid parameter exception caught: #{e.message}")
94
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
95
+ exit
96
+ rescue AWS::RDS::Errors => e
97
+ $evm.log('error', "CreateSES: Exception caught: #{e.message}")
98
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
99
+ exit
100
+ rescue StandardError => e
101
+ $evm.log('error', "CreateSES: Exception caught #{e.message}")
102
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
103
+ exit
104
+ end
105
+ end
106
+
107
+ # Return the response that it was created successfully
108
+ info = {
109
+ 'id' => order_id,
110
+ 'region' => region
111
+ }
112
+
113
+ $evm.log('info', 'CreateSES: Provision executed successfully.')
114
+ send_order_status(host, headers, 'OK', order_id, info)
@@ -0,0 +1,102 @@
1
+ # This script provisions a VMWare VM and
2
+ # gets an IP address for it
3
+
4
+ require 'rbvmomi'
5
+ require 'net/http'
6
+ require 'uri/http'
7
+ require 'json'
8
+
9
+ def send_order_status(referer, headers, status, order_id, information, message = '')
10
+ path = "/order_items/#{order_id}/provision_update"
11
+ host = URI.parse(referer).host
12
+ url = "http://#{host}#{path}"
13
+ uri = URI.parse(url)
14
+
15
+ information = information.merge('provision_status' => status.downcase)
16
+ $evm.log('info', "send_order_status: Information: #{information}")
17
+ json = {
18
+ status: "#{status}",
19
+ message: "#{message}",
20
+ info: information
21
+ }
22
+ $evm.log('info', "send_order_status: Information #{json}")
23
+ begin
24
+ http = Net::HTTP.new(uri.host, uri.port)
25
+ request = Net::HTTP::Put.new(uri.path)
26
+ request.add_field('X-Staff-Email', "#{headers[0]}")
27
+ request.add_field('X-Staff-Token', "#{headers[1]}")
28
+ request.content_type = 'application/json'
29
+ request.body = json.to_json
30
+ response = http.request(request)
31
+ $evm.log('info', "send_order_status: HTTP Response code: #{response.code}")
32
+ $evm.log('info', "send_order_status: HTTP Response message: #{response.message}")
33
+ rescue StandardError => e
34
+ $evm.log('error', "send_order_status: Exception caught while sending response back to core: #{e.message}")
35
+ end
36
+ end # End of function
37
+
38
+ # Retrieve all information set from the marketplace
39
+ product_details = $evm.root['dialog_order_item']
40
+ order_item_hash = JSON.parse(product_details.gsub("'", '"').gsub('=>', ':'))
41
+ product_hash = order_item_hash['product_details']
42
+ order_id = order_item_hash['id']
43
+ uuid = order_item_hash['uuid']
44
+ datacenter = product_hash['datacenter']
45
+ host = product_hash['host']
46
+ port = Integer(product_hash['port']) unless product_hash['port'].nil || product_hash[port] == ''
47
+ user = product_hash['user']
48
+ password = product_hash['password']
49
+ template = product_hash['template']
50
+ spec_name = product_hash['spec_name']
51
+ instance_name = product_hash['instance_name']
52
+ headers = [$evm.root['dialog_email'], $evm.root['dialog_token']]
53
+
54
+ info = {
55
+ 'id' => order_id,
56
+ 'uuid' => uuid
57
+ }
58
+
59
+ begin
60
+ $evm.log('info', 'CreateVMWareVM: Begin')
61
+ vim = RbVmomi::VIM.connect host: host, port: port, user: user, password: password, insecure: false
62
+ dc = vim.serviceInstance.find_datacenter(datacenter)
63
+ $evm.log('info', 'CreateVMWareVM: Found datacenter #{datacenter}')
64
+ clone_vm = dc.find_vm(template)
65
+ if clone_vm.nil?
66
+ send_order_status(host, headers, 'CRITICAL', order_id, info, 'Could not find VM')
67
+ exit
68
+ end
69
+ configuration = RbVmomi::VIM.VirtualMachineConfigSpec(annotation: 'Creation time: ' + Time.now.strftime('%Y-%m-%d %H:%M') + "\n\n")
70
+ hosts = dc.hostFolder.children
71
+ pool = hosts.first.resourcePool
72
+ relocation_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(pool: pool)
73
+ custom_spec = vim.serviceContent.customizationSpecManager.GetCustomizationSpec(name: spec_name).spec
74
+ if custom_spec.nil?
75
+ send_order_status(host, headers, 'CRITICAL', order_id, info, 'Could not find specified spec file')
76
+ exit
77
+ end
78
+ clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(
79
+ location: relocation_spec,
80
+ config: configuration,
81
+ customization: custom_spec,
82
+ powerOn: true,
83
+ template: false
84
+ )
85
+ task = clone_vm.CloneVM_Task(folder: clone_vm.parent, name: instance_name, spec: clone_spec)
86
+ task.wait_for_completion
87
+ created_vm = dc.find_vm(instance_name)
88
+ # Get information about the VM to pass back
89
+ ip_address = created_vm.guest.ipAddress
90
+ guest_family = created_vm.guest.guestFamily
91
+ info = {
92
+ 'id' => order_id,
93
+ 'uuid' => uuid,
94
+ 'ip_address' => ip_address,
95
+ 'guest_family' => guest_family
96
+ }
97
+ send_order_status(host, headers, 'OK', order_id, info, '')
98
+ rescue StandardError => e
99
+ $evm.log('error', "CloneVM: General exception caught: #{e.message}")
100
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "Exception caught while creating VM: #{e.message}")
101
+ exit
102
+ end
@@ -0,0 +1,130 @@
1
+ # Description: This MIQ Method Waits for the instance
2
+ # to be out of the creating state
3
+ # To retrieve instance properties to pass back to the marketplace
4
+ # from the criteria selected in the marketplace
5
+ # For use in Service/Provisioning/StateMachines/Methods/ProvisionRDS
6
+
7
+ require 'aws-sdk'
8
+ require 'rest-client'
9
+ require 'rubygems'
10
+ require 'net/http'
11
+ require 'uri/http'
12
+ require 'json'
13
+
14
+ $evm.log('info', 'ProvisionRDS: Entering Method.')
15
+
16
+ def send_order_status(referer, headers, status, order_id, information, message = '')
17
+ path = "/order_items/#{order_id}/provision_update"
18
+ host = URI.parse(referer).host
19
+ url = "http://#{host}#{path}"
20
+ uri = URI.parse(url)
21
+
22
+ information = information.merge('provision_status' => status.downcase)
23
+ $evm.log('info', "send_order_status: Information: #{information}")
24
+ json = {
25
+ status: "#{status}",
26
+ message: "#{message}",
27
+ info: information
28
+ }
29
+ $evm.log('info', "send_order_status: Information #{json}")
30
+ begin
31
+ http = Net::HTTP.new(uri.host, uri.port)
32
+ request = Net::HTTP::Put.new(uri.path)
33
+ request.add_field('X-Staff-Email', "#{headers[0]}")
34
+ request.add_field('X-Staff-Token', "#{headers[1]}")
35
+ request.content_type = 'application/json'
36
+ request.body = json.to_json
37
+ response = http.request(request)
38
+ $evm.log('info', "send_order_status: HTTP Response code: #{response.code}")
39
+ $evm.log('info', "send_order_status: HTTP Response message: #{response.message}")
40
+ rescue StandardError => e
41
+ $evm.log('error', "send_order_status: Exception caught while sending response back to core: #{e.message}")
42
+ end
43
+ end # End of function
44
+
45
+ # If the instance did not complete creation from the previous state,
46
+ # Exit method.
47
+ if $evm.root['instance_failed'] == true
48
+ $evm.log('error', 'ProvisionRDS: Could not create instance. Exiting method.')
49
+ # Does not need to pass back another response. Did that in the previous step.
50
+ exit
51
+ end
52
+
53
+ # MIQ makes dialog_product_details into a string.
54
+ # Must convert to a hash.
55
+ product_details = $evm.root['dialog_order_item']
56
+ order_item_hash = JSON.parse(product_details.gsub("'", '"').gsub('=>', ':'))
57
+ product_hash = order_item_hash['product_details']
58
+ order_id = order_item_hash['id']
59
+ uuid = order_item_hash['uuid']
60
+ access_key_id = product_hash['access_key_id']
61
+ secret_key = product_hash['secret_access_key']
62
+ db_instance_id = $evm.root['db_instance_id']
63
+ host = $evm.root['dialog_referer']
64
+ headers = [$evm.root['dialog_email'], $evm.root['dialog_token']]
65
+
66
+ # Retrieve request properties from the product hash
67
+ rds = AWS::RDS.new(
68
+ access_key_id: access_key_id,
69
+ secret_access_key: secret_key
70
+ )
71
+
72
+ # Get the instance name of the variable created
73
+ begin
74
+ instance_collection = rds.db_instances
75
+ instance = instance_collection[db_instance_id]
76
+ info = {
77
+ 'id' => order_id,
78
+ 'uuid' => uuid
79
+ }
80
+ rescue AWS::RDS::Errors::InvalidClientTokenId => e
81
+ $evm.log('error', 'ProvisionRDS: Exception caught when creating instance: #{e.message}')
82
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
83
+ exit
84
+ rescue AWS::RDS::Errors => e
85
+ $evm.log('error', "ProvisionRDS: Exception caught when creating instance: #{e.message}")
86
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
87
+ exit
88
+ end
89
+
90
+ if instance.exists?
91
+ $evm.log('info', "ProvisionRDS: Instance #{db_instance_id} exists")
92
+ # Wait for the instance to create
93
+ # Instance properties will not be available until the instance has
94
+ # Completed the 'creating' stage
95
+ # Typically takes 2-4 minutes
96
+ sleep 5 while instance.status == 'creating'
97
+
98
+ # Create the payload to send back to the marketplace
99
+ information = {
100
+ 'id' => order_id,
101
+ 'uuid' => uuid,
102
+ 'hostname' => "#{instance.endpoint_address}",
103
+ 'port' => "#{instance.endpoint_port}",
104
+ 'username' => "#{instance.master_username}",
105
+ 'password' => "#{$evm.root['root_sec_pw']}",
106
+ 'instance_name' => "#{$evm.root['dialog_instance_name']}",
107
+ 'instance_class' => "#{$evm.root['dialog_db_instance_class']}",
108
+ 'instance_storage' => "#{$evm.root['dialog_allocated_storage']}"
109
+ }
110
+ $evm.log('info', "ProvisionRDS: Generated the RDS with the following information #{information}")
111
+ send_order_status(host, headers, 'OK', order_id, information)
112
+ else # If the instance did not exist
113
+ $evm.log('info', "ProvisionRDS: Instance #{db_instance_id} was not created and does not exist")
114
+ info = {
115
+ 'order_id' => "#{order_id}"
116
+ }
117
+ send_order_status(host, headers, 'CRITICAL', order_id, info, 'Instance was not created and does not exist')
118
+ end
119
+
120
+ $evm.log('info', "ProvisionRDS: Instance #{db_instance_id} created")
121
+
122
+ #
123
+ # Description: This method launches the service provisioning job
124
+ # This is directly from MIQ
125
+
126
+ $evm.log('info', 'ProvisionRDS: Listing Root Object Attributes:')
127
+ $evm.root.attributes.sort.each { |k, v| $evm.log('info', "\t#{k}: #{v}") }
128
+ $evm.log('info', 'ProvisionRDS: End provisioning')
129
+
130
+ $evm.root['service_template_provision_task'].execute
@@ -0,0 +1,96 @@
1
+ # Description: This MIQ Method will delete a specified EC2 instance
2
+ # For use in Service/Provisioning/StateMachines/Methods/RetireEC2
3
+
4
+ require 'aws-sdk'
5
+ require 'net/http'
6
+ require 'uri/http'
7
+ require 'json'
8
+
9
+ $evm.log('error', 'RetireEC2: Enter Method.')
10
+
11
+ def send_order_status(referer, headers, status, order_id, information, message = '')
12
+ path = "/order_items/#{order_id}/provision_update"
13
+ host = URI.parse(referer).host
14
+ url = "http://#{host}#{path}"
15
+ uri = URI.parse(url)
16
+
17
+ information = information.merge('provision_status' => status.downcase)
18
+ $evm.log('info', "send_order_status: Information: #{information}")
19
+ json = {
20
+ status: "#{status}",
21
+ message: "#{message}",
22
+ info: information
23
+ }
24
+ $evm.log('info', "send_order_status: Information #{json}")
25
+ begin
26
+ http = Net::HTTP.new(uri.host, uri.port)
27
+ request = Net::HTTP::Put.new(uri.path)
28
+ request.content_type = 'application/json'
29
+ request.body = json.to_json
30
+ response = http.request(request)
31
+ $evm.log('info', "send_order_status: HTTP Response code: #{response.code}")
32
+ $evm.log('info', "send_order_status: HTTP Response message: #{response.message}")
33
+ rescue StandardError => e
34
+ $evm.log('error', "send_order_status: Exception caught while sending response back to core: #{e.message}")
35
+ end
36
+ end # End of function
37
+
38
+ # Retrieve properties from request
39
+ # MIQ makes product_details into a string.
40
+ # Must make into a hash
41
+ product_details = $evm.root['dialog_order_item']
42
+ order_item_hash = JSON.parse(product_details.gsub("'", '"').gsub('=>', ':'))
43
+ product_hash = order_item_hash['product_details']
44
+ uuid = order_item_hash['uuid']
45
+ access_key_id = product_hash['access_key_id']
46
+ secret_access_key = product_hash['secret_access_key']
47
+ instance_id = product_hash['instance_id']
48
+ order_id = order_item_hash['id']
49
+ headers = [$evm.root['dialog_email'], $evm.root['dialog_token']]
50
+
51
+ ec2 = AWS::EC2.new(
52
+ access_key_id: access_key_id,
53
+ secret_access_key: secret_access_key
54
+ )
55
+
56
+ info = {
57
+ 'id' => order_id,
58
+ 'uuid' => uuid
59
+ }
60
+
61
+ # Get the specified VM
62
+ begin
63
+ instance = ec2.instances[instance_id]
64
+ rescue AWS::EC2::Errors::InvalidClientTokenId => e
65
+ $evm.log('error', "RetireEC2: Invalid Token Id exception caught: #{e.message}")
66
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
67
+ exit
68
+ rescue AWS::EC2::Errors => e
69
+ $evm.log('error', "RetireEC2: EC2 exception caught: #{e.message}")
70
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
71
+ exit
72
+ end
73
+
74
+ if instance.exists?
75
+ $evm.log('info', 'RetireEC2: Instance exists')
76
+ begin
77
+ instance.terminate
78
+ $evm.log('info', 'RetireEC2: instance terminated.')
79
+ rescue AWS::EC2::Errors::InvalidClientTokenId => e
80
+ $evm.log('error', "RetireEC2: Invalid client token exception caught: #{e.message}")
81
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
82
+ exit
83
+ rescue AWS::EC2::Errors => e
84
+ $evm.log('error', "RetireEC2: Exception caught #{e.message}")
85
+ send_order_status(host, headers, 'CRITICAL', order_id, info, "#{e.message}")
86
+ exit
87
+ end
88
+ send_order_status(host, headers, 'OK', order_id, info)
89
+ else
90
+ $evm.log('error', "RetireEC2: Instance #{instance_id} does not exist.")
91
+ send_order_status(host, headers, 'CRITICAL', order_id, info, 'instance does not exist')
92
+ end
93
+
94
+ $evm.log('info', 'RetireEC2: Instance retired.')
95
+
96
+ send_order_status(host, headers, 'OK', order_id, info, 'Instance retired.')