From 1a3de82cabbe02f24bc66f888bc94621da50d14f Mon Sep 17 00:00:00 2001 From: semedi Date: Wed, 5 Jul 2017 16:30:25 +0200 Subject: [PATCH 01/10] F #5189 az_driver ask for CERTIFICATE ATT --- src/cli/one_helper/onehost_helper.rb | 23 ++++++++++++++++++ src/vmm_mad/remotes/az/az_driver.rb | 35 +++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 4efc658899..c60d8b2d83 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -42,6 +42,29 @@ class OneHostHelper < OpenNebulaHelper::OneHelper # #----------------------------------------------------------------------- EOT + }, + :az => { + :help => <<-EOT.unindent, + #----------------------------------------------------------------------- + # Supported AZURE AUTH ATTRIBUTTES: + # + # CERTIFICATE = + # + # + # + # + # + # + # + # + # + # + # + # + # + # + #----------------------------------------------------------------------- + EOT } } diff --git a/src/vmm_mad/remotes/az/az_driver.rb b/src/vmm_mad/remotes/az/az_driver.rb index 896186f79d..80cbfb022d 100755 --- a/src/vmm_mad/remotes/az/az_driver.rb +++ b/src/vmm_mad/remotes/az/az_driver.rb @@ -33,6 +33,7 @@ require 'yaml' require 'rubygems' require 'azure' require 'uri' +require 'tempfile' $: << RUBY_LIB_LOCATION @@ -161,15 +162,47 @@ class AzureDriver @region['management_endpoint']="https://management.core.windows.net" end + file = Tempfile.new("certificate") + file << get_connect_info(host) + file.close + Azure.configure do |config| - config.management_certificate = @region['pem_management_cert'] + config.management_certificate = file.path config.subscription_id = @region['subscription_id'] config.management_endpoint = @region['management_endpoint'] end + file.unlink # deletes the temp file + + @azure_vms = Azure::VirtualMachineManagementService.new end + def get_connect_info(host) + conn_opts={} + client = OpenNebula::Client.new + + pool = OpenNebula::HostPool.new(OpenNebula::Client.new) + pool.info + objects=pool.select {|object| object.name==host } + xmlhost = objects.first + + system = OpenNebula::System.new(client) + config = system.get_configuration + if OpenNebula.is_error?(config) + puts "Error getting oned configuration : #{config.message}" + exit -1 + end + token = config["ONE_KEY"] + + conn_opts = { + :cert => xmlhost["TEMPLATE/CERTIFICATE"] + } + + return xmlhost["TEMPLATE/CERTIFICATE"]#gsub(/ñ/,"\n") + + end + # DEPLOY action def deploy(id, host, xml_text, lcm_state, deploy_id) if lcm_state == "BOOT" || lcm_state == "BOOT_FAILURE" From 589d7a12309441f6776bf44672c7246fcc6235ca Mon Sep 17 00:00:00 2001 From: semedi Date: Thu, 6 Jul 2017 00:40:15 +0200 Subject: [PATCH 02/10] F #5189 new azure auth options requests --- src/cli/one_helper/onehost_helper.rb | 4 ++-- src/vmm_mad/remotes/az/az_driver.rb | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index c60d8b2d83..02eb43c4ef 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -48,8 +48,8 @@ class OneHostHelper < OpenNebulaHelper::OneHelper #----------------------------------------------------------------------- # Supported AZURE AUTH ATTRIBUTTES: # - # CERTIFICATE = - # + # AZ_ID = + # AZ_CERT = # # # diff --git a/src/vmm_mad/remotes/az/az_driver.rb b/src/vmm_mad/remotes/az/az_driver.rb index 80cbfb022d..894dd43157 100755 --- a/src/vmm_mad/remotes/az/az_driver.rb +++ b/src/vmm_mad/remotes/az/az_driver.rb @@ -162,13 +162,14 @@ class AzureDriver @region['management_endpoint']="https://management.core.windows.net" end + conn_opts = get_connect_info(host) file = Tempfile.new("certificate") - file << get_connect_info(host) + file << conn_opts[:cert] file.close Azure.configure do |config| config.management_certificate = file.path - config.subscription_id = @region['subscription_id'] + config.subscription_id = conn_opts[:id] config.management_endpoint = @region['management_endpoint'] end @@ -178,6 +179,8 @@ class AzureDriver @azure_vms = Azure::VirtualMachineManagementService.new end + # Check the current template to retrieve + # conection info needed for Azure def get_connect_info(host) conn_opts={} client = OpenNebula::Client.new @@ -189,18 +192,16 @@ class AzureDriver system = OpenNebula::System.new(client) config = system.get_configuration - if OpenNebula.is_error?(config) - puts "Error getting oned configuration : #{config.message}" - exit -1 - end + raise "Error getting oned configuration : #{config.message}" if OpenNebula.is_error?(config) + token = config["ONE_KEY"] conn_opts = { - :cert => xmlhost["TEMPLATE/CERTIFICATE"] + :cert => xmlhost["TEMPLATE/AZ_CERT"], + :id => xmlhost["TEMPLATE/AZ_ID"] } - return xmlhost["TEMPLATE/CERTIFICATE"]#gsub(/ñ/,"\n") - + return conn_opts end # DEPLOY action From 046e5bbc80011eddbb957604a016f16aef5a362a Mon Sep 17 00:00:00 2001 From: semedi Date: Fri, 14 Jul 2017 09:39:49 +0200 Subject: [PATCH 03/10] F #5189 Added azure creation host help --- src/cli/one_helper/onehost_helper.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 02eb43c4ef..b6a93bc751 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -48,20 +48,23 @@ class OneHostHelper < OpenNebulaHelper::OneHelper #----------------------------------------------------------------------- # Supported AZURE AUTH ATTRIBUTTES: # - # AZ_ID = - # AZ_CERT = - # - # - # - # - # - # - # + # AZ_ID = + # AZ_CERT = # + # REGION_NAME = # + # CAPACITY = [ + # Small = , + # Medium = , + # Large = # #----------------------------------------------------------------------- EOT From 0708461172140b2c605b3f198099c6d5055cf067 Mon Sep 17 00:00:00 2001 From: semedi Date: Fri, 14 Jul 2017 11:39:27 +0200 Subject: [PATCH 04/10] F #5189 Azure retrieves auth info from template, encrypting test --- src/vmm_mad/remotes/az/az_driver.rb | 43 +++++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/vmm_mad/remotes/az/az_driver.rb b/src/vmm_mad/remotes/az/az_driver.rb index 894dd43157..003465af06 100755 --- a/src/vmm_mad/remotes/az/az_driver.rb +++ b/src/vmm_mad/remotes/az/az_driver.rb @@ -145,36 +145,43 @@ class AzureDriver @instance_types = @public_cloud_az_conf['instance_types'] + certificate = Tempfile.new("certificate") + conn_opts = get_connect_info(host) + + access_id = conn_opts[:id] + endpoint_addr = conn_opts[:endpoint] + region_name = conn_opts[:region] + certificate << conn_opts[:cert] + + certificate.close + + #DEPRECATE + ############################################################# regions = @public_cloud_az_conf['regions'] @region = regions[host] || regions["default"] # Sanitize region data - if @region['pem_management_cert'].nil? + if certificate.nil? raise "pem_management_cert not defined for #{host}" end - if @region['subscription_id'].nil? + if access_id.nil? raise "subscription_id not defined for #{host}" end # Set default endpoint if not declared - if @region['management_endpoint'].nil? - @region['management_endpoint']="https://management.core.windows.net" + if endpoint_addr.nil? + endpoint_addr="https://management.core.windows.net" end - - conn_opts = get_connect_info(host) - file = Tempfile.new("certificate") - file << conn_opts[:cert] - file.close + ################################################################### Azure.configure do |config| - config.management_certificate = file.path - config.subscription_id = conn_opts[:id] - config.management_endpoint = @region['management_endpoint'] + config.management_certificate = certificate.path + config.subscription_id = access_id + config.management_endpoint = endpoint_addr end - file.unlink # deletes the temp file - + certificate.unlink # deletes the temp file @azure_vms = Azure::VirtualMachineManagementService.new end @@ -200,6 +207,12 @@ class AzureDriver :cert => xmlhost["TEMPLATE/AZ_CERT"], :id => xmlhost["TEMPLATE/AZ_ID"] } + conn_opts = OpenNebula.encrypt(conn_opts, token) + conn_opts = OpenNebula.decrypt(conn_opts, token) + + conn_opts[:region] = xmlhost["TEMPLATE/REGION_NAME"] + conn_opts[:endpoint] = xmlhost["TEMPLATE/AZ_ENDPOINT"] + return conn_opts end @@ -329,7 +342,7 @@ class AzureDriver usedcpu += cpu usedmemory += mem end - rescue + rescue next end end From 61604adba61a036bf9817dc0684fc02fd417cf3f Mon Sep 17 00:00:00 2001 From: semedi Date: Fri, 14 Jul 2017 12:46:02 +0200 Subject: [PATCH 05/10] F #5189 azure driver asks about capacity, added retrieve host method --- src/vmm_mad/remotes/az/az_driver.rb | 31 +++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/vmm_mad/remotes/az/az_driver.rb b/src/vmm_mad/remotes/az/az_driver.rb index 003465af06..62c8326347 100755 --- a/src/vmm_mad/remotes/az/az_driver.rb +++ b/src/vmm_mad/remotes/az/az_driver.rb @@ -186,16 +186,20 @@ class AzureDriver @azure_vms = Azure::VirtualMachineManagementService.new end + def get_host_info(client) + pool = OpenNebula::HostPool.new(client) + pool.info + objects=pool.select {|object| object.name==@host } + + objects.first + end + # Check the current template to retrieve # conection info needed for Azure def get_connect_info(host) conn_opts={} client = OpenNebula::Client.new - - pool = OpenNebula::HostPool.new(OpenNebula::Client.new) - pool.info - objects=pool.select {|object| object.name==host } - xmlhost = objects.first + xmlhost = get_host_info(client) system = OpenNebula::System.new(client) config = system.get_configuration @@ -295,12 +299,19 @@ class AzureDriver def monitor_all_vms totalmemory = 0 totalcpu = 0 - @region['capacity'].each { |name, size| - cpu, mem = instance_type_capacity(name) - totalmemory += mem * size.to_i - totalcpu += cpu * size.to_i - } + host_obj=get_host_info(OpenNebula::Client.new) + capacity = host_obj.to_hash["HOST"]["TEMPLATE"]["CAPACITY"] + if !capacity.nil? && Hash === capacity + capacity.each{ |name, value| + cpu, mem = instance_type_capacity(name) + + totalmemory += mem * value.to_i + totalcpu += cpu * value.to_i + } + else + raise "you must define CAPACITY section properly! check the template" + end host_info = "HYPERVISOR=AZURE\n" host_info << "PUBLIC_CLOUD=YES\n" From 5ec658ed278693ae40163dd419397be5d07eb8bb Mon Sep 17 00:00:00 2001 From: semedi Date: Mon, 17 Jul 2017 14:40:55 +0200 Subject: [PATCH 06/10] F #5189 CORE encrypt || fix capacities --- src/host/Host.cc | 19 +++++++++++++++++++ src/vmm_mad/remotes/az/az_driver.rb | 15 ++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/host/Host.cc b/src/host/Host.cc index 17187acd4d..1dc1e75b45 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -726,6 +726,9 @@ int Host::post_update_template(string& error) string ec2_access; string ec2_secret; + string az_id; + string az_cert; + string crypted; get_template_attribute("VCENTER_PASSWORD", vcenter_password); @@ -755,6 +758,22 @@ int Host::post_update_template(string& error) replace_template_attribute("EC2_SECRET", crypted); } + get_template_attribute("AZ_ID", az_id); + + if (!az_id.empty()) + { + nebula_crypt(az_id, crypted); + replace_template_attribute("AZ_ID", crypted); + } + + get_template_attribute("AZ_CERT", az_cert); + + if (!az_cert.empty()) + { + nebula_crypt(az_cert, crypted); + replace_template_attribute("AZ_CERT", crypted); + } + get_template_attribute("IM_MAD", new_im_mad); get_template_attribute("VM_MAD", new_vm_mad); diff --git a/src/vmm_mad/remotes/az/az_driver.rb b/src/vmm_mad/remotes/az/az_driver.rb index 62c8326347..4122f8b2ad 100755 --- a/src/vmm_mad/remotes/az/az_driver.rb +++ b/src/vmm_mad/remotes/az/az_driver.rb @@ -136,6 +136,7 @@ class AzureDriver # Azure constructor, loads credentials and endpoint def initialize(host) @host = host + @to_inst ={} @public_cloud_az_conf = YAML::load(File.read(AZ_DRIVER_CONF)) @@ -144,6 +145,9 @@ class AzureDriver end @instance_types = @public_cloud_az_conf['instance_types'] + @instance_types.keys.each{ |key| + @to_inst[key.upcase] = key + } certificate = Tempfile.new("certificate") conn_opts = get_connect_info(host) @@ -158,7 +162,6 @@ class AzureDriver #DEPRECATE ############################################################# regions = @public_cloud_az_conf['regions'] - @region = regions[host] || regions["default"] # Sanitize region data if certificate.nil? @@ -211,7 +214,7 @@ class AzureDriver :cert => xmlhost["TEMPLATE/AZ_CERT"], :id => xmlhost["TEMPLATE/AZ_ID"] } - conn_opts = OpenNebula.encrypt(conn_opts, token) + #conn_opts = OpenNebula.encrypt(conn_opts, token) conn_opts = OpenNebula.decrypt(conn_opts, token) conn_opts[:region] = xmlhost["TEMPLATE/REGION_NAME"] @@ -372,9 +375,10 @@ private # Get the associated capacity of the instance_type as cpu (in 100 percent # e.g. 800 for 8 cores) and memory (in KB) def instance_type_capacity(name) - return 0, 0 if @instance_types[name].nil? - return (@instance_types[name]['cpu'].to_f * 100).to_i , - (@instance_types[name]['memory'].to_f * 1024 * 1024).to_i + resource = @instance_types[@to_inst[name]] || @instance_types[name] + return 0, 0 if resource.nil? + return (resource['cpu'].to_f * 100).to_i , + (resource['memory'].to_f * 1024 * 1024).to_i end # Get the Azure section of the template. If more than one Azure section @@ -389,6 +393,7 @@ private # First, let's see if we have an Azure location that matches # our host name all_az_elements.each { |element| + cloud_host = element.elements["LOCATION"] type = element.elements["TYPE"].text From 3132c14759b842a6c1907178d8f461bccb15fa80 Mon Sep 17 00:00:00 2001 From: semedi Date: Fri, 21 Jul 2017 14:51:55 +0200 Subject: [PATCH 07/10] azure driver code indentation --- src/vmm_mad/remotes/az/az_driver.rb | 172 ++++++++++++++-------------- 1 file changed, 87 insertions(+), 85 deletions(-) diff --git a/src/vmm_mad/remotes/az/az_driver.rb b/src/vmm_mad/remotes/az/az_driver.rb index 4122f8b2ad..b5eaa28470 100755 --- a/src/vmm_mad/remotes/az/az_driver.rb +++ b/src/vmm_mad/remotes/az/az_driver.rb @@ -226,38 +226,38 @@ class AzureDriver # DEPLOY action def deploy(id, host, xml_text, lcm_state, deploy_id) - if lcm_state == "BOOT" || lcm_state == "BOOT_FAILURE" - load_default_template_values + if lcm_state == "BOOT" || lcm_state == "BOOT_FAILURE" + load_default_template_values - az_info = get_deployment_info(host, xml_text) + az_info = get_deployment_info(host, xml_text) - if !az_value(az_info, 'IMAGE') - raise "Cannot find IMAGE in deployment file" - end + if !az_value(az_info, 'IMAGE') + raise "Cannot find IMAGE in deployment file" + end - csn = az_value(az_info, 'CLOUD_SERVICE') + csn = az_value(az_info, 'CLOUD_SERVICE') - csn = "csn#{id}" if !csn + csn = "csn#{id}" if !csn - create_params = create_params(id,csn,az_info) - create_options = create_options(id,csn,az_info) - instance = nil + create_params = create_params(id,csn,az_info) + create_options = create_options(id,csn,az_info) + instance = nil - in_silence do - instance = @azure_vms.create_virtual_machine(create_params, - create_options) - end + in_silence do + instance = @azure_vms.create_virtual_machine(create_params, + create_options) + end - if instance.class == Azure::VirtualMachineManagement::VirtualMachine - puts(instance.vm_name) + if instance.class == Azure::VirtualMachineManagement::VirtualMachine + puts(instance.vm_name) + else + raise "Deployment failure " + instance + end else - raise "Deployment failure " + instance + restore(deploy_id) + deploy_id end - else - restore(deploy_id) - deploy_id - end end # Shutdown an Azure instance @@ -405,87 +405,89 @@ private } if !az - # If we don't find an Azure location, and ONE just - # knows about one Azure location, let's use that - if all_az_elements.size == 1 and - all_az_elements[0].elements["TYPE"].text.downcase.eql? "azure" - az = all_az_elements[0] - else - STDERR.puts( - "Cannot find Azure element in VM template "<< - "or couldn't find any Azure location matching "<< - "one of the templates.") - exit(-1) - end - end + # If we don't find an Azure location, and ONE just + # knows about one Azure location, let's use that + if all_az_elements.size == 1 and + all_az_elements[0].elements["TYPE"].text.downcase.eql? "azure" + az = all_az_elements[0] + else + STDERR.puts( + "Cannot find Azure element in VM template "<< + "or couldn't find any Azure location matching "<< + "one of the templates.") + exit(-1) + end + end - # If LOCATION not explicitly defined, try to get default, if not - # try to use hostname as datacenter - if !az.elements["LOCATION"] + # location can be retrieved from host information... + + # If LOCATION not explicitly defined, try to get default, if not + # try to use hostname as datacenter + if !az.elements["LOCATION"] location=REXML::Element.new("LOCATION") if @defaults["LOCATION"] - location.text=@defaults["LOCATION"] + location.text=@defaults["LOCATION"] else - location.text=host + location.text=host end az.elements << location - end + end - # Translate region name form keyword to actual value - region_keyword = az.elements["LOCATION"].text - translated_region = @public_cloud_az_conf["regions"][region_keyword] - az.elements["LOCATION"].text=translated_region["region_name"] + # Translate region name form keyword to actual value + region_keyword = az.elements["LOCATION"].text + translated_region = @public_cloud_az_conf["regions"][region_keyword] + az.elements["LOCATION"].text=translated_region["region_name"] - az + az end # Retrive the vm information from the Azure instance def parse_poll(instance) - begin - info = "#{POLL_ATTRIBUTE[:memory]}=0 " \ - "#{POLL_ATTRIBUTE[:cpu]}=0 " \ - "#{POLL_ATTRIBUTE[:nettx]}=0 " \ - "#{POLL_ATTRIBUTE[:netrx]}=0 " + begin + info = "#{POLL_ATTRIBUTE[:memory]}=0 " \ + "#{POLL_ATTRIBUTE[:cpu]}=0 " \ + "#{POLL_ATTRIBUTE[:nettx]}=0 " \ + "#{POLL_ATTRIBUTE[:netrx]}=0 " - state = "" - if !instance - state = VM_STATE[:deleted] - else - state = case instance.deployment_status - when "Running", "Starting" - VM_STATE[:active] - when "Suspended", "Stopping", - VM_STATE[:paused] + state = "" + if !instance + state = VM_STATE[:deleted] else - VM_STATE[:unknown] - end - end - info << "#{POLL_ATTRIBUTE[:state]}=#{state} " - - AZ_POLL_ATTRS.map { |key| - value = instance.send(key) - if !value.nil? && !value.empty? - if key.to_s.upcase == "TCP_ENDPOINTS" or - key.to_s.upcase == "UDP_ENDPOINTS" - value_str = format_endpoints(value) - elsif value.kind_of?(Hash) - value_str = value.inspect + state = case instance.deployment_status + when "Running", "Starting" + VM_STATE[:active] + when "Suspended", "Stopping", + VM_STATE[:paused] else - value_str = value + VM_STATE[:unknown] end - - info << "AZ_#{key.to_s.upcase}=" - info << "\\\"#{value_str.gsub("\"","")}\\\" " - end - } + info << "#{POLL_ATTRIBUTE[:state]}=#{state} " - info - rescue - # Unknown state if exception occurs retrieving information from - # an instance - "#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:unknown]} " - end + AZ_POLL_ATTRS.map { |key| + value = instance.send(key) + if !value.nil? && !value.empty? + if key.to_s.upcase == "TCP_ENDPOINTS" or + key.to_s.upcase == "UDP_ENDPOINTS" + value_str = format_endpoints(value) + elsif value.kind_of?(Hash) + value_str = value.inspect + else + value_str = value + end + + info << "AZ_#{key.to_s.upcase}=" + info << "\\\"#{value_str.gsub("\"","")}\\\" " + + end + } + + info + rescue + # Unknown state if exception occurs retrieving information from + # an instance + "#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:unknown]} " + end end def format_endpoints(endpoints) From 98ab93f2c520f5ecf1e7a75cc3e9dddacfcaa1ca Mon Sep 17 00:00:00 2001 From: semedi Date: Tue, 25 Jul 2017 11:08:12 +0200 Subject: [PATCH 08/10] F #5189 core changes hybrid encrypt --- src/host/Host.cc | 127 ++++++++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 51 deletions(-) diff --git a/src/host/Host.cc b/src/host/Host.cc index 1dc1e75b45..359080e6f1 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -23,6 +23,43 @@ #include "Host.h" #include "Nebula.h" +/* -------------------------------------------------------------------------- */ +/* Hybrid constants */ +/* -------------------------------------------------------------------------- */ + +struct Hinfo +{ + const char *attr_name; + unsigned int bytes; +}; + +struct HybridVariable +{ + string hybrid_name; + vector template_atts; +}; + +const vector EC2 = { + {"EC2_ACCESS", 21}, + {"EC2_SECRET", 41} +}; + +const vector AZURE = { + {"AZ_ID", 41}, + {"AZ_CERT", 3130} +}; + +const vector VCENTER = { + {"VCENTER_PASSWORD", 22} +}; + +const vector REMOTE_PROVIDERS = { + {"vcenter", VCENTER}, + {"ec2", EC2}, + {"azure", AZURE} +}; + + /* ************************************************************************ */ /* Host :: Constructor/Destructor */ /* ************************************************************************ */ @@ -714,65 +751,53 @@ static void nebula_crypt(const std::string in, std::string& out) out = in; } } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ +/* HYBRID - static Interface */ +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ +static void hide_auth_fields (const vector& tfields, Host *host) +{ + string att; + string name; + string crypted; + vector::const_iterator it; + for (it = tfields.begin(); it != tfields.end() ; ++it) + { + + name = (*it).attr_name; + + host->get_template_attribute(name.c_str(), att); + + if (!att.empty() && att.size() <= (*it).bytes) + { + nebula_crypt(att, crypted); + host->replace_template_attribute(name.c_str(), crypted); + } + } +} + +static void update_hybrid (const vector& hvars, Host *host) +{ + vector::const_iterator it; + + for (it = hvars.begin(); it != hvars.end() ; ++it) + { + hide_auth_fields((*it).template_atts, host); + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ int Host::post_update_template(string& error) { - string vcenter_password; string new_im_mad; string new_vm_mad; - string ec2_access; - string ec2_secret; - - string az_id; - string az_cert; - - string crypted; - - get_template_attribute("VCENTER_PASSWORD", vcenter_password); - - if (!vcenter_password.empty() && vcenter_password.size() <= 22) - { - nebula_crypt(vcenter_password, crypted); - - replace_template_attribute("VCENTER_PASSWORD", crypted); - } - - get_template_attribute("EC2_ACCESS", ec2_access); - - if (!ec2_access.empty() && ec2_access.size() <= 21) - { - nebula_crypt(ec2_access, crypted); - - replace_template_attribute("EC2_ACCESS", crypted); - } - - get_template_attribute("EC2_SECRET", ec2_secret); - - if (!ec2_secret.empty() && ec2_secret.size() <= 41) - { - nebula_crypt(ec2_secret, crypted); - - replace_template_attribute("EC2_SECRET", crypted); - } - - get_template_attribute("AZ_ID", az_id); - - if (!az_id.empty()) - { - nebula_crypt(az_id, crypted); - replace_template_attribute("AZ_ID", crypted); - } - - get_template_attribute("AZ_CERT", az_cert); - - if (!az_cert.empty()) - { - nebula_crypt(az_cert, crypted); - replace_template_attribute("AZ_CERT", crypted); - } + update_hybrid(REMOTE_PROVIDERS, this); get_template_attribute("IM_MAD", new_im_mad); get_template_attribute("VM_MAD", new_vm_mad); From f87ca90bd716ca8c1639c183e5c727477fa20194 Mon Sep 17 00:00:00 2001 From: semedi Date: Tue, 25 Jul 2017 14:01:27 +0200 Subject: [PATCH 09/10] F #5189 small fix LOCATION and az conf file --- src/vmm_mad/remotes/az/az_driver.conf | 94 --------------------------- src/vmm_mad/remotes/az/az_driver.rb | 15 +---- 2 files changed, 3 insertions(+), 106 deletions(-) diff --git a/src/vmm_mad/remotes/az/az_driver.conf b/src/vmm_mad/remotes/az/az_driver.conf index c4a1301add..3ba2eeb7e1 100644 --- a/src/vmm_mad/remotes/az/az_driver.conf +++ b/src/vmm_mad/remotes/az/az_driver.conf @@ -1,98 +1,4 @@ proxy_uri: -regions: - default: - region_name: "West Europe" - # pem_management_cert --> Absolute path to pem management certificate - # Info on creating certificates: - # http://azure.microsoft.com/en-us/documentation/articles/linux-use-ssh-key/ - pem_management_cert: - subscription_id: - management_endpoint: - capacity: - Small: 5 - Medium: 1 - Large: 0 - west-europe: - region_name: "West Europe" - pem_management_cert: - subscription_id: - management_endpoint: - capacity: - Small: 5 - Medium: 1 - Large: 0 - north-europe: - region_name: "North Europe" - pem_management_cert: - subscription_id: - management_endpoint: - capacity: - Small: - Medium: - Large: - east-us: - region_name: "East US" - pem_management_cert: - subscription_id: - management_endpoint: - capacity: - Small: - Medium: - Large: - south-central-us: - region_name: "South Central US" - pem_management_cert: - subscription_id: - management_endpoint: - capacity: - Small: - Medium: - Large: - west-us: - region_name: "West US" - pem_management_cert: - subscription_id: - management_endpoint: - capacity: - Small: - Medium: - Large: - east-asia: - region_name: "East Asia" - pem_management_cert: - subscription_id: - management_endpoint: - capacity: - Small: - Medium: - Large: - southeast-asia: - region_name: "Southeast Asia" - pem_management_cert: - subscription_id: - management_endpoint: - capacity: - Small: - Medium: - Large: - japan-west: - region_name: "Japan West" - pem_management_cert: - subscription_id: - management_endpoint: - capacity: - Small: - Medium: - Large: - brazil-south: - region_name: "Brazil South" - pem_management_cert: - subscription_id: - management_endpoint: - capacity: - Small: - Medium: - Large: instance_types: ExtraSmall: cpu: 1 diff --git a/src/vmm_mad/remotes/az/az_driver.rb b/src/vmm_mad/remotes/az/az_driver.rb index b5eaa28470..1e2ccb7f9e 100755 --- a/src/vmm_mad/remotes/az/az_driver.rb +++ b/src/vmm_mad/remotes/az/az_driver.rb @@ -154,15 +154,11 @@ class AzureDriver access_id = conn_opts[:id] endpoint_addr = conn_opts[:endpoint] - region_name = conn_opts[:region] + @region_name = conn_opts[:region] certificate << conn_opts[:cert] certificate.close - #DEPRECATE - ############################################################# - regions = @public_cloud_az_conf['regions'] - # Sanitize region data if certificate.nil? raise "pem_management_cert not defined for #{host}" @@ -425,19 +421,14 @@ private # try to use hostname as datacenter if !az.elements["LOCATION"] location=REXML::Element.new("LOCATION") - if @defaults["LOCATION"] - location.text=@defaults["LOCATION"] + if @region_name + location.text=@region_name else location.text=host end az.elements << location end - # Translate region name form keyword to actual value - region_keyword = az.elements["LOCATION"].text - translated_region = @public_cloud_az_conf["regions"][region_keyword] - az.elements["LOCATION"].text=translated_region["region_name"] - az end From 16b87308a1e61b395f6a439397dcfd54299c8f6b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 1 Aug 2017 13:43:31 +0200 Subject: [PATCH 10/10] F #5189: Put limits in just one constant --- src/host/Host.cc | 101 ++++++++++++----------------------------------- 1 file changed, 26 insertions(+), 75 deletions(-) diff --git a/src/host/Host.cc b/src/host/Host.cc index 359080e6f1..e0a98c9e70 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -23,43 +23,6 @@ #include "Host.h" #include "Nebula.h" -/* -------------------------------------------------------------------------- */ -/* Hybrid constants */ -/* -------------------------------------------------------------------------- */ - -struct Hinfo -{ - const char *attr_name; - unsigned int bytes; -}; - -struct HybridVariable -{ - string hybrid_name; - vector template_atts; -}; - -const vector EC2 = { - {"EC2_ACCESS", 21}, - {"EC2_SECRET", 41} -}; - -const vector AZURE = { - {"AZ_ID", 41}, - {"AZ_CERT", 3130} -}; - -const vector VCENTER = { - {"VCENTER_PASSWORD", 22} -}; - -const vector REMOTE_PROVIDERS = { - {"vcenter", VCENTER}, - {"ec2", EC2}, - {"azure", AZURE} -}; - - /* ************************************************************************ */ /* Host :: Constructor/Destructor */ /* ************************************************************************ */ @@ -730,6 +693,9 @@ int Host::from_xml(const string& xml) return 0; } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + static void nebula_crypt(const std::string in, std::string& out) { Nebula& nd = Nebula::instance(); @@ -751,53 +717,38 @@ static void nebula_crypt(const std::string in, std::string& out) out = in; } } -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ -/* HYBRID - static Interface */ -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ -static void hide_auth_fields (const vector& tfields, Host *host) -{ - string att; - string name; - string crypted; - vector::const_iterator it; - - for (it = tfields.begin(); it != tfields.end() ; ++it) - { - - name = (*it).attr_name; - - host->get_template_attribute(name.c_str(), att); - - if (!att.empty() && att.size() <= (*it).bytes) - { - nebula_crypt(att, crypted); - host->replace_template_attribute(name.c_str(), crypted); - } - } -} - -static void update_hybrid (const vector& hvars, Host *host) -{ - vector::const_iterator it; - - for (it = hvars.begin(); it != hvars.end() ; ++it) - { - hide_auth_fields((*it).template_atts, host); - } -} /* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ +static const map MAX_HOST_VAR_SIZES = { + {"EC2_ACCESS", 21}, + {"EC2_SECRET", 41}, + {"AZ_ID", 41}, + {"AZ_CERT", 3130}, + {"VCENTER_PASSWORD", 22} +}; int Host::post_update_template(string& error) { string new_im_mad; string new_vm_mad; - update_hybrid(REMOTE_PROVIDERS, this); + map::const_iterator it; + + for (it = MAX_HOST_VAR_SIZES.begin(); it != MAX_HOST_VAR_SIZES.end() ; ++it) + { + string att; + string crypted; + + get_template_attribute(it->first.c_str(), att); + + if (!att.empty() && att.size() <= it->second) + { + nebula_crypt(att, crypted); + + replace_template_attribute(it->first, crypted); + } + } get_template_attribute("IM_MAD", new_im_mad); get_template_attribute("VM_MAD", new_vm_mad);