Created
October 10, 2012 16:08
-
-
Save arax/3866597 to your computer and use it in GitHub Desktop.
rOCCI-server VM instances from os_tpls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/occi/backend/opennebula/compute.rb b/lib/occi/backend/opennebula/compute.rb | |
index 70fdf01..e95a0d5 100644 | |
--- a/lib/occi/backend/opennebula/compute.rb | |
+++ b/lib/occi/backend/opennebula/compute.rb | |
@@ -241,6 +241,9 @@ module OCCI | |
# --------------------------------------------------------------------------------------------------------------------- | |
def compute_deploy(client, compute) | |
+ | |
+ OCCI::Log.debug "Deploying #{compute.inspect}" | |
+ | |
os_tpl = compute.mixins.select { |mixin| | |
OCCI::Log.debug("Compute deploy found mixin: #{mixin}") | |
if mixin.kind_of? String | |
@@ -268,13 +271,9 @@ module OCCI | |
end | |
if template | |
- vcpu_old = template['TEMPLATE/VCPU'] | |
vcpu = compute.attributes.occi.compute.cores if compute.attributes.occi!.compute!.cores | |
- memory_old = template['TEMPLATE/MEMORY'] | |
memory = (compute.attributes.occi.compute.memory.to_f * 1000).to_i if compute.attributes.occi!.compute!.memory | |
- architecture_old = template['TEMPLATE/ARCHITECTURE'] | |
architecture = compute.attributes.occi.compute.architecture if compute.attributes.occi!.compute!.architecture | |
- cpu_old = template['TEMPLATE/CPU'] | |
cpu = compute.attributes.occi.compute.speed if compute.attributes.occi!.compute!.speed | |
unless vcpu.nil? | |
@@ -303,28 +302,31 @@ module OCCI | |
template.add_element('TEMPLATE', "OCCI_MIXIN" => mixin) | |
end | |
- template.update(template.template_str) | |
- OCCI::Log.debug "Template #{template.inspect}" | |
- | |
vm_name = "" | |
vm_name = compute.attributes.occi.core.title unless compute.attributes.occi.core.title.nil? or compute.attributes.occi.core.title.empty? | |
- backend_id = template.instantiate vm_name | |
- | |
- check_rc(backend_id) | |
- | |
- OCCI::Log.debug("Backend ID #{backend_id}") if backend_id | |
- template.delete_element('TEMPLATE/OCCI_ID') | |
- template.delete_element('TEMPLATE/OCCI_MIXIN') | |
- template.delete_element('TEMPLATE/VCPU') | |
- template.add_element('TEMPLATE', { "VCPU" => vcpu_old }) | |
- template.delete_element('TEMPLATE/MEMORY') | |
- template.add_element('TEMPLATE', { "MEMORY" => memory_old }) | |
- template.delete_element('TEMPLATE/ARCHITECTURE') | |
- template.add_element('TEMPLATE', { "ARCHITECTURE" => architecture_old }) | |
- template.delete_element('TEMPLATE/CPU') | |
- template.add_element('TEMPLATE', { "CPU" => cpu_old }) | |
- template.update(template.template_str) | |
- backend_object = VirtualMachine.new(VirtualMachine.build_xml(backend_id), client) | |
+ | |
+ # remove template-specific values (not sure if this is necessary) | |
+ template.delete_element('ID') | |
+ template.delete_element('UID') | |
+ template.delete_element('GID') | |
+ template.delete_element('UNAME') | |
+ template.delete_element('GNAME') | |
+ template.delete_element('REGTIME') | |
+ template.delete_element('PERMISSIONS') | |
+ template.delete_element('TEMPLATE/TEMPLATE_ID') | |
+ | |
+ # set template name | |
+ template.delete_element('TEMPLATE/NAME') | |
+ template.add_element('TEMPLATE', 'NAME' => vm_name || "rOCCIVMGeneric") | |
+ | |
+ OCCI::Log.debug "Template #{template.template_str}" | |
+ | |
+ backend_object = VirtualMachine.new(VirtualMachine.build_xml, client) | |
+ | |
+ rc = backend_object.allocate(template.template_str) | |
+ check_rc(rc) | |
+ | |
+ OCCI::Log.debug("Return code from OpenNebula #{rc}") if rc != nil | |
else | |
backend_object = VirtualMachine.new(VirtualMachine.build_xml, client) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment