megam_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,44 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2012-2013 Megam Systems.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'mixlib/config'
|
18
|
+
|
19
|
+
module Megam
|
20
|
+
class Config
|
21
|
+
|
22
|
+
extend Mixlib::Config
|
23
|
+
|
24
|
+
def self.inspect
|
25
|
+
configuration.inspect
|
26
|
+
end
|
27
|
+
|
28
|
+
megam_api_server_url "http://localhost:9000"
|
29
|
+
|
30
|
+
megam_api_version "v1"
|
31
|
+
|
32
|
+
email nil
|
33
|
+
api_key nil
|
34
|
+
|
35
|
+
# Set these to enable SSL authentication / mutual-authentication
|
36
|
+
# with the server
|
37
|
+
ssl_client_cert nil
|
38
|
+
ssl_client_key nil
|
39
|
+
ssl_verify_mode :verify_none
|
40
|
+
ssl_ca_path nil
|
41
|
+
ssl_ca_file nil
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,99 @@
|
|
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 Error
|
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
|
+
def from_hash(o)
|
80
|
+
@some_msg[:code] = o["code"] if o.has_key?("code")
|
81
|
+
@some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
82
|
+
@some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
83
|
+
@some_msg[:links] = o["links"] if o.has_key?("links")
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
# just an auth
|
88
|
+
def self.auth
|
89
|
+
megam_rest.post_auth
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def to_s
|
95
|
+
Megam::Stuff.styled_hash(to_hash)
|
96
|
+
#"---> Megam::Account:[error=#{error?}]\n"+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
#
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
3
|
+
# you may not use this file except in compliance with the License.
|
4
|
+
# You may obtain a copy of the License at
|
5
|
+
#
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
7
|
+
#
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
# See the License for the specific language governing permissions and
|
12
|
+
# limitations under the License.
|
13
|
+
|
14
|
+
# Wrapper class for interacting with JSON.
|
15
|
+
|
16
|
+
require 'yajl/json_gem'
|
17
|
+
require 'yajl'
|
18
|
+
|
19
|
+
module Megam
|
20
|
+
class JSONCompat
|
21
|
+
JSON_MAX_NESTING = 1000
|
22
|
+
|
23
|
+
JSON_CLAZ = "json_claz".freeze
|
24
|
+
|
25
|
+
MEGAM_AUTH = "Megam::Auth".freeze
|
26
|
+
MEGAM_ERROR = "Megam::Error".freeze
|
27
|
+
MEGAM_ACCOUNT = "Megam::Account".freeze
|
28
|
+
MEGAM_NODE = "Megam::Node".freeze
|
29
|
+
MEGAM_APPDEFNS = "Megam::AppDefns".freeze
|
30
|
+
MEGAM_APPREQS = "Megam::AppRequest".freeze
|
31
|
+
MEGAM_BOLTREQS = "Megam::BoltRequest".freeze
|
32
|
+
MEGAM_BOLTDEFNS = "Megam::BoltDefns".freeze
|
33
|
+
MEGAM_NODECOLLECTION = "Megam::NodeCollection".freeze
|
34
|
+
MEGAM_APPDEFNSCOLLECTION = "Megam::AppDefnCollection".freeze
|
35
|
+
MEGAM_APPREQSCOLLECTION = "Megam::AppRequestCollection".freeze
|
36
|
+
MEGAM_BOLTREQSCOLLECTION = "Megam::BoltRequestCollection".freeze
|
37
|
+
MEGAM_BOLTDEFNSCOLLECTION = "Megam::BoltDefnCollection".freeze
|
38
|
+
MEGAM_REQUEST = "Megam::Request".freeze
|
39
|
+
MEGAM_REQUESTCOLLECTION = "Megam::RequestCollection".freeze
|
40
|
+
|
41
|
+
MEGAM_PREDEF = "Megam::Predef".freeze
|
42
|
+
MEGAM_PREDEFCOLLECTION = "Megam::PredefCollection".freeze
|
43
|
+
MEGAM_PREDEFCLOUD = "Megam::PredefCloud".freeze
|
44
|
+
MEGAM_PREDEFCLOUDCOLLECTION = "Megam::PredefCloudCollection".freeze
|
45
|
+
MEGAM_CLOUDTOOL = "Megam::CloudTool".freeze
|
46
|
+
MEGAM_CLOUDTOOLCOLLECTION = "Megam::CloudToolCollection".freeze
|
47
|
+
MEGAM_CLOUDTEMPLATE = "Megam::CloudTemplate".freeze
|
48
|
+
MEGAM_CLOUDTEMPLATECOLLECTION = "Megam::CloudTemplateCollection".freeze
|
49
|
+
MEGAM_CLOUDINSTRUCTION = "Megam::CloudInstruction".freeze
|
50
|
+
MEGAM_CLOUDINSTRUCTIONCOLLECTION = "Megam::CloudInstructionCollection".freeze
|
51
|
+
MEGAM_CLOUDINSTRUCTIONGROUP = "Megam::CloudInstructionGroup".freeze
|
52
|
+
class <<self
|
53
|
+
# Increase the max nesting for JSON, which defaults
|
54
|
+
# to 19, and isn't enough for some (for example, a Node within a Node)
|
55
|
+
# structures.
|
56
|
+
def opts_add_max_nesting(opts)
|
57
|
+
if opts.nil? || !opts.has_key?(:max_nesting)
|
58
|
+
opts = opts.nil? ? Hash.new : opts.clone
|
59
|
+
opts[:max_nesting] = JSON_MAX_NESTING
|
60
|
+
end
|
61
|
+
opts
|
62
|
+
end
|
63
|
+
|
64
|
+
# Just call the JSON gem's parse method with a modified :max_nesting field
|
65
|
+
def from_json(source, opts = {})
|
66
|
+
obj = ::Yajl::Parser.parse(source)
|
67
|
+
# JSON gem requires top level object to be a Hash or Array (otherwise
|
68
|
+
# you get the "must contain two octets" error). Yajl doesn't impose the
|
69
|
+
# same limitation. For compatibility, we re-impose this condition.
|
70
|
+
unless obj.kind_of?(Hash) or obj.kind_of?(Array)
|
71
|
+
raise JSON::ParserError, "Top level JSON object must be a Hash or Array. (actual: #{obj.class})"
|
72
|
+
end
|
73
|
+
|
74
|
+
# The old default in the json gem (which we are mimicing because we
|
75
|
+
# sadly rely on this misfeature) is to "create additions" i.e., convert
|
76
|
+
# JSON objects into ruby objects. Explicit :create_additions => false
|
77
|
+
# is required to turn it off.
|
78
|
+
if opts[:create_additions].nil? || opts[:create_additions]
|
79
|
+
map_to_rb_obj(obj)
|
80
|
+
else
|
81
|
+
obj
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Look at an object that's a basic type (from json parse) and convert it
|
86
|
+
# to an instance of Megam classes if desired.
|
87
|
+
def map_to_rb_obj(json_obj)
|
88
|
+
case json_obj
|
89
|
+
when Hash
|
90
|
+
mapped_hash = map_hash_to_rb_obj(json_obj)
|
91
|
+
if json_obj.has_key?(JSON_CLAZ) && (class_to_inflate = class_for_json_class(json_obj[JSON_CLAZ]))
|
92
|
+
class_to_inflate.json_create(mapped_hash)
|
93
|
+
else
|
94
|
+
mapped_hash
|
95
|
+
end
|
96
|
+
when Array
|
97
|
+
json_obj.map {|e| map_to_rb_obj(e) }
|
98
|
+
else
|
99
|
+
json_obj
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def map_hash_to_rb_obj(json_hash)
|
104
|
+
json_hash.each do |key, value|
|
105
|
+
json_hash[key] = map_to_rb_obj(value)
|
106
|
+
end
|
107
|
+
json_hash
|
108
|
+
end
|
109
|
+
|
110
|
+
def to_json(obj, opts = nil)
|
111
|
+
obj.to_json(opts_add_max_nesting(opts))
|
112
|
+
end
|
113
|
+
|
114
|
+
def to_json_pretty(obj, opts = nil)
|
115
|
+
::JSON.pretty_generate(obj, opts_add_max_nesting(opts))
|
116
|
+
end
|
117
|
+
|
118
|
+
# Map +JSON_CLAZ+ to a Class object. We use a +case+ instead of a Hash
|
119
|
+
# assigned to a constant because otherwise this file could not be loaded
|
120
|
+
# until all the constants were defined, which means you'd have to load
|
121
|
+
# the world to get json.
|
122
|
+
def class_for_json_class(json_class)
|
123
|
+
case json_class
|
124
|
+
when MEGAM_ERROR
|
125
|
+
Megam::Error
|
126
|
+
when MEGAM_AUTH
|
127
|
+
Megam::Auth
|
128
|
+
when MEGAM_ACCOUNT
|
129
|
+
Megam::Account
|
130
|
+
when MEGAM_NODE
|
131
|
+
Megam::Node
|
132
|
+
when MEGAM_APPDEFNS
|
133
|
+
Megam::Appdefns
|
134
|
+
when MEGAM_APPREQS
|
135
|
+
Megam::Appreqs
|
136
|
+
when MEGAM_BOLTREQS
|
137
|
+
Megam::Boltreqs
|
138
|
+
when MEGAM_BOLTDEFNS
|
139
|
+
Megam::Boltdefns
|
140
|
+
when MEGAM_NODECOLLECTION
|
141
|
+
Megam::NodeCollection
|
142
|
+
when MEGAM_APPDEFNSCOLLECTION
|
143
|
+
Megam::AppdefnsCollection
|
144
|
+
when MEGAM_APPREQSCOLLECTION
|
145
|
+
Megam::AppreqsCollection
|
146
|
+
when MEGAM_BOLTREQSCOLLECTION
|
147
|
+
Megam::BoltreqsCollection
|
148
|
+
when MEGAM_BOLTDEFNSCOLLECTION
|
149
|
+
Megam::BoltdefnsCollection
|
150
|
+
when MEGAM_REQUEST
|
151
|
+
Megam::Request
|
152
|
+
when MEGAM_REQUESTCOLLECTION
|
153
|
+
Megam::RequestCollection
|
154
|
+
when MEGAM_PREDEF
|
155
|
+
Megam::Predef
|
156
|
+
when MEGAM_PREDEFCOLLECTION
|
157
|
+
Megam::PredefCollection
|
158
|
+
when MEGAM_PREDEFCLOUD
|
159
|
+
Megam::PredefCloud
|
160
|
+
when MEGAM_PREDEFCLOUDCOLLECTION
|
161
|
+
Megam::PredefCloudCollection
|
162
|
+
when MEGAM_CLOUDTOOL
|
163
|
+
Megam::CloudTool
|
164
|
+
when MEGAM_CLOUDTOOLCOLLECTION
|
165
|
+
Megam::CloudToolCollection
|
166
|
+
when MEGAM_CLOUDTEMPLATE
|
167
|
+
Megam::CloudTemplate
|
168
|
+
when MEGAM_CLOUDTEMPLATECOLLECTION
|
169
|
+
Megam::CloudTemplateCollection
|
170
|
+
when MEGAM_CLOUDINSTRUCTION
|
171
|
+
Megam::CloudInstruction
|
172
|
+
when MEGAM_CLOUDINSTRUCTIONGROUP
|
173
|
+
Megam::CloudInstructionGroup
|
174
|
+
when MEGAM_CLOUDINSTRUCTIONCOLLECTION
|
175
|
+
Megam::CloudInstructionCollection
|
176
|
+
else
|
177
|
+
raise JSON::ParserError, "Unsupported `json_class` type '#{json_class}'"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#
|
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
|
+
require 'logger'
|
17
|
+
require 'mixlib/log'
|
18
|
+
|
19
|
+
module Megam
|
20
|
+
class Log
|
21
|
+
extend Mixlib::Log
|
22
|
+
|
23
|
+
# Force initialization of the primary log device (@logger)
|
24
|
+
init
|
25
|
+
|
26
|
+
class Formatter
|
27
|
+
def self.show_time=(*args)
|
28
|
+
Mixlib::Log::Formatter.show_time = *args
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,347 @@
|
|
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
|
+
require 'hashie'
|
17
|
+
module Megam
|
18
|
+
class Node
|
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_name = nil
|
32
|
+
@accounts_id = nil
|
33
|
+
@node_type = nil
|
34
|
+
@req_type = nil
|
35
|
+
@status=nil
|
36
|
+
@noofinstances=0
|
37
|
+
@request ={}
|
38
|
+
@predefs={}
|
39
|
+
@some_msg = {}
|
40
|
+
#@command = self.class.hash_tree
|
41
|
+
@command = Hashie::Mash.new
|
42
|
+
@appdefns = {}
|
43
|
+
@boltdefns = {}
|
44
|
+
@created_at = nil
|
45
|
+
end
|
46
|
+
def node
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def megam_rest
|
51
|
+
options = { :email => Megam::Config[:email], :api_key => Megam::Config[:api_key]}
|
52
|
+
Megam::API.new(options)
|
53
|
+
end
|
54
|
+
|
55
|
+
def node_name(arg=nil)
|
56
|
+
if arg != nil
|
57
|
+
@node_name = arg
|
58
|
+
else
|
59
|
+
@node_name
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def noofinstances(arg=nil)
|
64
|
+
if arg != nil
|
65
|
+
@noofinstances = arg
|
66
|
+
else
|
67
|
+
@noofinstances
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def command(arg=nil)
|
72
|
+
if arg != nil
|
73
|
+
@command = arg
|
74
|
+
else
|
75
|
+
@command
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def id(arg=nil)
|
80
|
+
if arg != nil
|
81
|
+
@id = arg
|
82
|
+
else
|
83
|
+
@id
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def accounts_id(arg=nil)
|
88
|
+
if arg != nil
|
89
|
+
@accounts_id = arg
|
90
|
+
else
|
91
|
+
@accounts_id
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def node_type(arg=nil)
|
96
|
+
if arg != nil
|
97
|
+
@node_type = arg
|
98
|
+
else
|
99
|
+
@node_type
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def req_type(arg=nil)
|
104
|
+
if arg != nil
|
105
|
+
@req_type = arg
|
106
|
+
else
|
107
|
+
@req_type
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def status(arg=nil)
|
112
|
+
if arg != nil
|
113
|
+
@status = arg
|
114
|
+
else
|
115
|
+
@status
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def request(arg=nil)
|
120
|
+
if arg != nil
|
121
|
+
@request = arg
|
122
|
+
else
|
123
|
+
@request
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def predefs(arg=nil)
|
128
|
+
if arg != nil
|
129
|
+
@predefs = arg
|
130
|
+
else
|
131
|
+
@predefs
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def appdefns(arg=nil)
|
136
|
+
if arg != nil
|
137
|
+
@appdefns = arg
|
138
|
+
else
|
139
|
+
@appdefns
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def boltdefns(arg=nil)
|
144
|
+
if arg != nil
|
145
|
+
@boltdefns = arg
|
146
|
+
else
|
147
|
+
@boltdefns
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def created_at(arg=nil)
|
152
|
+
if arg != nil
|
153
|
+
@created_at = arg
|
154
|
+
else
|
155
|
+
@created_at
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def some_msg(arg=nil)
|
160
|
+
if arg != nil
|
161
|
+
@some_msg = arg
|
162
|
+
else
|
163
|
+
@some_msg
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def error?
|
168
|
+
crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
|
169
|
+
end
|
170
|
+
|
171
|
+
# Transform the ruby obj -> to a Hash
|
172
|
+
def to_hash
|
173
|
+
index_hash = Hash.new
|
174
|
+
index_hash["json_claz"] = self.class.name
|
175
|
+
index_hash["id"] = id
|
176
|
+
index_hash["node_name"] = node_name
|
177
|
+
index_hash["accounts_id"] = accounts_id
|
178
|
+
index_hash["node_type"] = node_type
|
179
|
+
index_hash["req_type"] = req_type
|
180
|
+
index_hash["status"] = status
|
181
|
+
index_hash["command"] = command
|
182
|
+
index_hash["request"] = request
|
183
|
+
index_hash["predefs"] = predefs
|
184
|
+
index_hash["appdefns"] = appdefns
|
185
|
+
index_hash["boltdefns"] = boltdefns
|
186
|
+
index_hash["some_msg"] = some_msg
|
187
|
+
index_hash["noofinstances"] = noofinstances.to_i
|
188
|
+
index_hash["created_at"] = created_at
|
189
|
+
index_hash
|
190
|
+
end
|
191
|
+
|
192
|
+
# Serialize this object as a hash: called from JsonCompat.
|
193
|
+
# Verify if this called from JsonCompat during testing.
|
194
|
+
def to_json(*a)
|
195
|
+
for_json.to_json(*a)
|
196
|
+
end
|
197
|
+
|
198
|
+
def for_json
|
199
|
+
result = {
|
200
|
+
"id" => id,
|
201
|
+
"node_name" => node_name,
|
202
|
+
"accounts_id" => accounts_id,
|
203
|
+
"node_type" => node_type,
|
204
|
+
"req_type" => req_type,
|
205
|
+
"status" => status,
|
206
|
+
"request" => request,
|
207
|
+
"predefs" => predefs,
|
208
|
+
"appdefns" => appdefns,
|
209
|
+
"boltdefns" => boltdefns,
|
210
|
+
"noofinstances" => noofinstances,
|
211
|
+
"created_at" => created_at
|
212
|
+
}
|
213
|
+
result
|
214
|
+
end
|
215
|
+
|
216
|
+
# Create a Megam::Node from NodeResult-JSON
|
217
|
+
#
|
218
|
+
#[{
|
219
|
+
#"id":"NOD362212018897289216",
|
220
|
+
#"accounts_id":"ACT362211962353876992",
|
221
|
+
#"json_claz":"Megam::Node",
|
222
|
+
#"request":{
|
223
|
+
#"req_id":"NOD362212018897289216",
|
224
|
+
#"command":"commands"
|
225
|
+
#},
|
226
|
+
#"predefs":{
|
227
|
+
#"name":"",
|
228
|
+
#"scm":"",
|
229
|
+
#"war":"",
|
230
|
+
#"db":"",
|
231
|
+
#"queue":""
|
232
|
+
#}
|
233
|
+
#}]
|
234
|
+
#
|
235
|
+
def self.json_create(o)
|
236
|
+
node = new
|
237
|
+
node.id(o["id"]) if o.has_key?("id")
|
238
|
+
node.node_name(o["node_name"]) if o.has_key?("node_name")
|
239
|
+
node.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
|
240
|
+
node.node_type(o["node_type"]) if o.has_key?("node_type")
|
241
|
+
node.req_type(o["req_type"]) if o.has_key?("req_type")
|
242
|
+
node.status(o["status"]) if o.has_key?("status")
|
243
|
+
node.noofinstances(o["noofinstances"]) if o.has_key?("noofinstances")
|
244
|
+
node.created_at(o["created_at"]) if o.has_key?("created_at")
|
245
|
+
#requests
|
246
|
+
oq = o["request"]
|
247
|
+
node.request[:req_id] = oq["req_id"] if oq && oq.has_key?("req_id")
|
248
|
+
node.request[:req_type] = oq["req_type"] if oq && oq.has_key?("req_type")
|
249
|
+
node.request[:command] = oq["command"] if oq && oq.has_key?("command")
|
250
|
+
|
251
|
+
#Command
|
252
|
+
oc = o["command"]
|
253
|
+
node.command = node.command(oc) if oc && oc.has_key?("systemprovider")
|
254
|
+
=begin
|
255
|
+
node.command[:systemprovider][:provider][:prov] = oc["systemprovider"]["provider"]["prov"]
|
256
|
+
node.command[:compute][:cctype] = oc["compute"]["cctype"]
|
257
|
+
node.command[:compute][:cc][:groups] = oc["compute"]["cc"]["groups"]
|
258
|
+
node.command[:compute][:cc][:image] = oc["compute"]["cc"]["image"]
|
259
|
+
node.command[:compute][:cc][:flavor] = oc["compute"]["cc"]["flavor"]
|
260
|
+
node.command[:compute][:access][:ssh_key] = oc["compute"]["access"]["ssh_key"]
|
261
|
+
node.command[:compute][:access][:identity_file] = oc["compute"]["access"]["identity_file"]
|
262
|
+
node.command[:compute][:access][:ssh_user] = oc["compute"]["access"]["ssh_user"]
|
263
|
+
node.command[:cloudtool][:chef][:command] = oc["cloudtool"]["chef"]["command"]
|
264
|
+
node.command[:cloudtool][:chef][:plugin] = oc["cloudtool"]["chef"]["plugin"]
|
265
|
+
node.command[:cloudtool][:chef][:run_list] = oc["cloudtool"]["chef"]["run_list"]
|
266
|
+
node.command[:cloudtool][:chef][:name] = oc["cloudtool"]["chef"]["name"]
|
267
|
+
=end
|
268
|
+
#predef
|
269
|
+
op = o["predefs"]
|
270
|
+
node.predefs[:name] = op["name"] if op && op.has_key?("name")
|
271
|
+
node.predefs[:scm] = op["scm"] if op && op.has_key?("scm")
|
272
|
+
node.predefs[:war]= op["war"] if op && op.has_key?("war")
|
273
|
+
node.predefs[:db] = op["db"] if op && op.has_key?("db")
|
274
|
+
node.predefs[:queue] = op["queue"] if op && op.has_key?("queue")
|
275
|
+
|
276
|
+
#APP DEFINITIONS
|
277
|
+
op = o["appdefns"]
|
278
|
+
node.appdefns[:timetokill] = op["timetokill"] if op && op.has_key?("timetokill")
|
279
|
+
node.appdefns[:metered] = op["metered"] if op && op.has_key?("metered")
|
280
|
+
node.appdefns[:logging]= op["logging"] if op && op.has_key?("logging")
|
281
|
+
node.appdefns[:runtime_exec] = op["runtime_exec"] if op && op.has_key?("runtime_exec")
|
282
|
+
|
283
|
+
#BOLT DEFINITIONS
|
284
|
+
op = o["boltdefns"]
|
285
|
+
node.boltdefns[:username] = op["username"] if op && op.has_key?("username")
|
286
|
+
node.boltdefns[:apikey] = op["apikey"] if op && op.has_key?("apikey")
|
287
|
+
node.boltdefns[:store_name]= op["store_name"] if op && op.has_key?("store_name")
|
288
|
+
node.boltdefns[:url] = op["url"] if op && op.has_key?("url")
|
289
|
+
node.boltdefns[:timetokill] = op["timetokill"] if op && op.has_key?("timetokill")
|
290
|
+
node.boltdefns[:metered] = op["metered"] if op && op.has_key?("metered")
|
291
|
+
node.boltdefns[:logging]= op["logging"] if op && op.has_key?("logging")
|
292
|
+
node.boltdefns[:runtime_exec] = op["runtime_exec"] if op && op.has_key?("runtime_exec")
|
293
|
+
|
294
|
+
#success or error
|
295
|
+
node.some_msg[:code] = o["code"] if o.has_key?("code")
|
296
|
+
node.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
|
297
|
+
node.some_msg[:msg]= o["msg"] if o.has_key?("msg")
|
298
|
+
node.some_msg[:links] = o["links"] if o.has_key?("links")
|
299
|
+
|
300
|
+
node
|
301
|
+
end
|
302
|
+
|
303
|
+
def self.from_hash(o)
|
304
|
+
node = self.new()
|
305
|
+
node.from_hash(o)
|
306
|
+
node
|
307
|
+
end
|
308
|
+
|
309
|
+
def from_hash(o)
|
310
|
+
@node_name = o["node_name"] if o.has_key?("node_name")
|
311
|
+
@command = o["command"] if o.has_key?("command")
|
312
|
+
@id = o["id"] if o.has_key?("id")
|
313
|
+
@accounts_id = o["accounts_id"] if o.has_key?("accounts_id")
|
314
|
+
@node_type = o["node_type"] if o.has_key?("node_type")
|
315
|
+
@req_type = o["req_type"] if o.has_key?("req_type")
|
316
|
+
@request = o["request"] if o.has_key?("request")
|
317
|
+
@predefs = o["predefs"] if o.has_key?("predefs")
|
318
|
+
@appdefns = o["appdefns"] if o.has_key?("appdefns")
|
319
|
+
@boltdefns = o["boltdefns"] if o.has_key?("boltdefns")
|
320
|
+
@noofinstances = o["noofinstances"] if o.has_key?("noofinstances")
|
321
|
+
@created_at = o["created_at"] if o.has_key?("created_at")
|
322
|
+
self
|
323
|
+
end
|
324
|
+
|
325
|
+
def self.create(o)
|
326
|
+
acct = from_hash(o)
|
327
|
+
acct.create
|
328
|
+
end
|
329
|
+
|
330
|
+
# Create the node via the REST API
|
331
|
+
def create
|
332
|
+
megam_rest.post_node(to_hash)
|
333
|
+
end
|
334
|
+
|
335
|
+
# Load a account by email_p
|
336
|
+
def self.show(node_name)
|
337
|
+
node = self.new()
|
338
|
+
node.megam_rest.get_node(node_name)
|
339
|
+
end
|
340
|
+
|
341
|
+
def to_s
|
342
|
+
Megam::Stuff.styled_hash(to_hash)
|
343
|
+
#"---> Megam::Account:[error=#{error?}]\n"+
|
344
|
+
end
|
345
|
+
|
346
|
+
end
|
347
|
+
end
|