Class: Megam::PredefCloud
- Inherits:
-
Object
- Object
- Megam::PredefCloud
- Defined in:
- lib/megam/core/predefcloud.rb
Class Method Summary collapse
- .create(o) ⇒ Object
- .from_hash(o) ⇒ Object
- .json_create(o) ⇒ Object
-
.list ⇒ Object
Load all predefs - returns a PredefsCollection don’t return self.
-
.show(p_name) ⇒ Object
Show a particular predef by name, Megam::Predef.
Instance Method Summary collapse
- #access(arg = nil) ⇒ Object
- #accounts_id(arg = nil) ⇒ Object
-
#create ⇒ Object
Create the predef via the REST API.
- #created_at(arg = nil) ⇒ Object
- #error? ⇒ Boolean
- #for_json ⇒ Object
- #from_hash(o) ⇒ Object
- #id(arg = nil) ⇒ Object
- #ideal(arg = nil) ⇒ Object
-
#initialize ⇒ PredefCloud
constructor
Each notify entry is a resource/action pair, modeled as an Struct with a #resource and #action member.
- #megam_rest ⇒ Object
- #name(arg = nil) ⇒ Object
- #performance(arg = nil) ⇒ Object
- #predef_cloud ⇒ Object
- #some_msg(arg = nil) ⇒ Object
- #spec(arg = nil) ⇒ Object
-
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash.
-
#to_json(*a) ⇒ Object
Serialize this object as a hash: called from JsonCompat.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ PredefCloud
Each notify entry is a resource/action pair, modeled as an Struct with a #resource and #action member
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/megam/core/predefcloud.rb', line 21 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
203 204 205 206 |
# File 'lib/megam/core/predefcloud.rb', line 203 def self.create(o) acct = from_hash(o) acct.create end |
.from_hash(o) ⇒ Object
186 187 188 189 190 |
# File 'lib/megam/core/predefcloud.rb', line 186 def self.from_hash(o) predefcd = self.new() predefcd.from_hash(o) predefcd end |
.json_create(o) ⇒ Object
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 180 181 182 183 184 |
# File 'lib/megam/core/predefcloud.rb', line 154 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 ⇒ Object
Load all predefs - returns a PredefsCollection don’t return self. check if the Megam::PredefCollection is returned.
216 217 218 219 |
# File 'lib/megam/core/predefcloud.rb', line 216 def self.list predef = self.new() predef.megam_rest.get_predefclouds end |
.show(p_name) ⇒ Object
Show a particular predef by name, Megam::Predef
223 224 225 226 |
# File 'lib/megam/core/predefcloud.rb', line 223 def self.show(p_name) pre = self.new() pre.megam_rest.get_predefcloud(p_name) end |
Instance Method Details
#access(arg = nil) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/megam/core/predefcloud.rb', line 74 def access(arg=nil) if arg != nil @access = arg else @access end end |
#accounts_id(arg = nil) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/megam/core/predefcloud.rb', line 58 def accounts_id(arg=nil) if arg != nil @accounts_id= arg else @accounts_id end end |
#create ⇒ Object
Create the predef via the REST API
209 210 211 |
# File 'lib/megam/core/predefcloud.rb', line 209 def create megam_rest.post_predefcloud(to_hash) end |
#created_at(arg = nil) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/megam/core/predefcloud.rb', line 98 def created_at(arg=nil) if arg != nil @created_at = arg else @created_at end end |
#error? ⇒ Boolean
114 115 116 |
# File 'lib/megam/core/predefcloud.rb', line 114 def error? crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error") end |
#for_json ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/megam/core/predefcloud.rb', line 139 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
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/megam/core/predefcloud.rb', line 192 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
42 43 44 45 46 47 48 |
# File 'lib/megam/core/predefcloud.rb', line 42 def id(arg=nil) if arg != nil @id = arg else @id end end |
#ideal(arg = nil) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/megam/core/predefcloud.rb', line 82 def ideal(arg=nil) if arg != nil @ideal= arg else @ideal end end |
#megam_rest ⇒ Object
37 38 39 40 |
# File 'lib/megam/core/predefcloud.rb', line 37 def megam_rest = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]} Megam::API.new() end |
#name(arg = nil) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/megam/core/predefcloud.rb', line 50 def name(arg=nil) if arg != nil @name = arg else @name end end |
#performance(arg = nil) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/megam/core/predefcloud.rb', line 90 def performance(arg=nil) if arg != nil @performance= arg else @performance end end |
#predef_cloud ⇒ Object
33 34 35 |
# File 'lib/megam/core/predefcloud.rb', line 33 def predef_cloud self end |
#some_msg(arg = nil) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/megam/core/predefcloud.rb', line 106 def some_msg(arg=nil) if arg != nil @some_msg = arg else @some_msg end end |
#spec(arg = nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/megam/core/predefcloud.rb', line 66 def spec(arg=nil) if arg != nil @spec = arg else @spec end end |
#to_hash ⇒ Object
Transform the ruby obj -> to a Hash
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/megam/core/predefcloud.rb', line 119 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.
135 136 137 |
# File 'lib/megam/core/predefcloud.rb', line 135 def to_json(*a) for_json.to_json(*a) end |
#to_s ⇒ Object
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 |