Class: CloudhouseGuardian::Pluggable

Inherits:
BaseObject show all
Defined in:
lib/cloudhouse_guardian/Pluggable.rb

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#appliance_api_key, #appliance_url, #insecure, #sec_key

Instance Method Summary collapse

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) ⇒ Pluggable

Returns a new instance of Pluggable.



10
11
12
13
14
15
16
17
18
19
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 10

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.operating_system_family = nil
  self.operating_system_family_id = nil
  self.operating_system_id = nil
  self.script = nil
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 3

def description
  @description
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 5

def name
  @name
end

#operating_system_familyObject

Returns the value of attribute operating_system_family.



6
7
8
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 6

def operating_system_family
  @operating_system_family
end

#operating_system_family_idObject

Returns the value of attribute operating_system_family_id.



7
8
9
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 7

def operating_system_family_id
  @operating_system_family_id
end

#operating_system_idObject

Returns the value of attribute operating_system_id.



8
9
10
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 8

def operating_system_id
  @operating_system_id
end

#scriptObject

Returns the value of attribute script.



9
10
11
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 9

def script
  @script
end

Instance Method Details

#createObject



61
62
63
64
65
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 61

def create
  h = to_hash
  out = http_post("/api/v2/pluggables.json", h)
  from_hash(out)
end

#deleteObject



75
76
77
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 75

def delete
  http_delete("/api/v2/pluggables/#{self.operating_system_id}.json")
end

#from_hash(h) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 21

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.operating_system_family = h['operating_system_family'] if h.include?('operating_system_family')
  self.operating_system_family_id = h['operating_system_family_id'] if h.include?('operating_system_family_id')
  self.operating_system_id = h['operating_system_id'] if h.include?('operating_system_id')
  self.script = h['script'] if h.include?('script')
end

#loadObject



46
47
48
49
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 46

def load
  obj = http_get("/api/v2/pluggables/#{self.operating_system_id}.json")
  from_hash(obj)
end

#saveObject



52
53
54
55
56
57
58
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 52

def save
  if self.id.to_i == 0
    return create
  else
    return update
  end
end

#to_hashObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 30

def to_hash
  h = {}
  h['description'] = self.description
  h['id'] = self.id
  h['name'] = self.name
  h['operating_system_family'] = self.operating_system_family
  h['operating_system_family_id'] = self.operating_system_family_id
  h['operating_system_id'] = self.operating_system_id
  h['script'] = self.script
  return h
end

#to_json(options = nil) ⇒ Object



41
42
43
44
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 41

def to_json(options = nil)
  h = to_hash
  return h.to_json(options)
end

#updateObject



68
69
70
71
72
73
# File 'lib/cloudhouse_guardian/Pluggable.rb', line 68

def update
  h = to_hash
  h.delete("operating_system_family_id")
  h.delete("operating_system_id")
  http_put("/api/v2/pluggables/#{self.operating_system_id}.json", h)
end