Class: OpenNebula::DocumentJSON
- Inherits:
-
Document
- Object
- XMLElement
- PoolElement
- Document
- OpenNebula::DocumentJSON
- Defined in:
- lib/opennebula/document_json.rb
Constant Summary collapse
- TEMPLATE_TAG =
"BODY"
Constants inherited from Document
OpenNebula::Document::DOCUMENT_METHODS
Instance Method Summary collapse
-
#allocate(template_json, name = nil) ⇒ nil, OpenNebula::Error
Allocate a new Document containing the json inside the TEMPLATE.
-
#info ⇒ nil, OpenNebula::Error
(also: #info!)
Retrieves the information of the Service and all its Nodes.
-
#load_body ⇒ Object
Fill the @body hash with the values of the template.
-
#to_json(pretty_generate = true) ⇒ String
Generates a json representing the object.
-
#update(template_json = nil, append = false) ⇒ nil, OpenNebula::Error
Updates the current state of this Service in the OpenNebula DB.
-
#update_raw(template_raw, append = false) ⇒ nil, OpenNebula::Error
Replaces the raw template contents.
Methods inherited from Document
build_xml, #chmod, #chmod_octet, #chown, #clone, #delete, #document_type, #gid, #initialize, #lock, #owner_id, #public?, #rename, #unlock
Methods inherited from PoolElement
#id, #name, new_with_id, #replace, #to_str
Methods inherited from XMLElement
#[], #add_element, #attr, build_xml, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize, #initialize_xml, #name, #retrieve_elements, #retrieve_xmlelements, #set_content, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?
Constructor Details
This class inherits a constructor from OpenNebula::Document
Instance Method Details
#allocate(template_json, name = nil) ⇒ nil, OpenNebula::Error
Allocate a new Document containing the json inside the TEMPLATE
33 34 35 36 37 |
# File 'lib/opennebula/document_json.rb', line 33 def allocate(template_json, name=nil) text = build_template_xml(template_json, name) super(text) end |
#info ⇒ nil, OpenNebula::Error Also known as: info!
Retrieves the information of the Service and all its Nodes.
44 45 46 47 48 49 50 51 |
# File 'lib/opennebula/document_json.rb', line 44 def info rc = super if OpenNebula.is_error?(rc) return rc end load_body end |
#load_body ⇒ Object
Fill the @body hash with the values of the template
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/opennebula/document_json.rb', line 108 def load_body body_str = self["TEMPLATE/#{TEMPLATE_TAG}"] if body_str begin @body = JSON.parse(body_str) rescue JSON::JSONError return OpenNebula::Error.new($!) end end return nil end |
#to_json(pretty_generate = true) ⇒ String
Generates a json representing the object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/opennebula/document_json.rb', line 90 def to_json(pretty_generate=true) hash = self.to_hash body = hash['DOCUMENT']['TEMPLATE']["#{TEMPLATE_TAG}"] if body body_hash = JSON.parse(body) hash['DOCUMENT']['TEMPLATE']["#{TEMPLATE_TAG}"] = body_hash end if pretty_generate JSON.pretty_generate hash else hash.to_json end end |
#update(template_json = nil, append = false) ⇒ nil, OpenNebula::Error
Updates the current state of this Service in the OpenNebula DB
65 66 67 68 69 70 71 |
# File 'lib/opennebula/document_json.rb', line 65 def update(template_json=nil, append=false) template_json ||= @body.to_json text = build_template_xml(template_json) super(text, append) end |
#update_raw(template_raw, append = false) ⇒ nil, OpenNebula::Error
Replaces the raw template contents
81 82 83 |
# File 'lib/opennebula/document_json.rb', line 81 def update_raw(template_raw, append=false) super(template_raw, append) end |