diff --git a/scripts/OPNFV/NetworkServices/Methods.class/__methods__/create_networks_and_subnets.rb b/scripts/OPNFV/NetworkServices/Methods.class/__methods__/create_networks_and_subnets.rb index e522129..7292b88 100644 --- a/scripts/OPNFV/NetworkServices/Methods.class/__methods__/create_networks_and_subnets.rb +++ b/scripts/OPNFV/NetworkServices/Methods.class/__methods__/create_networks_and_subnets.rb @@ -46,12 +46,25 @@ def get_networks_template(network_service, parent_service) end vnf_networks_template_name = "#{parent_service.name} networks #{parent_service.id}" - - template = $evm.vmdb('orchestration_template_hot').create( - :name => vnf_networks_template_name, - :orderable => true, - :content => YAML.dump(template_content)) - template + + resource = {:name => vnf_networks_template_name, + :type => "OrchestrationTemplateHot", + :orderable => true, + :content => YAML.dump(template_content)} + + url = "http://localhost:3000/api/orchestration_templates" + options = {:method => :post, + :url => url, + :verify_ssl => false, + :payload => {"action" => "create", + "resource" => resource}.to_json, + :headers => {"X-Auth-Token" => MIQ_API_TOKEN, + :accept => :json}} + $evm.log("info", "Creating HOT template #{options}") + + body = JSON.parse(RestClient::Request.execute(options)) + + $evm.vmdb('orchestration_template_hot', body["results"].first["id"]) end def deploy_networks(network_service, parent_service) @@ -93,22 +106,36 @@ def deploy_networks(network_service, parent_service) end def deploy_networks_stack(orchestration_manager, parent_service, template) + resource = {:name => "#{parent_service.name} networks", + :type => "ServiceOrchestration", + :orchestration_template => {:id => template.id}, + :orchestration_manager => {:id => orchestration_manager.id}, + :parent_service => {:id => parent_service.id}, + :stack_name => "#{parent_service.name}_#{$evm.root['service_template_provision_task_id']}_networks", + :stack_options => {:attributes => {}}, + :display => true} + + url = "http://localhost:3000/api/services" + options = {:method => :post, + :url => url, + :verify_ssl => false, + :payload => {"action" => "create", + "resource" => resource}.to_json, + :headers => {"X-Auth-Token" => MIQ_API_TOKEN, + :accept => :json}} + $evm.log("info", "Creating HOT service #{options}") - orchestration_service = $evm.vmdb('ServiceOrchestration').create( - :name => "#{parent_service.name} networks") + body = JSON.parse(RestClient::Request.execute(options)) - orchestration_service.stack_name = "#{parent_service.name}_#{$evm.root['service_template_provision_task_id']}_networks" - orchestration_service.orchestration_template = template - orchestration_service.orchestration_manager = orchestration_manager - orchestration_service.stack_options = {:attributes => {}} - orchestration_service.display = true - orchestration_service.parent_service = parent_service - orchestration_service.deploy_orchestration_stack + orchestration_service = $evm.vmdb('service', body["results"].first["id"]) + orchestration_service.deploy_orchestration_stack orchestration_service end begin + require 'rest-client' + nsd = $evm.get_state_var(:nsd) $evm.log("info", "Listing nsd #{nsd}") $evm.log("info", "Listing Root Object Attributes:") diff --git a/scripts/OPNFV/NetworkServices/Methods.class/__methods__/deploy_cfns.rb b/scripts/OPNFV/NetworkServices/Methods.class/__methods__/deploy_cfns.rb index a0ab8c2..8f0eae5 100644 --- a/scripts/OPNFV/NetworkServices/Methods.class/__methods__/deploy_cfns.rb +++ b/scripts/OPNFV/NetworkServices/Methods.class/__methods__/deploy_cfns.rb @@ -164,10 +164,25 @@ def create_template(name,nsd_properties,nsd_requirements) $evm.log(:info ,"nic array==> #{nic}") template_content["Resources"].merge!(instance("Ec2Instance", nic, key_name, image.ems_ref,availability_zone,instance_type)) - $evm.vmdb('orchestration_template_cfn').create( - :name => name, - :orderable => true, - :content => JSON.pretty_generate(template_content)) + + resource = {:name => name, + :type => "OrchestrationTemplateCfn", + :orderable => true, + :content => JSON.pretty_generate(template_content)} + + url = "http://localhost:3000/api/orchestration_templates" + options = {:method => :post, + :url => url, + :verify_ssl => false, + :payload => {"action" => "create", + "resource" => resource}.to_json, + :headers => {"X-Auth-Token" => MIQ_API_TOKEN, + :accept => :json}} + $evm.log("info", "Creating CFN template #{options}") + + body = JSON.parse(RestClient::Request.execute(options)) + + $evm.vmdb('orchestration_template_cfn', body["results"].first["id"]) end def deploy_amazon_stack(orchestration_manager, parent_service, vnf_service) @@ -182,17 +197,29 @@ def deploy_amazon_stack(orchestration_manager, parent_service, vnf_service) name = "#{parent_service.name} #{vnf_service.name} #{parent_service.id}" template = create_template(name,nsd_properties,nsd_requirements) - $evm.log("info", "Deploying CFN template #{name}") - orchestration_service = $evm.vmdb('ServiceOrchestration').create( - :name => "#{parent_service.name} #{vnf_service.name}") + resource = {:name => "#{parent_service.name} #{vnf_service.name}", + :type => "ServiceOrchestration", + :orchestration_template => {:id => template.id}, + :orchestration_manager => {:id => orchestration_manager.id}, + :parent_service => {:id => parent_service.id}, + :stack_name => name.gsub("\s", "-").gsub("_", "-"), + :stack_options => {}, + :display => true} + url = "http://localhost:3000/api/services" + options = {:method => :post, + :url => url, + :verify_ssl => false, + :payload => {"action" => "create", + "resource" => resource}.to_json, + :headers => {"X-Auth-Token" => MIQ_API_TOKEN, + :accept => :json}} + $evm.log("info", "Creating CFN service #{options}") + + body = JSON.parse(RestClient::Request.execute(options)) + + orchestration_service = $evm.vmdb('service', body["results"].first["id"]) orchestration_service.custom_set('properties', nsd_properties.to_json) - orchestration_service.stack_name = name.gsub("\s", "-").gsub("_", "-") - orchestration_service.orchestration_template = template - orchestration_service.orchestration_manager = orchestration_manager - orchestration_service.stack_options = {} - orchestration_service.display = true - orchestration_service.parent_service = parent_service orchestration_service.deploy_orchestration_stack end @@ -220,6 +247,8 @@ def ethx_config(ethx) end begin + require 'rest-client' + nsd = $evm.get_state_var(:nsd) $evm.log("info", "Listing nsd #{nsd}") $evm.log("info", "Listing Root Object Attributes:") diff --git a/scripts/OPNFV/NetworkServices/Methods.class/__methods__/deploy_vnfs.rb b/scripts/OPNFV/NetworkServices/Methods.class/__methods__/deploy_vnfs.rb index ee1fa1c..79871e0 100644 --- a/scripts/OPNFV/NetworkServices/Methods.class/__methods__/deploy_vnfs.rb +++ b/scripts/OPNFV/NetworkServices/Methods.class/__methods__/deploy_vnfs.rb @@ -14,7 +14,6 @@ def get_template_contents(network_service) end def get_template(orchestration_manager, network_service, parent_service, vnf_service) - templates = {} # Load our general VNFDs per type template_contents = get_template_contents(network_service) @@ -108,12 +107,27 @@ def get_template(orchestration_manager, network_service, parent_service, vnf_ser template_content['topology_template']['node_templates'].merge!(virtual_links) unused_cps.each { |x| template_content['topology_template']['node_templates'].delete(x) } - - $evm.vmdb('orchestration_template_vnfd').create( - :name => vnf_template_name, - :orderable => true, - :ems_id => orchestration_manager.id, - :content => YAML.dump(template_content)) + + resource = {:name => vnf_template_name, + :type => "OrchestrationTemplateVnfd", + :orderable => true, + :remote_proxy => true, + :ems_id => orchestration_manager.id, + :content => YAML.dump(template_content)} + + url = "http://localhost:3000/api/orchestration_templates" + options = {:method => :post, + :url => url, + :verify_ssl => false, + :payload => {"action" => "create", + "resource" => resource}.to_json, + :headers => {"X-Auth-Token" => MIQ_API_TOKEN, + :accept => :json}} + $evm.log("info", "Creating VNFd template #{options}") + + body = JSON.parse(RestClient::Request.execute(options)) + + $evm.vmdb('orchestration_template_vnfd', body["results"].first["id"]) end def deploy_vnfs(network_service, parent_service) @@ -135,21 +149,36 @@ def deploy_vnf_stack(orchestration_manager, network_service, parent_service, vnf params['type'] = vnf_service.custom_get('type') params = params.to_json - - orchestration_service = $evm.vmdb('ServiceOrchestration').create( - :name => "#{parent_service.name} #{vnf_service.name}") - + + resource = {:name => "#{parent_service.name} #{vnf_service.name}", + :type => "ServiceOrchestration", + :orchestration_template => {:id => template.id}, + :orchestration_manager => {:id => orchestration_manager.id}, + :parent_service => {:id => parent_service.id}, + :stack_name => "#{parent_service.name} #{vnf_service.name} #{parent_service.id}", + :stack_options => {:attributes => {:param_values => params}}, + :display => true} + + url = "http://localhost:3000/api/services" + options = {:method => :post, + :url => url, + :verify_ssl => false, + :payload => {"action" => "create", + "resource" => resource}.to_json, + :headers => {"X-Auth-Token" => MIQ_API_TOKEN, + :accept => :json}} + $evm.log("info", "Creating Vnf service #{options}") + + body = JSON.parse(RestClient::Request.execute(options)) + + orchestration_service = $evm.vmdb('service', body["results"].first["id"]) orchestration_service.custom_set('properties', params) - orchestration_service.stack_name = "#{parent_service.name} #{vnf_service.name} #{parent_service.id}" - orchestration_service.orchestration_template = template - orchestration_service.orchestration_manager = orchestration_manager - orchestration_service.stack_options = {:attributes => {:param_values => params}} - orchestration_service.display = true - orchestration_service.parent_service = parent_service orchestration_service.deploy_orchestration_stack end begin + require 'rest-client' + nsd = $evm.get_state_var(:nsd) $evm.log("info", "Listing nsd #{nsd}") $evm.log("info", "Listing Root Object Attributes:") diff --git a/scripts/OPNFV/NetworkServices/Methods.class/__methods__/retire_vnfs.rb b/scripts/OPNFV/NetworkServices/Methods.class/__methods__/retire_vnfs.rb index 077582a..a36f018 100644 --- a/scripts/OPNFV/NetworkServices/Methods.class/__methods__/retire_vnfs.rb +++ b/scripts/OPNFV/NetworkServices/Methods.class/__methods__/retire_vnfs.rb @@ -7,20 +7,20 @@ def retire_vnfs(network_service) # This a VNF service stack = $evm.vmdb('ManageIQ_Providers_Openstack_CloudManager_Vnf').find_by_name("#{vnf_service.name} #{network_service.id}") - - if stack + status, reason = vnf_service.orchestration_stack.normalized_live_status + + if stack && status != 'not_exist' # Tacker stack - if vnf_service.orchestration_stack_status[0] == 'create_complete' - stack.raw_delete_stack() - $evm.log(:info, "Retiring #{vnf_service.name}") - vnf_service.retire_now() - found_stack = true - elsif vnf_service.orchestration_stack_status[0] == 'transient' - found_stack = true + found_stack = true + if vnf_service.orchestration_stack_status[0] == 'create_complete' || vnf_service.orchestration_stack_status[0] == 'update_complete' + $evm.log(:info, "Deleting VNF stack#{vnf_service.name}") + delete_stack(stack) end else - # Could be a Tacker template remaining... + # Could be a Tacker template remaining... + $evm.log(:info, "Properties '#{vnf_service.custom_get('properties')}' VNFD orchestration template for deletion") type = JSON.parse(vnf_service.custom_get('properties') || '{}').try(:[], 'type') || "" + $evm.log(:info, "Finding '#{vnf_service.name} #{type} #{network_service.id}' VNFD orchestration template for deletion") template = $evm.vmdb('orchestration_template_vnfd').find_by_name("#{vnf_service.name} #{type} #{network_service.id}") if template @@ -29,9 +29,15 @@ def retire_vnfs(network_service) next end - $evm.log(:info, "Deleting #{vnf_service.name} VNFD orchestration template") - temp_vnfd = $evm.vmdb('orchestration_template_vnfd') - temp_vnfd.destroy(template.id) + $evm.log(:info, "Deleting #{vnf_service.name} VNFD #{template.id} orchestration template") + + url = "http://localhost:3000/api/orchestration_templates/#{template.id}" + options = {:method => :delete, + :url => url, + :verify_ssl => false, + :headers => {"X-Auth-Token" => MIQ_API_TOKEN, + :accept => :json}} + RestClient::Request.execute(options) end # ...but also could be an AWS (CFN) stack @@ -40,7 +46,7 @@ def retire_vnfs(network_service) if stack != nil if vnf_service.orchestration_stack_status[0] == 'create_complete' - stack.raw_delete_stack() + delete_stack(stack) $evm.log(:info, "Retiring #{vnf_service.name}") vnf_service.retire_now() found_stack = true @@ -51,11 +57,18 @@ def retire_vnfs(network_service) if vnf_service.respond_to?(:orchestration_stack_status) && (vnf_service.orchestration_stack_status[0] == 'create_complete' or vnf_service.orchestration_stack_status[0] == 'transient') found_stack = true else + $evm.log(:info, "Finding '#{vnf_service.name} #{network_service.id}' CFN orchestration template for deletion") template = $evm.vmdb('orchestration_template_cfn').find_by_name("#{vnf_service.name} #{network_service.id}") if template != nil $evm.log(:info, "Deleting #{vnf_service.name} CFN orchestration template") - $evm.vmdb('orchestration_template_cfn').destroy(template.id) + url = "http://localhost:3000/api/orchestration_templates/#{template.id}" + options = {:method => :delete, + :url => url, + :verify_ssl => false, + :headers => {"X-Auth-Token" => MIQ_API_TOKEN, + :accept => :json}} + RestClient::Request.execute(options) end end end @@ -66,7 +79,13 @@ def retire_vnfs(network_service) if template != nil $evm.log(:info, "Deleting #{vnf_service.name} networks HOT orchestration template") - $evm.vmdb('orchestration_template_hot').destroy(template.id) + url = "http://localhost:3000/api/orchestration_templates/#{template.id}" + options = {:method => :delete, + :url => url, + :verify_ssl => false, + :headers => {"X-Auth-Token" => MIQ_API_TOKEN, + :accept => :json}} + RestClient::Request.execute(options) end end end @@ -78,7 +97,18 @@ def retire_vnfs(network_service) end end +def delete_stack(stack) + begin + $evm.log(:info, "Deleting stack #{stack}") + stack.raw_delete_stack() + rescue NotImplementedError => e + $evm.log(:info, "Stack #{stack} does not have a raw_delete_stack action") + end +end + begin + require 'rest-client' + nsd = $evm.get_state_var(:nsd) network_service = nil $evm.log("info", "Listing nsd #{nsd}") diff --git a/scripts/OPNFV/NetworkServices/Methods.class/__methods__/run_ansible_jobs.rb b/scripts/OPNFV/NetworkServices/Methods.class/__methods__/run_ansible_jobs.rb index 28b6034..e53d752 100644 --- a/scripts/OPNFV/NetworkServices/Methods.class/__methods__/run_ansible_jobs.rb +++ b/scripts/OPNFV/NetworkServices/Methods.class/__methods__/run_ansible_jobs.rb @@ -4,15 +4,7 @@ def launch_ansible_job(configuration_manager, network_service, parent_service, t else job_name = "#{Time.now.utc} #{template.name}" end - - orchestration_service = $evm.vmdb('ServiceAnsibleTower').create( - :name => job_name) - - # Store the ansible service ids, so we can wait for them in next step - ansible_service_ids = $evm.get_state_var(:ansible_service_ids) - ansible_service_ids << orchestration_service.id - $evm.set_state_var(:ansible_service_ids, ansible_service_ids) - + $evm.log(:info, "Running Ansible Tower template on VM of the type: #{vms.first.type}") if vms.first.type == "ManageIQ::Providers::Amazon::CloudManager::Vm" # TODO figure out, how to pass elastic ip as part of VM inventory, this will work only @@ -22,16 +14,37 @@ def launch_ansible_job(configuration_manager, network_service, parent_service, t vm_names = vms.collect(&:name).join(",") end $evm.log(:info, "Running Ansible Tower template: #{template.name} on VMs: #{vm_names} with properties: #{properties}") - + + resource = {:name => job_name, + :type => "ServiceAnsibleTower", + :job_template => {:id => template.id}, + :parent_service => {:id => parent_service.id}, + :job_options => {:limit => vm_names, :extra_vars => properties}, + :display => true} + + url = "http://localhost:3000/api/services" + options = {:method => :post, + :url => url, + :verify_ssl => false, + :payload => {"action" => "create", + "resource" => resource}.to_json, + :headers => {"X-Auth-Token" => MIQ_API_TOKEN, + :content_type => :json, + :accept => :json}} + $evm.log("info", "Creating Ansible Tower service #{options}") + + body = JSON.parse(RestClient::Request.execute(options)) + + orchestration_service = $evm.vmdb('service', body["results"].first["id"]) + orchestration_service.launch_job + orchestration_service.custom_set(:extra_vars, JSON.pretty_generate(properties)) orchestration_service.custom_set(:limit, vm_names) - - orchestration_service.job_template = template - orchestration_service.configuration_manager = configuration_manager - orchestration_service.job_options = {:limit => vm_names, :extra_vars => properties} - orchestration_service.display = true - orchestration_service.parent_service = parent_service - orchestration_service.launch_job + + # Store the ansible service ids, so we can wait for them in next step + ansible_service_ids = $evm.get_state_var(:ansible_service_ids) + ansible_service_ids << orchestration_service.id + $evm.set_state_var(:ansible_service_ids, ansible_service_ids) end def cps_for_id(network_service, id) @@ -84,8 +97,10 @@ def get_cluster_info(parent_service, network_service) return cluster, subnets end -require 'ipaddr' begin + require 'ipaddr' + require 'rest-client' + nsd = $evm.get_state_var(:nsd) $evm.set_state_var(:ansible_service_ids, []) diff --git a/scripts/OPNFV/Service/Provisioning/StateMachines/OrderNetworkService.class/__methods__/update_serviceprovision_status.rb b/scripts/OPNFV/Service/Provisioning/StateMachines/OrderNetworkService.class/__methods__/update_serviceprovision_status.rb index 108fbf6..576bb8b 100644 --- a/scripts/OPNFV/Service/Provisioning/StateMachines/OrderNetworkService.class/__methods__/update_serviceprovision_status.rb +++ b/scripts/OPNFV/Service/Provisioning/StateMachines/OrderNetworkService.class/__methods__/update_serviceprovision_status.rb @@ -10,11 +10,14 @@ exit(MIQ_STOP) end -# Get status from input field status status = $evm.inputs['status'] -# Update Status for on_entry,on_exit -if $evm.root['ae_result'] != 'retry' - prov.message = status - prov.miq_request.user_message = status -end +# Update Status Message +updated_message = "[#{$evm.root['miq_server'].name}] " +updated_message += "Step [#{$evm.root['ae_state']}] " +updated_message += "Status [#{status}] " +# TODO the message is missleading, figure out why, always says it's processed +# updated_message += "Message [#{prov.message}] " +updated_message += "Current Retry Number [#{$evm.root['ae_state_retries']}]" +prov.miq_request.user_message = updated_message +prov.message = status diff --git a/scripts/OPNFV/Service/Provisioning/StateMachines/ServiceProvision_Template.class/order_network_service.yaml b/scripts/OPNFV/Service/Provisioning/StateMachines/ServiceProvision_Template.class/order_network_service.yaml deleted file mode 100644 index 18fea37..0000000 --- a/scripts/OPNFV/Service/Provisioning/StateMachines/ServiceProvision_Template.class/order_network_service.yaml +++ /dev/null @@ -1,24 +0,0 @@ ---- -object_type: instance -version: 1.0 -object: - attributes: - display_name: - name: order_network_service - inherits: - description: - fields: - - post1: - value: "/NetworkServices/Methods/create_networks_and_subnets" - - post2: - value: "/NetworkServices/Methods/deploy_vnfs" - - post3: - value: "/NetworkServices/Methods/deploy_cfns" - - post4: - value: "/NetworkServices/Methods/check_services_provisioned" - - post5: - value: "/NetworkServices/Methods/wait_for_providers_to_refresh" - - post6: - value: "/NetworkServices/Methods/run_ansible_jobs" - - post7: - value: "/NetworkServices/Methods/check_ansible_jobs_finished"