Class: CloudhouseGuardian::Environment
- Inherits:
-
BaseObject
- Object
- BaseObject
- CloudhouseGuardian::Environment
- Defined in:
- lib/cloudhouse_guardian/Environment.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#created_by ⇒ Object
Returns the value of attribute created_by.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#node_rules ⇒ Object
Returns the value of attribute node_rules.
-
#short_description ⇒ Object
Returns the value of attribute short_description.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#updated_by ⇒ Object
Returns the value of attribute updated_by.
-
#weight ⇒ Object
Returns the value of attribute weight.
Attributes inherited from BaseObject
#appliance_api_key, #appliance_url, #insecure, #sec_key
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #from_hash(h) ⇒ Object
-
#initialize(appliance_url, appliance_api_key, sec_key, insecure = false) ⇒ Environment
constructor
A new instance of Environment.
- #load ⇒ Object
- #nodes ⇒ Object
- #save ⇒ Object
- #to_hash ⇒ Object
- #to_json(options = nil) ⇒ Object
- #update ⇒ Object
Methods inherited from BaseObject
#http_delete, #http_get, #http_post, #http_put, #make_headers
Constructor Details
#initialize(appliance_url, appliance_api_key, sec_key, insecure = false) ⇒ Environment
Returns a new instance of Environment.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 13 def initialize(appliance_url, appliance_api_key, sec_key, insecure = false) super(appliance_url, appliance_api_key, sec_key, insecure) self.description = nil self.id = nil self.name = nil self.node_rules = nil self.short_description = nil self.updated_by = nil self.created_by = nil self.updated_at = nil self.created_at = nil self.weight = nil end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
11 12 13 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 11 def created_at @created_at end |
#created_by ⇒ Object
Returns the value of attribute created_by.
9 10 11 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 9 def created_by @created_by end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 3 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 4 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 5 def name @name end |
#node_rules ⇒ Object
Returns the value of attribute node_rules.
6 7 8 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 6 def node_rules @node_rules end |
#short_description ⇒ Object
Returns the value of attribute short_description.
7 8 9 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 7 def short_description @short_description end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
10 11 12 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 10 def updated_at @updated_at end |
#updated_by ⇒ Object
Returns the value of attribute updated_by.
8 9 10 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 8 def updated_by @updated_by end |
#weight ⇒ Object
Returns the value of attribute weight.
12 13 14 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 12 def weight @weight end |
Instance Method Details
#create ⇒ Object
73 74 75 76 77 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 73 def create h = to_hash out = http_post("/api/v2/environments.json", h) from_hash(out) end |
#delete ⇒ Object
92 93 94 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 92 def delete http_delete("/api/v2/environments/#{self.id}.json") end |
#from_hash(h) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 27 def from_hash(h) self.description = h['description'] if h.include?('description') self.id = h['id'] if h.include?('id') self.name = h['name'] if h.include?('name') self.node_rules = h['node_rules'] if h.include?('node_rules') self.short_description = h['short_description'] if h.include?('short_description') self.updated_by = h['updated_by'] if h.include?('updated_by') self.created_by = h['created_by'] if h.include?('created_by') self.updated_at = h['updated_at'] if h.include?('updated_at') self.created_at = h['created_at'] if h.include?('created_at') self.weight = h['weight'] if h.include?('weight') end |
#load ⇒ Object
58 59 60 61 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 58 def load obj = http_get("/api/v2/environments/#{self.id}.json") from_hash(obj) end |
#nodes ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 97 def nodes obj = http_get("/api/v2/environments/#{self.id}/nodes.json") the_list = NodeList.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure) obj.each do |x| elem = Node.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure) elem.id = x["id"] if x.include?("id") elem.name = x["name"] if x.include?("name") the_list << elem end return the_list end |
#save ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 64 def save if self.id.to_i == 0 return create else return update end end |
#to_hash ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 39 def to_hash h = {} h['description'] = self.description h['id'] = self.id h['name'] = self.name h['node_rules'] = self.node_rules h['short_description'] = self.short_description h['updated_by'] = self.updated_by h['created_by'] = self.created_by h['updated_at'] = self.updated_at h['created_at'] = self.created_at h['weight'] = self.weight return h end |
#to_json(options = nil) ⇒ Object
53 54 55 56 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 53 def to_json( = nil) h = to_hash return h.to_json() end |
#update ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cloudhouse_guardian/Environment.rb', line 80 def update h = to_hash h.delete("id") h.delete("organisation_id") h.delete("updated_by") h.delete("created_by") h.delete("updated_at") h.delete("created_at") h.delete("weight") http_put("/api/v2/environments/#{self.id}.json", h) end |