Class: Megam::PredefCloud

Inherits:
ServerAPI show all
Defined in:
lib/megam/core/predefcloud.rb

Instance Attribute Summary

Attributes inherited from ServerAPI

#api_key, #email

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServerAPI

#megam_rest

Constructor Details

#initialize(email = nil, api_key = nil) ⇒ PredefCloud

Returns a new instance of PredefCloud.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/megam/core/predefcloud.rb', line 19

def initialize(email=nil, api_key=nil)
  @id = nil
  @name = nil
  @accounts_id = nil
  @spec = {}
  @access = {}
  #@ideal=nil
  #@performance = nil
  @created_at = nil
  @some_msg = {}
  super(email, api_key)
end

Class Method Details

.create(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



198
199
200
201
# File 'lib/megam/core/predefcloud.rb', line 198

def self.create(o,tmp_email=nil, tmp_api_key=nil)
  acct = from_hash(o,tmp_email, tmp_api_key)
  acct.create
end

.delete(p_name, tmp_email = nil, tmp_api_key = nil) ⇒ Object



223
224
225
226
# File 'lib/megam/core/predefcloud.rb', line 223

def self.delete(p_name,tmp_email=nil, tmp_api_key=nil)
pre = self.new(tmp_email,tmp_api_key)
pre.megam_rest.delete_predefcloud(p_name)
end

.from_hash(o, tmp_email = nil, tmp_api_key = nil) ⇒ Object



181
182
183
184
185
# File 'lib/megam/core/predefcloud.rb', line 181

def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
  predefcd = self.new(tmp_email, tmp_api_key)
  predefcd.from_hash(o)
  predefcd
end

.json_create(o) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/megam/core/predefcloud.rb', line 149

def self.json_create(o)
  predefcd = new
  predefcd.id(o["id"]) if o.has_key?("id")
  predefcd.name(o["name"]) if o.has_key?("name")
  #requests
  oq = o["spec"]
  predefcd.spec[:type_name] = oq["type_name"] if oq && oq.has_key?("type_name")
  predefcd.spec[:groups] = oq["groups"] if oq && oq.has_key?("groups")
  predefcd.spec[:image] = oq["image"] if oq && oq.has_key?("image")
  predefcd.spec[:flavor] = oq["flavor"] if oq && oq.has_key?("flavor")
  predefcd.spec[:tenant_id] = oq["tenant_id"] if oq && oq.has_key?("tenant_id")
  #predef
  op = o["access"]
  predefcd.access[:ssh_key] = op["ssh_key"] if op && op.has_key?("ssh_key")
  predefcd.access[:identity_file] = op["identity_file"] if op && op.has_key?("identity_file")
  predefcd.access[:ssh_user]= op["ssh_user"] if op && op.has_key?("ssh_user")
  predefcd.access[:vault_location]= op["vault_location"] if op && op.has_key?("vault_location")
  predefcd.access[:sshpub_location]= op["sshpub_location"] if op && op.has_key?("sshpub_location")
  predefcd.access[:zone]= op["zone"] if op && op.has_key?("zone")
  predefcd.access[:region]= op["region"] if op && op.has_key?("region")
  #access
 # predefcd.ideal(o["ideal"]) if o.has_key?("ideal")
 # predefcd.performance(o["performance"]) if o.has_key?("performance")
  predefcd.created_at(o["created_at"]) if o.has_key?("created_at")
  #success or error
  predefcd.some_msg[:code] = o["code"] if o.has_key?("code")
  predefcd.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
  predefcd.some_msg[:msg]= o["msg"] if o.has_key?("msg")
  predefcd.some_msg[:links] = o["links"] if o.has_key?("links")
  predefcd
end

.list(tmp_email = nil, tmp_api_key = nil) ⇒ Object

Load all predefs - returns a PredefsCollection don’t return self. check if the Megam::PredefCollection is returned.



211
212
213
214
# File 'lib/megam/core/predefcloud.rb', line 211

def self.list(tmp_email=nil, tmp_api_key=nil)
predef = self.new(tmp_email,tmp_api_key)
  predef.megam_rest.get_predefclouds
end

.show(p_name, tmp_email = nil, tmp_api_key = nil) ⇒ Object

Show a particular predef by name, Megam::Predef



218
219
220
221
# File 'lib/megam/core/predefcloud.rb', line 218

def self.show(p_name,tmp_email=nil, tmp_api_key=nil)
pre = self.new(tmp_email,tmp_api_key)
pre.megam_rest.get_predefcloud(p_name)
end

Instance Method Details

#access(arg = nil) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/megam/core/predefcloud.rb', line 69

def access(arg=nil)
  if arg != nil
    @access = arg
  else
  @access
  end
end

#accounts_id(arg = nil) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/megam/core/predefcloud.rb', line 53

def accounts_id(arg=nil)
  if arg != nil
    @accounts_id= arg
  else
  @accounts_id
  end
end

#createObject

Create the predef via the REST API



204
205
206
# File 'lib/megam/core/predefcloud.rb', line 204

def create
  megam_rest.post_predefcloud(to_hash)
end

#created_at(arg = nil) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/megam/core/predefcloud.rb', line 93

def created_at(arg=nil)
  if arg != nil
    @created_at = arg
  else
  @created_at
  end
end

#error?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/megam/core/predefcloud.rb', line 109

def error?
  crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#for_jsonObject



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/megam/core/predefcloud.rb', line 134

def for_json
  result = {
    "id" => id,
    "name" => name,
    "accounts_id" => accounts_id,
    "spec" => spec,
    "access" => access,
 #   "ideal" => ideal,
 #   "performance" => performance,
    "created_at" => created_at
  }
  result
end

#from_hash(o) ⇒ Object



187
188
189
190
191
192
193
194
195
196
# File 'lib/megam/core/predefcloud.rb', line 187

def from_hash(o)
  @id        = o[:id] if o.has_key?(:id)
  @name = o[:name] if o.has_key?(:name)
  @spec   = o[:spec] if o.has_key?(:spec)
  @access     = o[:access] if o.has_key?(:access)
#  @ideal   = o[:ideal] if o.has_key?(:ideal)
#  @performance   = o[:performance] if o.has_key?(:performance)
  @created_at   = o[:created_at] if o.has_key?(:created_at)
  self
end

#id(arg = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/megam/core/predefcloud.rb', line 37

def id(arg=nil)
  if arg != nil
    @id = arg
  else
  @id
  end
end

#ideal(arg = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/megam/core/predefcloud.rb', line 77

def ideal(arg=nil)
  if arg != nil
    @ideal= arg
  else
  @ideal
  end
end

#name(arg = nil) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/megam/core/predefcloud.rb', line 45

def name(arg=nil)
  if arg != nil
    @name = arg
  else
  @name
  end
end

#performance(arg = nil) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/megam/core/predefcloud.rb', line 85

def performance(arg=nil)
  if arg != nil
    @performance= arg
  else
  @performance
  end
end

#predef_cloudObject



32
33
34
# File 'lib/megam/core/predefcloud.rb', line 32

def predef_cloud
  self
end

#some_msg(arg = nil) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/megam/core/predefcloud.rb', line 101

def some_msg(arg=nil)
  if arg != nil
    @some_msg = arg
  else
  @some_msg
  end
end

#spec(arg = nil) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/megam/core/predefcloud.rb', line 61

def spec(arg=nil)
  if arg != nil
    @spec = arg
  else
  @spec
  end
end

#to_hashObject

Transform the ruby obj -> to a Hash



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/megam/core/predefcloud.rb', line 114

def to_hash
  index_hash = Hash.new
  index_hash["json_claz"] = self.class.name
  index_hash["id"] = id
  index_hash["name"] = name
  index_hash["accounts_id"] = accounts_id
  index_hash["spec"] = spec
  index_hash["access"] = access
 # index_hash["ideal"] = ideal
 # index_hash["performance"] = performance
  index_hash["created_at"] = created_at
  index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.



130
131
132
# File 'lib/megam/core/predefcloud.rb', line 130

def to_json(*a)
  for_json.to_json(*a)
end

#to_sObject



228
229
230
231
# File 'lib/megam/core/predefcloud.rb', line 228

def to_s
  Megam::Stuff.styled_hash(to_hash)
#"---> Megam::Account:[error=#{error?}]\n"+
end