megam_api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.project +17 -0
- data/.travis.yml +11 -0
- data/Gemfile +5 -0
- data/README.md +83 -0
- data/Rakefile +10 -0
- data/lib/certs/cacert.pem +3554 -0
- data/lib/megam/api.rb +244 -0
- data/lib/megam/api/accounts.rb +29 -0
- data/lib/megam/api/appdefns.rb +26 -0
- data/lib/megam/api/appreqs.rb +27 -0
- data/lib/megam/api/boltdefns.rb +27 -0
- data/lib/megam/api/boltreqs.rb +27 -0
- data/lib/megam/api/cloud_tools.rb +35 -0
- data/lib/megam/api/errors.rb +27 -0
- data/lib/megam/api/login.rb +14 -0
- data/lib/megam/api/logs.rb +18 -0
- data/lib/megam/api/nodes.rb +50 -0
- data/lib/megam/api/predef_clouds.rb +35 -0
- data/lib/megam/api/predefs.rb +35 -0
- data/lib/megam/api/requests.rb +37 -0
- data/lib/megam/api/version.rb +5 -0
- data/lib/megam/core/account.rb +170 -0
- data/lib/megam/core/appdefns.rb +192 -0
- data/lib/megam/core/appdefns_collection.rb +148 -0
- data/lib/megam/core/appreqs.rb +224 -0
- data/lib/megam/core/appreqs_collection.rb +148 -0
- data/lib/megam/core/auth.rb +91 -0
- data/lib/megam/core/boltdefns.rb +198 -0
- data/lib/megam/core/boltdefns_collection.rb +148 -0
- data/lib/megam/core/boltreqs.rb +224 -0
- data/lib/megam/core/boltreqs_collection.rb +148 -0
- data/lib/megam/core/cloudinstruction.rb +110 -0
- data/lib/megam/core/cloudinstruction_collection.rb +145 -0
- data/lib/megam/core/cloudinstruction_group.rb +99 -0
- data/lib/megam/core/cloudtemplate.rb +127 -0
- data/lib/megam/core/cloudtemplate_collection.rb +145 -0
- data/lib/megam/core/cloudtool.rb +153 -0
- data/lib/megam/core/cloudtool_collection.rb +145 -0
- data/lib/megam/core/config.rb +44 -0
- data/lib/megam/core/error.rb +99 -0
- data/lib/megam/core/json_compat.rb +183 -0
- data/lib/megam/core/log.rb +33 -0
- data/lib/megam/core/node.rb +347 -0
- data/lib/megam/core/node_collection.rb +166 -0
- data/lib/megam/core/predef.rb +208 -0
- data/lib/megam/core/predef_collection.rb +164 -0
- data/lib/megam/core/predefcloud.rb +229 -0
- data/lib/megam/core/predefcloud_collection.rb +168 -0
- data/lib/megam/core/request.rb +187 -0
- data/lib/megam/core/request_collection.rb +145 -0
- data/lib/megam/core/stuff.rb +69 -0
- data/lib/megam/core/text.rb +88 -0
- data/lib/megam_api.rb +1 -0
- data/megam_api.gemspec +26 -0
- data/test/test_accounts.rb +46 -0
- data/test/test_appdefns.rb +23 -0
- data/test/test_appreqs.rb +28 -0
- data/test/test_boltdefns.rb +23 -0
- data/test/test_boltreqs.rb +28 -0
- data/test/test_cloudtools.rb +22 -0
- data/test/test_helper.rb +67 -0
- data/test/test_login.rb +12 -0
- data/test/test_logs.rb +15 -0
- data/test/test_nodes.rb +141 -0
- data/test/test_predefclouds.rb +67 -0
- data/test/test_predefs.rb +72 -0
- data/test/test_requests.rb +85 -0
- metadata +213 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012-2013 Megam Systems, Inc.
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Megam
|
17
|
+
class Auth
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@some_msg = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
#used by resque workers and any other background job
|
24
|
+
def auth
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def megam_rest
|
29
|
+
Megam::API.new(Megam::Config[:email], Megam::Config[:api_key])
|
30
|
+
end
|
31
|
+
|
32
|
+
def some_msg(arg=nil)
|
33
|
+
if arg != nil
|
34
|
+
@some_msg = arg
|
35
|
+
else
|
36
|
+
@some_msg
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def error?
|
41
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
42
|
+
end
|
43
|
+
|
44
|
+
# Transform the ruby obj -> to a Hash
|
45
|
+
def to_hash
|
46
|
+
index_hash = Hash.new
|
47
|
+
index_hash["json_claz"] = self.class.name
|
48
|
+
index_hash["some_msg"] = some_msg
|
49
|
+
index_hash
|
50
|
+
end
|
51
|
+
|
52
|
+
# Serialize this object as a hash: called from JsonCompat.
|
53
|
+
# Verify if this called from JsonCompat during testing.
|
54
|
+
def to_json(*a)
|
55
|
+
for_json.to_json(*a)
|
56
|
+
end
|
57
|
+
|
58
|
+
def for_json
|
59
|
+
result = { }
|
60
|
+
result
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create a Megam::Account from JSON (used by the backgroud job workers)
|
64
|
+
def self.json_create(o)
|
65
|
+
acct = new
|
66
|
+
acct.some_msg[:code] = o["code"] if o.has_key?("code")
|
67
|
+
acct.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
68
|
+
acct.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
69
|
+
acct.some_msg[:links] = o["links"] if o.has_key?("links")
|
70
|
+
acct
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.from_hash(o)
|
74
|
+
acct = self.new()
|
75
|
+
acct.from_hash(o)
|
76
|
+
acct
|
77
|
+
end
|
78
|
+
|
79
|
+
# just an auth
|
80
|
+
def self.auth
|
81
|
+
megam_rest.post_auth
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def to_s
|
87
|
+
Megam::Stuff.styled_hash(to_hash)
|
88
|
+
#"---> Megam::Account:[error=#{error?}]\n"+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012, 2013 Megam Systems
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Megam
|
18
|
+
class Boltdefns
|
19
|
+
# Each notify entry is a resource/action pair, modeled as an
|
20
|
+
# Struct with a #resource and #action member
|
21
|
+
=begin
|
22
|
+
def self.hash_tree
|
23
|
+
Hash.new do |hash, key|
|
24
|
+
hash[key] = hash_tree
|
25
|
+
end
|
26
|
+
end
|
27
|
+
=end
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@id = nil
|
31
|
+
@node_id = nil
|
32
|
+
@node_name = nil
|
33
|
+
@boltdefns ={}
|
34
|
+
@created_at = nil
|
35
|
+
end
|
36
|
+
def node
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def megam_rest
|
41
|
+
options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
|
42
|
+
Megam::API.new(options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def id(arg=nil)
|
46
|
+
if arg != nil
|
47
|
+
@id = arg
|
48
|
+
else
|
49
|
+
@id
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def node_id(arg=nil)
|
54
|
+
if arg != nil
|
55
|
+
@node_id = arg
|
56
|
+
else
|
57
|
+
@node_id
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def node_name(arg=nil)
|
62
|
+
if arg != nil
|
63
|
+
@node_name = arg
|
64
|
+
else
|
65
|
+
@node_name
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def boltdefns(arg=nil)
|
70
|
+
if arg != nil
|
71
|
+
@boltdefns = arg
|
72
|
+
else
|
73
|
+
@boltdefns
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def created_at(arg=nil)
|
79
|
+
if arg != nil
|
80
|
+
@created_at = arg
|
81
|
+
else
|
82
|
+
@created_at
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def error?
|
87
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
88
|
+
end
|
89
|
+
|
90
|
+
# Transform the ruby obj -> to a Hash
|
91
|
+
def to_hash
|
92
|
+
index_hash = Hash.new
|
93
|
+
index_hash["json_claz"] = self.class.name
|
94
|
+
index_hash["id"] = id
|
95
|
+
index_hash["node_id"] = node_id
|
96
|
+
index_hash["node_name"] = node_name
|
97
|
+
index_hash["boltdefns"] = boltdefns
|
98
|
+
index_hash["created_at"] = created_at
|
99
|
+
index_hash
|
100
|
+
end
|
101
|
+
|
102
|
+
# Serialize this object as a hash: called from JsonCompat.
|
103
|
+
# Verify if this called from JsonCompat during testing.
|
104
|
+
def to_json(*a)
|
105
|
+
for_json.to_json(*a)
|
106
|
+
end
|
107
|
+
|
108
|
+
def for_json
|
109
|
+
result = {
|
110
|
+
"id" => id,
|
111
|
+
"node_id" => node_id,
|
112
|
+
"node_name" => node_name,
|
113
|
+
"boltdefns" => boltdefns,
|
114
|
+
"created_at" => created_at
|
115
|
+
}
|
116
|
+
result
|
117
|
+
end
|
118
|
+
|
119
|
+
# Create a Megam::Node from NodeResult-JSON
|
120
|
+
#
|
121
|
+
#[{
|
122
|
+
#"id":"NOD362212018897289216",
|
123
|
+
#"accounts_id":"ACT362211962353876992",
|
124
|
+
#"json_claz":"Megam::Node",
|
125
|
+
#"request":{
|
126
|
+
#"req_id":"NOD362212018897289216",
|
127
|
+
#"command":"commands"
|
128
|
+
#},
|
129
|
+
#"predefs":{
|
130
|
+
#"name":"",
|
131
|
+
#"scm":"",
|
132
|
+
#"war":"",
|
133
|
+
#"db":"",
|
134
|
+
#"queue":""
|
135
|
+
#}
|
136
|
+
#}]
|
137
|
+
#
|
138
|
+
def self.json_create(o)
|
139
|
+
node = new
|
140
|
+
node.id(o["id"]) if o.has_key?("id")
|
141
|
+
node.node_id(o["node_id"]) if o.has_key?("node_id")
|
142
|
+
node.node_name(o["node_name"]) if o.has_key?("node_name")
|
143
|
+
node.created_at(o["created_at"]) if o.has_key?("created_at")
|
144
|
+
|
145
|
+
|
146
|
+
#APP DEFINITIONS
|
147
|
+
op = o["boltdefns"]
|
148
|
+
node.boltdefns[:username] = op["username"] if op && op.has_key?("username")
|
149
|
+
node.boltdefns[:apikey] = op["apikey"] if op && op.has_key?("apikey")
|
150
|
+
node.boltdefns[:store_name]= op["store_name"] if op && op.has_key?("store_name")
|
151
|
+
node.boltdefns[:url] = op["url"] if op && op.has_key?("url")
|
152
|
+
node.boltdefns[:prime] = op["prime"] if op && op.has_key?("prime")
|
153
|
+
|
154
|
+
node.boltdefns[:timetokill] = op["timetokill"] if op && op.has_key?("timetokill")
|
155
|
+
node.boltdefns[:metered] = op["metered"] if op && op.has_key?("metered")
|
156
|
+
node.boltdefns[:logging]= op["logging"] if op && op.has_key?("logging")
|
157
|
+
node.boltdefns[:runtime_exec] = op["runtime_exec"] if op && op.has_key?("runtime_exec")
|
158
|
+
node
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.from_hash(o)
|
162
|
+
node = self.new()
|
163
|
+
node.from_hash(o)
|
164
|
+
node
|
165
|
+
end
|
166
|
+
|
167
|
+
def from_hash(o)
|
168
|
+
@id = o["id"] if o.has_key?("id")
|
169
|
+
@node_id = o["node_id"] if o.has_key?("node_id")
|
170
|
+
@node_name = o["node_name"] if o.has_key?("node_name")
|
171
|
+
@boltdefns = o["boltdefns"] if o.has_key?("boltdefns")
|
172
|
+
@created_at = o["created_at"] if o.has_key?("created_at")
|
173
|
+
self
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.create(o)
|
177
|
+
acct = from_hash(o)
|
178
|
+
acct.create
|
179
|
+
end
|
180
|
+
|
181
|
+
# Create the node via the REST API
|
182
|
+
def create
|
183
|
+
megam_rest.post_boltdefn(to_hash)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Load a account by email_p
|
187
|
+
def self.show(node_name)
|
188
|
+
megam_rest.get_boltdefn(node_name)
|
189
|
+
self
|
190
|
+
end
|
191
|
+
|
192
|
+
def to_s
|
193
|
+
Megam::Stuff.styled_hash(to_hash)
|
194
|
+
#"---> Megam::Account:[error=#{error?}]\n"+
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012, 2013 Megam Systems
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by boltlicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Megam
|
17
|
+
class BoltdefnsCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
|
21
|
+
attr_reader :iterator
|
22
|
+
def initialize
|
23
|
+
@boltdefns = Array.new
|
24
|
+
@boltdefns_by_name = Hash.new
|
25
|
+
@insert_after_idx = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def all_boltdefns
|
29
|
+
@boltdefns
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](index)
|
33
|
+
@boltdefns[index]
|
34
|
+
end
|
35
|
+
|
36
|
+
def []=(index, arg)
|
37
|
+
is_megam_boltdefn(arg)
|
38
|
+
@boltdefns[index] = arg
|
39
|
+
@boltdefns_by_name[arg.id] = index
|
40
|
+
end
|
41
|
+
|
42
|
+
def <<(*args)
|
43
|
+
args.flatten.each do |a|
|
44
|
+
is_megam_boltdefn(a)
|
45
|
+
@boltdefns << a
|
46
|
+
@boltdefns_by_name[a.id] = @boltdefns.length - 1
|
47
|
+
end
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
# 'push' is an alias method to <<
|
52
|
+
alias_method :push, :<<
|
53
|
+
|
54
|
+
def insert(boltdefn)
|
55
|
+
is_megam_boltdefn(boltdefn)
|
56
|
+
if @insert_after_idx
|
57
|
+
# in the middle of executing a run, so any boltdefnss inserted now should
|
58
|
+
# be placed after the most recent addition done by the currently executing
|
59
|
+
# boltdefns
|
60
|
+
@boltdefns.insert(@insert_after_idx + 1, boltdefn)
|
61
|
+
# update name -> location mappings and register new boltdefns
|
62
|
+
@boltdefns_by_name.each_key do |key|
|
63
|
+
@boltdefns_by_name[key] += 1 if @boltdefns_by_name[key] > @insert_after_idx
|
64
|
+
end
|
65
|
+
@boltdefns_by_name[boltdefn.id] = @insert_after_idx + 1
|
66
|
+
@insert_after_idx += 1
|
67
|
+
else
|
68
|
+
@boltdefns << boltdefn
|
69
|
+
@boltdefns_by_name[boltdefn.id] = @boltdefns.length - 1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def each
|
74
|
+
@boltdefns.each do |boltdefn|
|
75
|
+
yield boltdefn
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def each_index
|
80
|
+
@boltdefns.each_index do |i|
|
81
|
+
yield i
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def empty?
|
86
|
+
@boltdefns.empty?
|
87
|
+
end
|
88
|
+
|
89
|
+
def lookup(boltdefn)
|
90
|
+
lookup_by = nil
|
91
|
+
if boltdefn.kind_of?(Megam::Boltdefns)
|
92
|
+
lookup_by = boltdefn.id
|
93
|
+
elsif boltdefn.kind_of?(String)
|
94
|
+
lookup_by = boltdefn
|
95
|
+
else
|
96
|
+
raise ArgumentError, "Must pass a Megam::Boltdefns or String to lookup"
|
97
|
+
end
|
98
|
+
res = @boltdefns_by_name[lookup_by]
|
99
|
+
unless res
|
100
|
+
raise ArgumentError, "Cannot find a boltdefn matching #{lookup_by} (did you define it first?)"
|
101
|
+
end
|
102
|
+
@boltdefns[res]
|
103
|
+
end
|
104
|
+
|
105
|
+
# Transform the ruby obj -> to a Hash
|
106
|
+
def to_hash
|
107
|
+
index_hash = Hash.new
|
108
|
+
self.each do |boltdefn|
|
109
|
+
index_hash[boltdefn.id] = boltdefn.to_s
|
110
|
+
end
|
111
|
+
index_hash
|
112
|
+
end
|
113
|
+
|
114
|
+
# Serialize this object as a hash: called from JsonCompat.
|
115
|
+
# Verify if this called from JsonCompat during testing.
|
116
|
+
def to_json(*a)
|
117
|
+
for_json.to_json(*a)
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
def self.json_create(o)
|
122
|
+
collection = self.new()
|
123
|
+
o["results"].each do |boltdefns_list|
|
124
|
+
boltdefns_array = boltdefns_list.kind_of?(Array) ? boltdefns_list : [ boltdefns_list ]
|
125
|
+
boltdefns_array.each do |boltdefn|
|
126
|
+
collection.insert(boltdefn)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
collection
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
def is_megam_boltdefn(arg)
|
137
|
+
unless arg.kind_of?(Megam::Boltdefns)
|
138
|
+
raise ArgumentError, "Members must be Megam::Boltdefn's"
|
139
|
+
end
|
140
|
+
true
|
141
|
+
end
|
142
|
+
|
143
|
+
def to_s
|
144
|
+
Megam::Stuff.styled_hash(to_hash)
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2012, 2013 Megam Systems
|
2
|
+
# License:: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Megam
|
17
|
+
class Boltreqs
|
18
|
+
# Each notify entry is a resource/action pair, modeled as an
|
19
|
+
# Struct with a #resource and #action member
|
20
|
+
=begin
|
21
|
+
def self.hash_tree
|
22
|
+
Hash.new do |hash, key|
|
23
|
+
hash[key] = hash_tree
|
24
|
+
end
|
25
|
+
end
|
26
|
+
=end
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@id = nil
|
30
|
+
@req_type = nil
|
31
|
+
@boltdefns_id = nil
|
32
|
+
@node_name = nil
|
33
|
+
@lc_apply = nil
|
34
|
+
@lc_additional = nil
|
35
|
+
@lc_when = nil
|
36
|
+
@created_at = nil
|
37
|
+
end
|
38
|
+
def node
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def megam_rest
|
43
|
+
options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
|
44
|
+
Megam::API.new(options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def id(arg=nil)
|
48
|
+
if arg != nil
|
49
|
+
@id = arg
|
50
|
+
else
|
51
|
+
@id
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def req_type(arg=nil)
|
56
|
+
if arg != nil
|
57
|
+
@req_type = arg
|
58
|
+
else
|
59
|
+
@req_type
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def boltdefns_id(arg=nil)
|
64
|
+
if arg != nil
|
65
|
+
@boltdefns_id = arg
|
66
|
+
else
|
67
|
+
@boltdefns_id
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def node_name(arg=nil)
|
72
|
+
if arg != nil
|
73
|
+
@node_name = arg
|
74
|
+
else
|
75
|
+
@node_name
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def lc_apply(arg=nil)
|
80
|
+
if arg != nil
|
81
|
+
@lc_apply = arg
|
82
|
+
else
|
83
|
+
@lc_apply
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def lc_additional(arg=nil)
|
88
|
+
if arg != nil
|
89
|
+
@lc_additional = arg
|
90
|
+
else
|
91
|
+
@lc_additional
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def lc_when(arg=nil)
|
96
|
+
if arg != nil
|
97
|
+
@lc_when = arg
|
98
|
+
else
|
99
|
+
@lc_when
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def created_at(arg=nil)
|
104
|
+
if arg != nil
|
105
|
+
@created_at = arg
|
106
|
+
else
|
107
|
+
@created_at
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def error?
|
112
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
113
|
+
end
|
114
|
+
|
115
|
+
# Transform the ruby obj -> to a Hash
|
116
|
+
def to_hash
|
117
|
+
index_hash = Hash.new
|
118
|
+
index_hash["json_claz"] = self.class.name
|
119
|
+
index_hash["id"] = id
|
120
|
+
index_hash["req_type"] = req_type
|
121
|
+
index_hash["boltdefns_id"] = boltdefns_id
|
122
|
+
index_hash["node_name"] = node_name
|
123
|
+
index_hash["lc_apply"] = lc_apply
|
124
|
+
index_hash["lc_additional"] = lc_additional
|
125
|
+
index_hash["lc_when"] = lc_when
|
126
|
+
index_hash["created_at"] = created_at
|
127
|
+
index_hash
|
128
|
+
end
|
129
|
+
|
130
|
+
# Serialize this object as a hash: called from JsonCompat.
|
131
|
+
# Verify if this called from JsonCompat during testing.
|
132
|
+
def to_json(*a)
|
133
|
+
for_json.to_json(*a)
|
134
|
+
end
|
135
|
+
|
136
|
+
def for_json
|
137
|
+
result = {
|
138
|
+
"id" => id,
|
139
|
+
"req_type" => req_type,
|
140
|
+
"boltdefns_id" => boltdefns_id,
|
141
|
+
"node_name" => node_name,
|
142
|
+
"lc_apply" => lc_apply,
|
143
|
+
"lc_additional" => lc_additional,
|
144
|
+
"lc_when" => lc_when,
|
145
|
+
"created_at" => created_at
|
146
|
+
}
|
147
|
+
result
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
# Create a Megam::Node from NodeResult-JSON
|
152
|
+
#
|
153
|
+
#[{
|
154
|
+
#"id":"NOD362212018897289216",
|
155
|
+
#"accounts_id":"ACT362211962353876992",
|
156
|
+
#"json_claz":"Megam::Node",
|
157
|
+
#"request":{
|
158
|
+
#"req_id":"NOD362212018897289216",
|
159
|
+
#"command":"commands"
|
160
|
+
#},
|
161
|
+
#"predefs":{
|
162
|
+
#"name":"",
|
163
|
+
#"scm":"",
|
164
|
+
#"war":"",
|
165
|
+
#"db":"",
|
166
|
+
#"queue":""
|
167
|
+
#}
|
168
|
+
#}]
|
169
|
+
#
|
170
|
+
def self.json_create(o)
|
171
|
+
node = new
|
172
|
+
node.id(o["id"]) if o.has_key?("id")
|
173
|
+
node.req_type(o["req_type"]) if o.has_key?("req_type")
|
174
|
+
node.boltdefns_id(o["boltdefns_id"]) if o.has_key?("boltdefns_id")
|
175
|
+
node.node_name(o["node_name"]) if o.has_key?("node_name")
|
176
|
+
node.lc_apply(o["lc_apply"]) if o.has_key?("lc_apply")
|
177
|
+
node.lc_additional(o["lc_additional"]) if o.has_key?("lc_additional")
|
178
|
+
node.lc_when(o["lc_when"]) if o.has_key?("lc_when")
|
179
|
+
node.created_at(o["created_at"]) if o.has_key?("created_at")
|
180
|
+
|
181
|
+
node
|
182
|
+
end
|
183
|
+
|
184
|
+
def self.from_hash(o)
|
185
|
+
node = self.new()
|
186
|
+
node.from_hash(o)
|
187
|
+
node
|
188
|
+
end
|
189
|
+
|
190
|
+
def from_hash(o)
|
191
|
+
@id = o["id"] if o.has_key?("id")
|
192
|
+
@req_type = o["req_type"] if o.has_key?("req_type")
|
193
|
+
@boltdefns_id = o["boltdefns_id"] if o.has_key?("boltdefns_id")
|
194
|
+
@node_name = o["node_name"] if o.has_key?("node_name")
|
195
|
+
@lc_apply = o["lc_apply"] if o.has_key?("lc_apply")
|
196
|
+
@lc_additional = o["lc_additional"] if o.has_key?("lc_additional")
|
197
|
+
@lc_when = o["lc_when"] if o.has_key?("lc_when")
|
198
|
+
@created_at = o["created_at"] if o.has_key?("created_at")
|
199
|
+
self
|
200
|
+
end
|
201
|
+
|
202
|
+
def self.create(o)
|
203
|
+
acct = from_hash(o)
|
204
|
+
acct.create
|
205
|
+
end
|
206
|
+
|
207
|
+
# Create the node via the REST API
|
208
|
+
def create
|
209
|
+
megam_rest.post_node(to_hash)
|
210
|
+
end
|
211
|
+
|
212
|
+
# Load a account by email_p
|
213
|
+
def self.show(node_name)
|
214
|
+
megam_rest.get_node(node_name)
|
215
|
+
self
|
216
|
+
end
|
217
|
+
|
218
|
+
def to_s
|
219
|
+
Megam::Stuff.styled_hash(to_hash)
|
220
|
+
#"---> Megam::Account:[error=#{error?}]\n"+
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
end
|