megam_api 0.17 → 0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/lib/megam/api.rb +20 -35
  4. data/lib/megam/api/{nodes.rb → assemblies.rb} +9 -9
  5. data/lib/megam/api/domains.rb +30 -0
  6. data/lib/megam/api/organizations.rb +30 -0
  7. data/lib/megam/api/version.rb +1 -1
  8. data/lib/megam/core/assemblies.rb +180 -0
  9. data/lib/megam/core/{node_collection.rb → assemblies_collection.rb} +44 -65
  10. data/lib/megam/core/csar.rb +0 -1
  11. data/lib/megam/core/domains.rb +129 -0
  12. data/lib/megam/core/json_compat.rb +17 -4
  13. data/lib/megam/core/organizations.rb +129 -0
  14. data/test/test_accounts.rb +1 -1
  15. data/test/test_assemblies.rb +10 -0
  16. data/test/test_domains.rb +27 -0
  17. data/test/test_helper.rb +25 -16
  18. data/test/test_organizations.rb +26 -0
  19. metadata +12 -38
  20. data/lib/megam/api/app_request.rb +0 -27
  21. data/lib/megam/api/appdefns.rb +0 -47
  22. data/lib/megam/api/bolt_request.rb +0 -27
  23. data/lib/megam/api/boltdefns.rb +0 -39
  24. data/lib/megam/api/cloud_tools.rb +0 -35
  25. data/lib/megam/api/logs.rb +0 -18
  26. data/lib/megam/api/predefs.rb +0 -35
  27. data/lib/megam/builder/delete_node.rb +0 -107
  28. data/lib/megam/builder/make_node.rb +0 -133
  29. data/lib/megam/core/app_request.rb +0 -227
  30. data/lib/megam/core/app_request_collection.rb +0 -148
  31. data/lib/megam/core/appdefns.rb +0 -182
  32. data/lib/megam/core/appdefns_collection.rb +0 -148
  33. data/lib/megam/core/bolt_request.rb +0 -225
  34. data/lib/megam/core/bolt_request_collection.rb +0 -148
  35. data/lib/megam/core/boltdefns.rb +0 -207
  36. data/lib/megam/core/boltdefns_collection.rb +0 -148
  37. data/lib/megam/core/cloudinstruction.rb +0 -110
  38. data/lib/megam/core/cloudinstruction_collection.rb +0 -145
  39. data/lib/megam/core/cloudinstruction_group.rb +0 -99
  40. data/lib/megam/core/cloudtemplate.rb +0 -127
  41. data/lib/megam/core/cloudtemplate_collection.rb +0 -145
  42. data/lib/megam/core/cloudtool.rb +0 -152
  43. data/lib/megam/core/cloudtool_collection.rb +0 -145
  44. data/lib/megam/core/node.rb +0 -366
  45. data/lib/megam/core/predef.rb +0 -201
  46. data/lib/megam/core/predef_collection.rb +0 -164
  47. data/test/test_appdefns.rb +0 -35
  48. data/test/test_appreqs.rb +0 -25
  49. data/test/test_boltdefns.rb +0 -32
  50. data/test/test_boltreqs.rb +0 -26
  51. data/test/test_cloudtools.rb +0 -22
  52. data/test/test_nodes.rb +0 -140
  53. data/test/test_predefs.rb +0 -72
@@ -1,127 +0,0 @@
1
- # Copyright:: Copyright (c) 2012, 2014 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 CloudTemplate
18
- def initialize
19
- @cctype = nil
20
- @cloud_instruction_group = nil
21
- @cloud_instruction_group_by_name = Hash.new
22
- end
23
-
24
- def cloud_template
25
- self
26
- end
27
-
28
- def cctype(arg=nil)
29
- if arg != nil
30
- @cctype = arg
31
- else
32
- @cctype
33
- end
34
- end
35
-
36
- def cloud_instruction_group(arg=nil)
37
- if arg != nil
38
- @cloud_instruction_group = arg
39
- else
40
- @cloud_instruction_group
41
- end
42
- end
43
-
44
- def cloud_instruction_group_by_name(arg=nil)
45
- if arg != nil
46
- @cloud_instruction_group_by_name = arg
47
- else
48
- @cloud_instruction_group_by_name
49
- end
50
- end
51
-
52
- #returns a cloud instruction for a particular group
53
- def lookup_by_group_name(group)
54
- res =@cloud_instruction_group_by_name[group]
55
- unless res
56
- raise ArgumentError, "Cannot find a cloudgroup matching #{group} (did you define it first?)"
57
- end
58
- res
59
- end
60
-
61
- #returns a cloud instruction for a particular group, action
62
- def lookup_by_instruction(group,action)
63
- single_cig = lookup_by_group_name(group)
64
- #single_cig.cloud_instructions_array.select { |cloudinstructions| cloudinstructions.lookup(action) }
65
- single_cig.cloud_instructions_array.each do |cia|
66
- @ci= cia.lookup(action)
67
- end
68
- @ci
69
- end
70
-
71
- def error?
72
- crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
73
- end
74
-
75
- # Transform the ruby obj -> to a Hash
76
- def to_hash
77
- index_hash = Hash.new
78
- index_hash["json_claz"] = self.class.name
79
- index_hash["cctype"] = cctype
80
- cloud_instruction_group.each do |single_cig|
81
- index_hash[single_cig.group] = single_cig
82
- end
83
- index_hash
84
- end
85
-
86
- # Serialize this object as a hash: called from JsonCompat.
87
- # Verify if this called from JsonCompat during testing.
88
- def to_json(*a)
89
- for_json.to_json(*a)
90
- end
91
-
92
- def for_json
93
- result = {
94
- "cctype" => cctype,
95
- "cloud_instruction_group" => cloud_instruction_group
96
- }
97
- result
98
- end
99
-
100
- #
101
- def self.json_create(o)
102
- cloudtemplate = new
103
- cloudtemplate.cctype(o["cctype"]) if o.has_key?("cctype")
104
- cloudtemplate.cloud_instruction_group(o["cloud_instruction_group"]) if o.has_key?("cloud_instruction_group")
105
- cloudtemplate.cloud_instruction_group.each do |single_cig|
106
- cloudtemplate.cloud_instruction_group_by_name[single_cig.group] = single_cig
107
- end
108
- cloudtemplate
109
- end
110
-
111
- def self.from_hash(o)
112
- cloudtemplate = self.new()
113
- cloudtemplate.from_hash(o)
114
- cloudtemplate
115
- end
116
-
117
- def from_hash(o)
118
- @cctype = o[:cctype] if o.has_key?(:cctype)
119
- self
120
- end
121
-
122
- def to_s
123
- Megam::Stuff.styled_hash(to_hash)
124
- end
125
-
126
- end
127
- end
@@ -1,145 +0,0 @@
1
- # Copyright:: Copyright (c) 2012, 2014 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 CloudTemplateCollection
18
- include Enumerable
19
-
20
- attr_reader :iterator
21
- def initialize
22
- @cloudtemplates = Array.new
23
- @cloudtemplates_by_name = Hash.new
24
- @insert_after_idx = nil
25
- end
26
-
27
- def all_cloudtemplates
28
- @cloudtemplates
29
- end
30
-
31
- def [](index)
32
- @cloudtemplates[index]
33
- end
34
-
35
- def []=(index, arg)
36
- is_megam_cloudtemplate(arg)
37
- @cloudtemplates[index] = arg
38
- @cloudtemplates_by_name[arg.cctype] = index
39
- end
40
-
41
- def <<(*args)
42
- args.flatten.each do |a|
43
- is_megam_cloudtemplate(a)
44
- @cloudtemplates << a
45
- @cloudtemplates_by_name[a.cctype] =@cloudtemplates.length - 1
46
- end
47
- self
48
- end
49
-
50
- # 'push' is an alias method to <<
51
- alias_method :push, :<<
52
-
53
- def insert(cloudtemplate)
54
- is_megam_cloudtemplate(cloudtemplate)
55
- if @insert_after_idx
56
- # in the middle of executing a run, so any predefs inserted now should
57
- # be placed after the most recent addition done by the currently executing
58
- # cloudtemplates
59
- @cloudtemplates.insert(@insert_after_idx + 1, cloudtemplate)
60
- # update name -> location mappings and register new cloudtemplates
61
- @cloudtemplates_by_name.each_key do |key|
62
- @cloudtemplates_by_name[key] += 1 if@cloudtemplates_by_name[key] > @insert_after_idx
63
- end
64
- @cloudtemplates_by_name[cloudtemplate.cctype] = @insert_after_idx + 1
65
- @insert_after_idx += 1
66
- else
67
- @cloudtemplates << cloudtemplate
68
- @cloudtemplates_by_name[cloudtemplate.cctype] =@cloudtemplates.length - 1
69
- end
70
- end
71
-
72
- def each
73
- @cloudtemplates.each do |cloudtemplate|
74
- yield cloudtemplate
75
- end
76
- end
77
-
78
- def each_index
79
- @cloudtemplates.each_index do |i|
80
- yield i
81
- end
82
- end
83
-
84
- def empty?
85
- @cloudtemplates.empty?
86
- end
87
-
88
- def lookup(cloudtemplate)
89
- lookup_by = nil
90
- if cloudtemplate.kind_of?(Megam::CloudTemplate)
91
- lookup_by = cloudtemplate.cctype
92
- elsif cloudtemplate.kind_of?(String)
93
- lookup_by = cloudtemplate
94
- else
95
- raise ArgumentError, "Must pass a Megam::CloudTemplates or String to lookup"
96
- end
97
- res =@cloudtemplates_by_name[lookup_by]
98
- unless res
99
- raise ArgumentError, "Cannot find a cloudtemplates matching #{lookup_by} (did you define it first?)"
100
- end
101
- @cloudtemplates[res]
102
- end
103
-
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = Hash.new
107
- self.each do |cloudtemplate|
108
- index_hash[cloudtemplate.cctype] = cloudtemplate.to_s
109
- end
110
- index_hash
111
- end
112
-
113
- # Serialize this object as a hash: called from JsonCompat.
114
- # Verify if this called from JsonCompat during testing.
115
- def to_json(*a)
116
- for_json.to_json(*a)
117
- end
118
-
119
-
120
- def self.json_create(o)
121
- collection = self.new()
122
- o["results"].each do |cloudtemplates_list|
123
- cloudtemplates_array = cloudtemplates_list.kind_of?(Array) ? cloudtemplates_list : [ cloudtemplates_list ]
124
- cloudtemplates_array.each do |cloudtemplate|
125
- collection.insert(cloudtemplate)
126
- end
127
- end
128
- collection
129
- end
130
-
131
- private
132
-
133
- def is_megam_cloudtemplate(arg)
134
- unless arg.kind_of?(Megam::CloudTemplate)
135
- raise ArgumentError, "Members must be Megam::CloudTemplate's"
136
- end
137
- true
138
- end
139
-
140
- def to_s
141
- Megam::Stuff.styled_hash(to_hash)
142
- end
143
-
144
- end
145
- end
@@ -1,152 +0,0 @@
1
- # Copyright:: Copyright (c) 2012, 2014 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 CloudTool < Megam::ServerAPI
18
-
19
- def initialize(email=nil, api_key=nil)
20
- @id = nil
21
- @name = nil
22
- @cli = nil
23
- @cloudtemplates = nil
24
- @some_msg = {}
25
- super(email, api_key)
26
- end
27
-
28
- def cloud_tool
29
- self
30
- end
31
-
32
-
33
- def id(arg=nil)
34
- if arg != nil
35
- @id = arg
36
- else
37
- @id
38
- end
39
- end
40
-
41
- def cli(arg=nil)
42
- if arg != nil
43
- @cli = arg
44
- else
45
- @cli
46
- end
47
- end
48
-
49
- def name(arg=nil)
50
- if arg != nil
51
- @name = arg
52
- else
53
- @name
54
- end
55
- end
56
-
57
- def cloudtemplates(arg=nil)
58
- if arg != nil
59
- @cloudtemplates = arg
60
- else
61
- @cloudtemplates
62
- end
63
- end
64
-
65
- def some_msg(arg=nil)
66
- if arg != nil
67
- @some_msg = arg
68
- else
69
- @some_msg
70
- end
71
- end
72
-
73
- def error?
74
- crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
75
- end
76
-
77
- # Transform the ruby obj -> to a Hash
78
- def to_hash
79
- index_hash = Hash.new
80
- index_hash["json_claz"] = self.class.name
81
- index_hash["id"] = id
82
- index_hash["name"] = name
83
- index_hash["cli"] = cli
84
- index_hash["cloudtemplates"] = cloudtemplates
85
- index_hash["some_msg"] = some_msg
86
- index_hash
87
- end
88
-
89
- # Serialize this object as a hash: called from JsonCompat.
90
- # Verify if this called from JsonCompat during testing.
91
- def to_json(*a)
92
- for_json.to_json(*a)
93
- end
94
-
95
- def for_json
96
- result = {
97
- "id" => id,
98
- "name" => name,
99
- "cli" => cli,
100
- "cloudtemplates" => cloudtemplates
101
- }
102
- result
103
- end
104
-
105
- #
106
- def self.json_create(o)
107
- cloudtool = new
108
- cloudtool.id(o["id"]) if o.has_key?("id")
109
- cloudtool.name(o["name"]) if o.has_key?("name")
110
- cloudtool.cli(o["cli"]) if o.has_key?("cli")
111
- cloudtool.cloudtemplates(o["cloudtemplates"]) if o.has_key?("cloudtemplates")
112
-
113
- #success or error
114
- cloudtool.some_msg[:code] = o["code"] if o.has_key?("code")
115
- cloudtool.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
116
- cloudtool.some_msg[:msg]= o["msg"] if o.has_key?("msg")
117
- cloudtool.some_msg[:links] = o["links"] if o.has_key?("links")
118
- cloudtool
119
- end
120
-
121
- def self.from_hash(o)
122
- cloudtool = self.new()
123
- cloudtool.from_hash(o)
124
- cloudtool
125
- end
126
-
127
- def from_hash(o)
128
- @provider = o[:provider] if o.has_key?(:provider)
129
- self
130
- end
131
-
132
- # Load all cloudtools -
133
- # returns a CloudToolsCollection
134
- def self.list(tmp_email=nil, tmp_api_key=nil)
135
- ct = self.new(tmp_email, tmp_api_key)
136
- ct.megam_rest.get_cloudtools
137
- end
138
-
139
- # Show a particular cloudtool by name,
140
- # Megam::CloudTool
141
- def self.show(p_name,tmp_email=nil, tmp_api_key=nil)
142
- ct = self.new(tmp_email, tmp_api_key)
143
- ct.megam_rest.get_cloudtool(p_name)
144
- self
145
- end
146
-
147
- def to_s
148
- Megam::Stuff.styled_hash(to_hash)
149
- end
150
-
151
- end
152
- end
@@ -1,145 +0,0 @@
1
- # Copyright:: Copyright (c) 2012, 2014 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 CloudToolCollection
18
- include Enumerable
19
-
20
- attr_reader :iterator
21
- def initialize
22
- @cloudtools = Array.new
23
- @cloudtools_by_name = Hash.new
24
- @insert_after_idx = nil
25
- end
26
-
27
- def all_cloudtools
28
- @cloudtools
29
- end
30
-
31
- def [](index)
32
- @cloudtools[index]
33
- end
34
-
35
- def []=(index, arg)
36
- is_megam_cloudtool(arg)
37
- @cloudtools[index] = arg
38
- @cloudtools_by_name[arg.name] = index
39
- end
40
-
41
- def <<(*args)
42
- args.flatten.each do |a|
43
- is_megam_cloudtool(a)
44
- @cloudtools << a
45
- @cloudtools_by_name[a.name] =@cloudtools.length - 1
46
- end
47
- self
48
- end
49
-
50
- # 'push' is an alias method to <<
51
- alias_method :push, :<<
52
-
53
- def insert(cloudtool)
54
- is_megam_cloudtool(cloudtool)
55
- if @insert_after_idx
56
- # in the middle of executing a run, so any predefs inserted now should
57
- # be placed after the most recent addition done by the currently executing
58
- # cloudtools
59
- @cloudtools.insert(@insert_after_idx + 1, cloudtool)
60
- # update name -> location mappings and register new cloudtools
61
- @cloudtools_by_name.each_key do |key|
62
- @cloudtools_by_name[key] += 1 if@cloudtools_by_name[key] > @insert_after_idx
63
- end
64
- @cloudtools_by_name[cloudtool.name] = @insert_after_idx + 1
65
- @insert_after_idx += 1
66
- else
67
- @cloudtools << cloudtool
68
- @cloudtools_by_name[cloudtool.name] =@cloudtools.length - 1
69
- end
70
- end
71
-
72
- def each
73
- @cloudtools.each do |cloudtool|
74
- yield cloudtool
75
- end
76
- end
77
-
78
- def each_index
79
- @cloudtools.each_index do |i|
80
- yield i
81
- end
82
- end
83
-
84
- def empty?
85
- @cloudtools.empty?
86
- end
87
-
88
- def lookup(cloudtool)
89
- lookup_by = nil
90
- if cloudtool.kind_of?(Megam::CloudTool)
91
- lookup_by = cloudtool.name
92
- elsif cloudtool.kind_of?(String)
93
- lookup_by = cloudtool
94
- else
95
- raise ArgumentError, "Must pass a Megam::CloudTools or String to lookup"
96
- end
97
- res =@cloudtools_by_name[lookup_by]
98
- unless res
99
- raise ArgumentError, "Cannot find a cloudtools matching #{lookup_by} (did you define it first?)"
100
- end
101
- @cloudtools[res]
102
- end
103
-
104
- # Transform the ruby obj -> to a Hash
105
- def to_hash
106
- index_hash = Hash.new
107
- self.each do |cloudtool|
108
- index_hash[cloudtool.name] = cloudtool.to_s
109
- end
110
- index_hash
111
- end
112
-
113
- # Serialize this object as a hash: called from JsonCompat.
114
- # Verify if this called from JsonCompat during testing.
115
- def to_json(*a)
116
- for_json.to_json(*a)
117
- end
118
-
119
-
120
- def self.json_create(o)
121
- collection = self.new()
122
- o["results"].each do |cloudtools_list|
123
- cloudtools_array = cloudtools_list.kind_of?(Array) ? cloudtools_list : [ cloudtools_list ]
124
- cloudtools_array.each do |cloudtool|
125
- collection.insert(cloudtool)
126
- end
127
- end
128
- collection
129
- end
130
-
131
- private
132
-
133
- def is_megam_cloudtool(arg)
134
- unless arg.kind_of?(Megam::CloudTool)
135
- raise ArgumentError, "Members must be Megam::CloudTool's"
136
- end
137
- true
138
- end
139
-
140
- def to_s
141
- Megam::Stuff.styled_hash(to_hash)
142
- end
143
-
144
- end
145
- end