Module: Backends::Opennebula::Helpers::ComputeCreateHelper

Included in:
Compute
Defined in:
lib/backends/opennebula/helpers/compute_create_helper.rb

Constant Summary collapse

COMPUTE_SSH_REGEXP =
/^(command=.+\s)?((?:ssh\-|ecds)[\w-]+\s.+)$/
COMPUTE_BASE64_REGEXP =
/^[A-Za-z0-9+\/]+={0,2}$/
COMPUTE_USER_DATA_SIZE_LIMIT =
16384
COMPUTE_DN_BASED_AUTHS =
%w(x509 voms).freeze

Instance Method Summary collapse

Instance Method Details


71
72
73
74
75
# File 'lib/backends/opennebula/helpers/compute_create_helper.rb', line 71

def create_with_links(compute)
  # TODO: drop this branch in the second stable release
  fail Backends::Errors::MethodNotImplementedError,
       "This functionality has been deprecated! Use os_tpl and resource_tpl mixins!"
end

#create_with_os_tpl(compute) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
# File 'lib/backends/opennebula/helpers/compute_create_helper.rb', line 10

def create_with_os_tpl(compute)
  @logger.debug "[Backends] [Opennebula] Deploying #{compute.inspect}"

  # include some basic mixins
  # WARNING: adding mix-ins will re-set their attributes
  attr_backup = ::Occi::Core::Attributes.new(compute.attributes)
  compute.mixins << 'http://schemas.opennebula.org/occi/infrastructure#compute'
  compute.attributes = attr_backup

  os_tpl_mixins = compute.mixins.get_related_to(::Occi::Infrastructure::OsTpl.mixin.type_identifier)
  os_tpl = os_tpl_mixins.first

  @logger.debug "[Backends] [Opennebula] Deploying with OS template: #{os_tpl.term}"
  os_tpl = term_to_id(os_tpl.term)

  # get template
  template_alloc = ::OpenNebula::Template.build_xml(os_tpl)
  template = ::OpenNebula::Template.new(template_alloc, @client)
  rc = template.info
  check_retval(rc, Backends::Errors::ResourceRetrievalError)

  # update template
  create_set_attrs(compute, template)
  create_check_context(compute)
  create_add_context(compute, template)
  create_add_description(compute, template)
  create_add_custom_template_vars(compute, template)

  # remove template-specific values
  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')

  # convert template structure to a pure String
  template = template.template_str

  # add inline links
  template = create_add_inline_links(compute, template)

  @logger.debug "[Backends] [Opennebula] Template #{template.inspect}"
  vm_alloc = ::OpenNebula::VirtualMachine.build_xml
  backend_object = ::OpenNebula::VirtualMachine.new(vm_alloc, @client)

  rc = backend_object.allocate(template)
  check_retval(rc, Backends::Errors::ResourceCreationError)

  rc = backend_object.info
  check_retval(rc, Backends::Errors::ResourceRetrievalError)

  compute_id = backend_object['ID']
  rc = backend_object.update("OCCI_ID=\"#{compute_id}\"", true)
  check_retval(rc, Backends::Errors::ResourceActionError)

  compute_id
end