Class: Roca::Template

Inherits:
Object
  • Object
show all
Extended by:
ConnectorHelper::ClassMethods
Includes:
ConnectorHelper
Defined in:
lib/roca/template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConnectorHelper::ClassMethods

connector, connector=

Methods included from ConnectorHelper

#connector, #connector=

Constructor Details

#initialize(attributes = {}) ⇒ Template

Returns a new instance of Template.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/roca/template.rb', line 33

def initialize(attributes = {})
  @template_id  = attributes[:template_id]
  @user_id      = attributes[:user_id]
  @group_id     = attributes[:group_id]
  @user_name    = attributes[:user_name]
  @group_name   = attributes[:group_name]
  @name         = attributes[:name]
  @public       = attributes[:public]
  @regtime      = attributes[:regtime]
  @xml_template = attributes[:xml_template]
end

Instance Attribute Details

#group_idObject (readonly)

Returns the value of attribute group_id.



6
7
8
# File 'lib/roca/template.rb', line 6

def group_id
  @group_id
end

#group_nameObject (readonly)

Returns the value of attribute group_name.



6
7
8
# File 'lib/roca/template.rb', line 6

def group_name
  @group_name
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/roca/template.rb', line 6

def name
  @name
end

#template_idObject (readonly)

Returns the value of attribute template_id.



6
7
8
# File 'lib/roca/template.rb', line 6

def template_id
  @template_id
end

#user_idObject (readonly)

Returns the value of attribute user_id.



6
7
8
# File 'lib/roca/template.rb', line 6

def user_id
  @user_id
end

#user_nameObject (readonly)

Returns the value of attribute user_name.



6
7
8
# File 'lib/roca/template.rb', line 6

def user_name
  @user_name
end

#xml_templateObject (readonly)

Returns the value of attribute xml_template.



6
7
8
# File 'lib/roca/template.rb', line 6

def xml_template
  @xml_template
end

Class Method Details

.build_from_hash(attributes = {}) ⇒ Object



13
14
15
# File 'lib/roca/template.rb', line 13

def self.build_from_hash(attributes = {})
  Template.new(attributes)
end

.build_from_xml(xml_description) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/roca/template.rb', line 17

def self.build_from_xml(xml_description)
  doc = Nokogiri::Slop(xml_description)

  Template.build_from_hash(
    template_id:  doc.VMTEMPLATE.ID.content.to_i,
    user_id:      doc.VMTEMPLATE.UID.content.to_i,
    group_id:     doc.VMTEMPLATE.GID.content.to_i,
    user_name:    doc.VMTEMPLATE.UNAME.content,
    group_name:   doc.VMTEMPLATE.GNAME.content,
    name:         doc.VMTEMPLATE.NAME.content,
    public:       !doc.VMTEMPLATE.PUBLIC.content.to_i.zero?,
    regtime:      doc.VMTEMPLATE.REGTIME.content.to_i,
    xml_template: doc.VMTEMPLATE.TEMPLATE.to_xml
  )
end

.find(template_id) ⇒ Object



8
9
10
11
# File 'lib/roca/template.rb', line 8

def self.find(template_id)
  success_flag, xml_object_description, error_code = connector.execute("one.template.info", template_id)
  success_flag ? Template.build_from_xml(xml_object_description) : false
end

Instance Method Details

#groupObject



59
60
61
# File 'lib/roca/template.rb', line 59

def group
  @group ||= Group.find(@group_id)
end

#instantiate(attributes = {}) ⇒ Object



45
46
47
48
49
# File 'lib/roca/template.rb', line 45

def instantiate(attributes = {})
  virtual_machine_name = attributes[:virtual_machine_name] || ""
  success_flag, virtual_machine_id, error_code = connector.execute("one.template.instantiate", template_id, virtual_machine_name)
  success_flag ? virtual_machine_name : false
end

#public?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/roca/template.rb', line 51

def public?
  @public
end

#registration_timeObject



55
56
57
# File 'lib/roca/template.rb', line 55

def registration_time
  @regtime_as_time_object ||= Time.at(@regtime)
end