Class: Roca::Template
- Inherits:
-
Object
- Object
- Roca::Template
- Extended by:
- ConnectorHelper::ClassMethods
- Includes:
- ConnectorHelper
- Defined in:
- lib/roca/template.rb
Instance Attribute Summary collapse
-
#group_id ⇒ Object
readonly
Returns the value of attribute group_id.
-
#group_name ⇒ Object
readonly
Returns the value of attribute group_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#template_id ⇒ Object
readonly
Returns the value of attribute template_id.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#user_name ⇒ Object
readonly
Returns the value of attribute user_name.
-
#xml_template ⇒ Object
readonly
Returns the value of attribute xml_template.
Class Method Summary collapse
- .build_from_hash(attributes = {}) ⇒ Object
- .build_from_xml(xml_description) ⇒ Object
- .find(template_id) ⇒ Object
Instance Method Summary collapse
- #group ⇒ Object
-
#initialize(attributes = {}) ⇒ Template
constructor
A new instance of Template.
- #instantiate(attributes = {}) ⇒ Object
- #public? ⇒ Boolean
- #registration_time ⇒ Object
Methods included from ConnectorHelper::ClassMethods
Methods included from ConnectorHelper
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_id ⇒ Object (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_name ⇒ Object (readonly)
Returns the value of attribute group_name.
6 7 8 |
# File 'lib/roca/template.rb', line 6 def group_name @group_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/roca/template.rb', line 6 def name @name end |
#template_id ⇒ Object (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_id ⇒ Object (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_name ⇒ Object (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_template ⇒ Object (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
#group ⇒ Object
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
51 52 53 |
# File 'lib/roca/template.rb', line 51 def public? @public end |
#registration_time ⇒ Object
55 56 57 |
# File 'lib/roca/template.rb', line 55 def registration_time @regtime_as_time_object ||= Time.at(@regtime) end |