Class: Nifty::Backends::Opennebula
- Inherits:
-
Nifty::Backend
- Object
- Nifty::Backend
- Nifty::Backends::Opennebula
- Defined in:
- lib/nifty/backends/opennebula.rb
Overview
OpenNebula backend
Constant Summary collapse
- VMCATCHER_APPLIANCE_ID =
'VMCATCHER_EVENT_DC_IDENTIFIER'- VMCATCHER_APPLIANCE_VERSION =
'VMCATCHER_EVENT_HV_VERSION'- VMCATCHER_APPLIANCE_TITLE =
'VMCATCHER_EVENT_DC_TITLE'- VMCATCHER_APPLIANCE_DESCRIPTION =
'VMCATCHER_EVENT_DC_DESCRIPTION'- VMCATCHER_APPLIANCE_OS_ARCH =
'VMCATCHER_EVENT_SL_ARCH'- VMCATCHER_APPLIANCE_OS_DISTRIBUTION =
'VMCATCHER_EVENT_SL_OS'- VMCATCHER_APPLIANCE_OS_VERSION =
'VMCATCHER_EVENT_SL_OSVERSION'
Class Method Summary collapse
- .backend? ⇒ Boolean
- .create_event(event_class, appliance, transfer_method, parameters) ⇒ Object
- .description ⇒ Object
- .migrate(parameters) ⇒ Object
- .migrate_options ⇒ Object
- .options ⇒ Object
- .pre(parameters) ⇒ Object
Methods inherited from Nifty::Backend
Class Method Details
.backend? ⇒ Boolean
17 18 19 |
# File 'lib/nifty/backends/opennebula.rb', line 17 def backend? true end |
.create_event(event_class, appliance, transfer_method, parameters) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/nifty/backends/opennebula.rb', line 107 def create_event(event_class, appliance, transfer_method, parameters) client = Nifty::Backends::Utils::Opennebula::Helper.client(parameters[:secret], parameters[:endpoint]) datastores = Nifty::Backends::Utils::Opennebula::DatastoreHandler.new(client).datastores(parameters[:datastores]) event_class.new(appliance, transfer_method, client, datastores, parameters) rescue Nifty::Errors::Backends::OpennebulaError => ex fail Nifty::Errors::BackendError, ex end |
.description ⇒ Object
22 23 24 |
# File 'lib/nifty/backends/opennebula.rb', line 22 def description "OpenNebula backend" end |
.migrate(parameters) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/nifty/backends/opennebula.rb', line 115 def migrate(parameters) client = Nifty::Backends::Utils::Opennebula::Helper.client(parameters[:secret], parameters[:endpoint]) image_handler = Nifty::Backends::Utils::Opennebula::ImageHandler.new(client) template_handler = Nifty::Backends::Utils::Opennebula::TemplateHandler.new(client) image_handler.unmanaged_images.each do |image| image_name = image.name logger.debug "Processing image #{image_name}" os = Cloud::Appliance::Descriptor::Os.new os.arch = image["TEMPLATE/#{VMCATCHER_APPLIANCE_OS_ARCH}"] os.version = image["TEMPLATE/#{VMCATCHER_APPLIANCE_OS_VERSION}"] os.distribution = image["TEMPLATE/#{VMCATCHER_APPLIANCE_OS_DISTRIBUTION}"] appliance = Cloud::Appliance::Descriptor::Appliance.new os: os appliance.identifier = image["TEMPLATE/#{VMCATCHER_APPLIANCE_ID}"] appliance.version = image["TEMPLATE/#{VMCATCHER_APPLIANCE_VERSION}"] appliance.title = image["TEMPLATE/#{VMCATCHER_APPLIANCE_TITLE}"] appliance.description = image["TEMPLATE/#{VMCATCHER_APPLIANCE_DESCRIPTION}"] image_template = Tilt::ERBTemplate.new(File.join(Nifty::GEM_DIR, 'templates', 'image.erb')) image_template_update = image_template.render(Object.new, {name: image_name, appliance: appliance}) logger.debug("Updating image template for image #{image_name}") Nifty::Backends::Utils::Opennebula::Helper.handle_opennebula_error { image.update(image_template_update, true) } logger.debug("Looking for templates with image #{image_name}...") template_handler.unmanaged_templates_with_image(image_name).each do |template| template_name = template.name logger.debug "Processing template #{template_name}" template_template = Tilt::ERBTemplate.new(File.join(Nifty::GEM_DIR, 'templates', 'template.erb')) template_template_update = template_template.render(Object.new, {name: template_name, appliance: appliance}) logger.debug("Updating template template for template #{template_name}") Nifty::Backends::Utils::Opennebula::Helper.handle_opennebula_error { template.update(template_template_update, true) } end end Nifty::ExitCodes::NO_ERROR_EXIT_CODE rescue Nifty::Errors::Backends::OpennebulaError => ex logger.error "Migration error: #{ex.message}" Nifty::ExitCodes::MIGRATION_ERROR_EXIT_CODE end |
.migrate_options ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/nifty/backends/opennebula.rb', line 78 def { :secret => { :type => :string, :desc => 'Pair of username and password in form of \'username:password\' for accessing OpenNebula' }, :endpoint => { :type => :string, :desc => 'OpenNebula\'s XML RPC endpoint' }, :"api-call-timeout" => { :required => true, :type => :string, :desc => 'How long will NIFTY wait for image/template operations to finish in OpenNebula' } } end |
.options ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/nifty/backends/opennebula.rb', line 27 def { :secret => { :type => :string, :desc => 'Pair of username and password in form of \'username:password\' for accessing OpenNebula' }, :endpoint => { :type => :string, :desc => 'OpenNebula\'s XML RPC endpoint' }, :"expiration-interval" => { :required => true, :type => :string, :desc => 'How long should expired images be kept in OpenNebula befor removal, 0 means don\'t remove' }, :"api-call-timeout" => { :required => true, :type => :string, :desc => 'How long will NIFTY wait for image/template operations to finish in OpenNebula' }, :datastores => { :required => true, :type => :array, :aliases => '-d', :desc => 'Names of OpenNebula datastores images will be uploaded to' }, :"template-dir" => { :default => File.join(Nifty::GEM_DIR, 'config', 'templates'), :type => :string, :desc => 'If set, templates within this directory are used to construct images and templates in OpenNebula' }, :"description-naming" => { :type => :boolean, :desc => 'If true, uses identifier and version from appliance description as template/image name instead of generated uuids' }, :"disk-expiration" => { :type => :boolean, :desc => 'Will expire old disks before the new one is registered' }, :permissions => { :required => true, :type => :string, :desc => 'UNIX-like image and template permissions in OpenNebula' }, :groups => { :type => :array, :desc => 'Names of groups appliances will be registred to in OpenNebula' } } end |
.pre(parameters) ⇒ Object
96 97 98 99 |
# File 'lib/nifty/backends/opennebula.rb', line 96 def pre(parameters) Nifty::Backends::Utils::Opennebula::Handler.api_call_timeout = ChronicDuration.parse(parameters[:'api-call-timeout'], keep_zero: true) expiration_check(parameters) end |