Class: Megam::Snapshots

Inherits:
RestAdapter show all
Defined in:
lib/megam/core/snapshots.rb

Instance Attribute Summary

Attributes inherited from RestAdapter

#api_key, #email, #headers, #host, #master_key, #password_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestAdapter

#megam_rest

Constructor Details

#initialize(o) ⇒ Snapshots

Returns a new instance of Snapshots.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/megam/core/snapshots.rb', line 3

def initialize(o)
    @snap_id = nil
    @account_id = nil
    @asm_id = nil
    @org_id = nil
    @tosca_type = nil
    @inputs = []
    @outputs = []
    @name= nil
    @status=nil
    @image_id=nil
    @created_at = nil
    @some_msg = {}
    super(o)
end

Class Method Details

.create(params) ⇒ Object



207
208
209
210
# File 'lib/megam/core/snapshots.rb', line 207

def self.create(params)
    sps = from_hash(params)
    sps.create
end

.from_hash(o) ⇒ Object



186
187
188
189
190
# File 'lib/megam/core/snapshots.rb', line 186

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

.json_create(o) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/megam/core/snapshots.rb', line 166

def self.json_create(o)
    sps = new({})
    sps.snap_id(o["snap_id"]) if o.has_key?("snap_id")
    sps.(o["account_id"]) if o.has_key?("account_id")
    sps.asm_id(o["asm_id"]) if o.has_key?("asm_id")
    sps.org_id(o["org_id"]) if o.has_key?("org_id") #this will be an array? can hash store array?
    sps.tosca_type(o['tosca_type']) if o.key?('tosca_type')
    sps.inputs(o['inputs']) if o.key?('inputs')
    sps.outputs(o['outputs']) if o.key?('outputs')
    sps.name(o["name"]) if o.has_key?("name")
    sps.status(o["status"]) if o.has_key?("status")
    sps.image_id(o["status"]) if o.has_key?("image_id")
    sps.created_at(o["created_at"]) if o.has_key?("created_at")
    sps.some_msg[:code] = o["code"] if o.has_key?("code")
    sps.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
    sps.some_msg[:msg]= o["msg"] if o.has_key?("msg")
    sps.some_msg[:links] = o["links"] if o.has_key?("links")
    sps
end

.list(params) ⇒ Object



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

def self.list(params)
    sps = self.new(params)
    sps.megam_rest.list_snapshots
end

.show(o) ⇒ Object

Load a account by email_p



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

def self.show(o)
    sps = self.new(o)
    sps.megam_rest.get_snapshots(o[:id])
end

Instance Method Details

#account_id(arg = nil) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/megam/core/snapshots.rb', line 30

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

#asm_id(arg = nil) ⇒ Object



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

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

#createObject

Create the node via the REST API



213
214
215
# File 'lib/megam/core/snapshots.rb', line 213

def create
    megam_rest.post_snapshots(to_hash)
end

#created_at(arg = nil) ⇒ Object



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

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

#error?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/megam/core/snapshots.rb', line 110

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

#for_jsonObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/megam/core/snapshots.rb', line 149

def for_json
    result = {
      "snap_id" => snap_id,
        "account_id" => ,
        "asm_id" => asm_id,
        "org_id" => org_id,
        "tosca_type" => tosca_type,
        "inputs" => inputs,
        "outputs" => outputs,
        "name" => name,
        "status" => status,
        "image_id" => image_id,
        "created_at" => created_at
    }
    result
end

#from_hash(o) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/megam/core/snapshots.rb', line 192

def from_hash(o)
    @snap_id       = o[:snap_id] if o.has_key?(:snap_id)
    @account_id       = o[:account_id] if o.has_key?(:account_id)
    @asm_id        = o[:asm_id] if o.has_key?(:asm_id)
    @org_id        = o[:org_id] if o.has_key?(:org_id)
    @tosca_type        = o[:tosca_type] if o.key?(:tosca_type)
    @inputs            = o[:inputs] if o.key?(:inputs)
    @outputs           = o[:outputs] if o.key?(:outputs)
    @name            = o[:name] if o.has_key?(:name)
    @status            = o[:status] if o.has_key?(:status)
    @image_id          = o[:image_id] if o.has_key?(:image_id)
    @created_at        = o[:created_at] if o.has_key?(:created_at)
    self
end

#image_id(arg = nil) ⇒ Object



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

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

#inputs(arg = []) ⇒ Object



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

def inputs(arg = [])
    if arg != []
        @inputs = arg
    else
        @inputs
    end
end

#name(arg = nil) ⇒ Object



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

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

#org_id(arg = nil) ⇒ Object



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

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

#outputs(arg = []) ⇒ Object



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

def outputs(arg = [])
    if arg != []
        @outputs = arg
    else
        @outputs
    end
end

#snap_id(arg = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/megam/core/snapshots.rb', line 22

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

#snapshotsObject



19
20
21
# File 'lib/megam/core/snapshots.rb', line 19

def snapshots
    self
end

#some_msg(arg = nil) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/megam/core/snapshots.rb', line 115

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

#status(arg = nil) ⇒ Object



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

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

#to_hashObject

Transform the ruby obj -> to a Hash



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/megam/core/snapshots.rb', line 125

def to_hash
    index_hash = Hash.new
    index_hash["json_claz"] = self.class.name
    index_hash["snap_id"] = snap_id
    index_hash["account_id"] = 
    index_hash["asm_id"] = asm_id
    index_hash["org_id"] = org_id
    index_hash["tosca_type"] = tosca_type
    index_hash["inputs"] = inputs
    index_hash["outputs"] = outputs
    index_hash["name"] = name
    index_hash["status"] = status
    index_hash["image_id"] = image_id
    index_hash["created_at"] = created_at
    index_hash["some_msg"] = some_msg
    index_hash
end

#to_json(*a) ⇒ Object

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



145
146
147
# File 'lib/megam/core/snapshots.rb', line 145

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

#to_sObject



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

def to_s
    Megam::Stuff.styled_hash(to_hash)
end

#tosca_type(arg = nil) ⇒ Object



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

def tosca_type(arg = nil)
    if !arg.nil?
        @tosca_type = arg
    else
        @tosca_type
    end
end