diff --git a/install.sh b/install.sh index dafb77251a..36383285ad 100755 --- a/install.sh +++ b/install.sh @@ -352,12 +352,14 @@ VAR_DIRS="$VAR_LOCATION/remotes \ $VAR_LOCATION/remotes/im/lxd-probes.d/host/system \ $VAR_LOCATION/remotes/im/lxd-probes.d/vm/monitor \ $VAR_LOCATION/remotes/im/lxd-probes.d/vm/status \ + $VAR_LOCATION/remotes/im/lxd-probes.d/vm/snapshot \ $VAR_LOCATION/remotes/im/firecracker.d \ $VAR_LOCATION/remotes/im/firecracker-probes.d/host/beacon \ $VAR_LOCATION/remotes/im/firecracker-probes.d/host/monitor \ $VAR_LOCATION/remotes/im/firecracker-probes.d/host/system \ $VAR_LOCATION/remotes/im/firecracker-probes.d/vm/monitor \ $VAR_LOCATION/remotes/im/firecracker-probes.d/vm/status \ + $VAR_LOCATION/remotes/im/firecracker-probes.d/vm/snapshot \ $VAR_LOCATION/remotes/im/vcenter.d \ $VAR_LOCATION/remotes/im/ec2.d \ $VAR_LOCATION/remotes/im/ec2-probes.d/host/beacon \ @@ -2382,7 +2384,7 @@ ONEPROVISION_CONF_FILES="src/cli/etc/oneprovision.yaml \ ONEPROVISION_ANSIBLE_FILES="share/oneprovision/ansible" -ONEPROVISION_TEMPLATES_FILES="share/oneprovision/provisions" +ONEPROVISION_TEMPLATES_FILES="share/oneprovision/provisions/" ONEPROVISION_LIB_FILES="src/oneprovision/lib/oneprovision.rb \ src/oneprovision/lib/provision_element.rb" diff --git a/src/cli/one_helper/oneprovision_helper.rb b/src/cli/one_helper/oneprovision_helper.rb index 982c6eeec8..9c528c1722 100644 --- a/src/cli/one_helper/oneprovision_helper.rb +++ b/src/cli/one_helper/oneprovision_helper.rb @@ -450,9 +450,8 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper # # @param host [OpenNebula::Host] # @param operation [String] Operation to perform - # @param options [Hash] User CLI options # @param args [Array] Operation arguments - def host_operation(host, operation, options, args) + def host_operation(host, operation, args) p_id = host['TEMPLATE/PROVISION/ID'] return OpenNebula::Error.new('No provision ID found') unless p_id @@ -471,7 +470,7 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper when 'delete' provision.update_objects('hosts', :remove, host.one['ID']) when 'configure' - host.configure((options.key? :force)) + host.configure when 'ssh' host.ssh(args) end @@ -503,7 +502,7 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper case type when 'HOSTS' - host_operation(obj, operation, options, args[1]) + host_operation(obj, operation, args[1]) else msg = "Deleting #{type} #{obj['ID']}" diff --git a/src/cli/onemarketapp b/src/cli/onemarketapp index 708fd32bfb..057b4f8f65 100755 --- a/src/cli/onemarketapp +++ b/src/cli/onemarketapp @@ -42,6 +42,9 @@ require 'one_helper/onemarketapp_helper' require 'one_helper/onemarket_helper' require 'one_helper/onedatastore_helper' +require 'vcenter_driver' +CONFIG = VCenterConf.new + CommandParser::CmdParser.new(ARGV) do usage '`onemarket` [] []' version OpenNebulaHelper::ONE_VERSION @@ -101,6 +104,13 @@ CommandParser::CmdParser.new(ARGV) do end } + TEMPLATE = { + :name => 'template', + :large => '--template template_id ', + :description => 'Associate with VM template', + :format => Integer, + } + MARKET = { :name => 'market', :large => '--market market_id', @@ -123,7 +133,8 @@ CommandParser::CmdParser.new(ARGV) do OneDatastoreHelper::FILE_DATASTORE, OneMarketPlaceAppHelper::VMNAME, TAG, - NO] + NO, + TEMPLATE] IMPORT_OPTIONS = [YES, NO, MARKET, OneMarketPlaceAppHelper::VMNAME] ######################################################################## @@ -272,7 +283,9 @@ CommandParser::CmdParser.new(ARGV) do :name => args[1], :vmtemplate_name => options[:vmname], :url_args => tag, - :notemplate => options[:no] == 'no' + :notemplate => options[:no] == 'no', + :template => options[:template], + :default_template => CONFIG[:default_template], ) if OpenNebula.is_error?(rc) diff --git a/src/cli/oneprovision b/src/cli/oneprovision index e7ba66612e..83bdce9fc6 100755 --- a/src/cli/oneprovision +++ b/src/cli/oneprovision @@ -123,6 +123,9 @@ CommandParser::CmdParser.new(ARGV) do if OpenNebula.is_error?(rc) STDERR.puts rc.message exit(-1) + elsif rc < 0 + puts "ID: #{rc}" + rc else puts "ID: #{rc}" 0 @@ -261,8 +264,7 @@ CommandParser::CmdParser.new(ARGV) do command [:host, :configure], host_configure_desc, [:range, :hostid_list], - :options => [OneProvisionHelper::MODES, - OneProvisionHelper::FORCE] do + :options => [OneProvisionHelper::MODES] do operation = { :operation => 'configure', :message => 'enabled' } rc = helper.resources_operation(args, operation, options, 'HOSTS') diff --git a/src/fireedge/.eslintrc b/src/fireedge/.eslintrc index 1bc7e45a53..22108bb5a8 100644 --- a/src/fireedge/.eslintrc +++ b/src/fireedge/.eslintrc @@ -2,8 +2,7 @@ "env": { "browser": true, "es2021": true, - "node": true, - "cypress/globals": true + "node": true }, "extends": [ "plugin:react/recommended", @@ -16,12 +15,8 @@ "ecmaVersion": 12, "sourceType": "module" }, - "plugins": ["react", "cypress"], + "plugins": ["react"], "rules": { - "cypress/no-assigning-return-values": "error", - "cypress/no-unnecessary-waiting": "error", - "cypress/assertion-before-screenshot": "warn", - "cypress/no-async-tests": "error", "import/no-extraneous-dependencies": [ "error", { diff --git a/src/fireedge/cypress/plugins/index.js b/src/fireedge/cypress/plugins/index.js deleted file mode 100644 index fd170fba69..0000000000 --- a/src/fireedge/cypress/plugins/index.js +++ /dev/null @@ -1,17 +0,0 @@ -// *********************************************************** -// This example plugins/index.js can be used to load plugins -// -// You can change the location of this file or turn off loading -// the plugins file with the 'pluginsFile' configuration option. -// -// You can read more here: -// https://on.cypress.io/plugins-guide -// *********************************************************** - -// This function is called when a project is opened or re-opened (e.g. due to -// the project's config changing) - -module.exports = (on, config) => { - // `on` is used to hook into various events Cypress emits - // `config` is the resolved Cypress config -} diff --git a/src/fireedge/cypress/support/index.js b/src/fireedge/cypress/support/index.js deleted file mode 100644 index d68db96df2..0000000000 --- a/src/fireedge/cypress/support/index.js +++ /dev/null @@ -1,20 +0,0 @@ -// *********************************************************** -// This example support/index.js is processed and -// loaded automatically before your test files. -// -// This is a great place to put global configuration and -// behavior that modifies Cypress. -// -// You can change the location of this file or turn off -// automatically serving support files with the -// 'supportFile' configuration option. -// -// You can read more here: -// https://on.cypress.io/configuration -// *********************************************************** - -// Import commands.js using ES2015 syntax: -import './commands' - -// Alternatively you can use CommonJS syntax: -// require('./commands') diff --git a/src/fireedge/package.json b/src/fireedge/package.json index 6b53f39026..7be19ee137 100644 --- a/src/fireedge/package.json +++ b/src/fireedge/package.json @@ -27,7 +27,6 @@ "opennebula" ], "devDependencies": { - "cypress": "^6.2.1", "eslint": "^7.11.0", "eslint-config-prettier": "^6.11.0", "eslint-config-standard": "^14.1.1", diff --git a/src/flow/lib/LifeCycleManager.rb b/src/flow/lib/LifeCycleManager.rb index 662d311105..97476f5135 100644 --- a/src/flow/lib/LifeCycleManager.rb +++ b/src/flow/lib/LifeCycleManager.rb @@ -772,7 +772,7 @@ class ServiceLCM next unless role.nodes.find {|n| n['deploy_id'] == node } # just update if the cardinality is positive - set_cardinality(role, cardinality, false) if cardinality >= 0 + set_cardinality(role, cardinality, true) if cardinality >= 0 role.nodes.delete_if {|n| n['deploy_id'] == node } diff --git a/src/oca/ruby/opennebula/marketplaceapp_ext.rb b/src/oca/ruby/opennebula/marketplaceapp_ext.rb index d1badc655c..1e72fb0a3e 100644 --- a/src/oca/ruby/opennebula/marketplaceapp_ext.rb +++ b/src/oca/ruby/opennebula/marketplaceapp_ext.rb @@ -89,12 +89,14 @@ module OpenNebula::MarketPlaceAppExt private # Exports an OpenNebula Image from this marketplace app - # @param optoins to export the image + # @param options to export the image # :vmtemplate_name [String] name of new image and template # :url_args [String] optional URL arguments # :dsid [String] Datastore id to create the image # :f_dsid [String] Files Datastore id # :notemplate [Bool] if true do not create vm_template (if any) + # :template [Integer] Template id to use with image + # :default_template [String] Default template id for vCenter # @return [Hash] # :image [Array] of the new image # :image_type [String] of the new image (CONTEXT, KERNEL, CDROM) @@ -181,19 +183,41 @@ module OpenNebula::MarketPlaceAppExt return rc_info end - tmpl = Base64.decode64(self['TEMPLATE/VMTEMPLATE64']) - tmpl << <<-EOT + if !options[:template].nil? + template_id = options[:template] - NAME = "#{options[:vmtemplate_name] || options[:name]}" - DISK = [ IMAGE_ID = "#{image.id}" ] - EOT + template_id = options[:default_template] if template_id == -1 - vmtpl = Template.new(Template.build_xml, @client) + template = Template.new_with_id(template_id, @client) - rc = vmtpl.allocate(tmpl) - rc = vmtpl.id unless OpenNebula.is_error?(rc) + vmtpl_id = template.clone(options[:vmtemplate_name] || options[:name]) - rc_info[:vmtemplate] = [rc] + tmpl << <<-EOT + + NAME = "#{options[:vmtemplate_name] || options[:name]}" + DISK = [ IMAGE_ID = "#{image.id}" ] + EOT + + template = Template.new_with_id(vmtpl_id, @client) + + template.update(tmpl, true) + + rc_info[:vmtemplate] = [vmtpl_id] + else + tmpl = Base64.decode64(self['TEMPLATE/VMTEMPLATE64']) + tmpl << <<-EOT + + NAME = "#{options[:vmtemplate_name] || options[:name]}" + DISK = [ IMAGE_ID = "#{image.id}" ] + EOT + + vmtpl = Template.new(Template.build_xml, @client) + + rc = vmtpl.allocate(tmpl) + rc = vmtpl.id unless OpenNebula.is_error?(rc) + + rc_info[:vmtemplate] = [rc] + end rc_info end @@ -218,7 +242,7 @@ module OpenNebula::MarketPlaceAppExt unless OpenNebula.is_error?(vmtmpl[0]) rc[:image] += vmtmpl[1] - rc[:vmtemplate] += vmtmpl[2] + rc[:vmtemplate] += vmtmpl[2] unless options[:notemplate] end rc diff --git a/src/oneprovision/lib/provision/ansible.rb b/src/oneprovision/lib/provision/ansible.rb index d25c170843..28835cbdba 100644 --- a/src/oneprovision/lib/provision/ansible.rb +++ b/src/oneprovision/lib/provision/ansible.rb @@ -83,7 +83,7 @@ module OneProvision # @param hosts [OpenNebula::Datastore array] Datastores for vars # @param provision [OpenNebula::Provision] Provision info # @param ping [Boolean] True to check ping to hosts - def configure(hosts, datastores, provision = nil, ping = true) + def configure(hosts, datastores = nil, provision = nil, ping = true) return if hosts.nil? || hosts.empty? Driver.retry_loop('Failed to configure hosts', provision) do diff --git a/src/oneprovision/lib/provision/provision.rb b/src/oneprovision/lib/provision/provision.rb index c4d8f83107..1e9b4eefa5 100644 --- a/src/oneprovision/lib/provision/provision.rb +++ b/src/oneprovision/lib/provision/provision.rb @@ -317,7 +317,7 @@ module OneProvision end if skip == :none - configure + configure_resources else info_objects('hosts', true) {|h| h.enable } end @@ -351,19 +351,7 @@ module OneProvision return OpenNebula::Error.new('Provision already configured') end - self.state = STATE['CONFIGURING'] - - update - - rc = Ansible.configure(hosts, datastores, self) - - if rc == 0 - self.state = STATE['RUNNING'] - else - self.state = STATE['ERROR'] - end - - update + configure_resources end # Deletes provision objects @@ -371,6 +359,8 @@ module OneProvision # @param cleanup [Boolean] True to delete running VMs and images # @param timeout [Integer] Timeout for deleting running VMs def delete(cleanup, timeout) + exist = true + if running_vms? && !cleanup Utils.fail('Provision with running VMs can\'t be deleted') end @@ -416,9 +406,13 @@ module OneProvision rc = super() + exist = false + return rc if OpenNebula.is_error?(rc) 0 + ensure + unlock if exist end # Updates provision objects @@ -691,6 +685,23 @@ module OneProvision end end + # Configures provision resources + def configure_resources + self.state = STATE['CONFIGURING'] + + update + + rc = Ansible.configure(hosts, datastores, self) + + if rc == 0 + self.state = STATE['RUNNING'] + else + self.state = STATE['ERROR'] + end + + update + end + # Updates provision hosts with new name # # @param ips [Array] IPs for each host diff --git a/src/oneprovision/lib/provision/resources/physical/host.rb b/src/oneprovision/lib/provision/resources/physical/host.rb index a1dd051f1e..b6deb68504 100644 --- a/src/oneprovision/lib/provision/resources/physical/host.rb +++ b/src/oneprovision/lib/provision/resources/physical/host.rb @@ -204,11 +204,8 @@ module OneProvision end # Configures the HOST - # - # @param force [Boolean] Force the configuration if the HOST - # is already configured - def configure(force) - Ansible.configure([{ 'id' => @one['ID'] }], force) + def configure + Ansible.configure([{ 'id' => @one['ID'] }]) end # Checks that the HOST is a baremetal HOST diff --git a/src/vmm_mad/remotes/vcenter/vcenterrc b/src/vmm_mad/remotes/vcenter/vcenterrc index 52ea919a79..c85fc301f3 100644 --- a/src/vmm_mad/remotes/vcenter/vcenterrc +++ b/src/vmm_mad/remotes/vcenter/vcenterrc @@ -35,4 +35,7 @@ :memory_dumps: true # Cache expiration for monitoring -:cache_expire: 120 \ No newline at end of file +:cache_expire: 120 + +# Default template when import from MarketPlace +:default_template: -1