Class: Megam::PredefCloud

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePredefCloud

Each notify entry is a resource/action pair, modeled as an Struct with a #resource and #action member



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

def initialize
  @id = nil
  @name = nil
  @accounts_id = nil
  @spec = {}
  @access = {}
  #@ideal=nil
  #@performance = nil
  @created_at = nil
  @some_msg = {}
end

Class Method Details

.create(o) ⇒ Object



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

def self.create(o)
  acct = from_hash(o)
  acct.create
end

.from_hash(o) ⇒ Object



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

def self.from_hash(o)
  predefcd = self.new()
  predefcd.from_hash(o)
  predefcd
end

.json_create(o) ⇒ Object



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
# File 'lib/megam/core/predefcloud.rb', line 153

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")
  #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")
  #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

.listObject

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



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

def self.list
  predef = self.new()
  predef.megam_rest.get_predefclouds
end

.show(p_name) ⇒ Object

Show a particular predef by name, Megam::Predef



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

def self.show(p_name)
  pre = self.new()
  pre.megam_rest.get_predefcloud(p_name)
  self
end

Instance Method Details

#access(arg = nil) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/megam/core/predefcloud.rb', line 73

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

#accounts_id(arg = nil) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/megam/core/predefcloud.rb', line 57

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

#createObject

Create the predef via the REST API



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

def create
  megam_rest.post_predefcloud(to_hash)
end

#created_at(arg = nil) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/megam/core/predefcloud.rb', line 97

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

#error?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/megam/core/predefcloud.rb', line 113

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

#for_jsonObject



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/megam/core/predefcloud.rb', line 138

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



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

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



41
42
43
44
45
46
47
# File 'lib/megam/core/predefcloud.rb', line 41

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

#ideal(arg = nil) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/megam/core/predefcloud.rb', line 81

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

#megam_restObject



36
37
38
39
# File 'lib/megam/core/predefcloud.rb', line 36

def megam_rest
  options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
  Megam::API.new(options)
end

#name(arg = nil) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/megam/core/predefcloud.rb', line 49

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

#performance(arg = nil) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/megam/core/predefcloud.rb', line 89

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



105
106
107
108
109
110
111
# File 'lib/megam/core/predefcloud.rb', line 105

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

#spec(arg = nil) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/megam/core/predefcloud.rb', line 65

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

#to_hashObject

Transform the ruby obj -> to a Hash



118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/megam/core/predefcloud.rb', line 118

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.



134
135
136
# File 'lib/megam/core/predefcloud.rb', line 134

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

#to_sObject



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

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