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.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.project +17 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +5 -0
  6. data/README.md +83 -0
  7. data/Rakefile +10 -0
  8. data/lib/certs/cacert.pem +3554 -0
  9. data/lib/megam/api.rb +244 -0
  10. data/lib/megam/api/accounts.rb +29 -0
  11. data/lib/megam/api/appdefns.rb +26 -0
  12. data/lib/megam/api/appreqs.rb +27 -0
  13. data/lib/megam/api/boltdefns.rb +27 -0
  14. data/lib/megam/api/boltreqs.rb +27 -0
  15. data/lib/megam/api/cloud_tools.rb +35 -0
  16. data/lib/megam/api/errors.rb +27 -0
  17. data/lib/megam/api/login.rb +14 -0
  18. data/lib/megam/api/logs.rb +18 -0
  19. data/lib/megam/api/nodes.rb +50 -0
  20. data/lib/megam/api/predef_clouds.rb +35 -0
  21. data/lib/megam/api/predefs.rb +35 -0
  22. data/lib/megam/api/requests.rb +37 -0
  23. data/lib/megam/api/version.rb +5 -0
  24. data/lib/megam/core/account.rb +170 -0
  25. data/lib/megam/core/appdefns.rb +192 -0
  26. data/lib/megam/core/appdefns_collection.rb +148 -0
  27. data/lib/megam/core/appreqs.rb +224 -0
  28. data/lib/megam/core/appreqs_collection.rb +148 -0
  29. data/lib/megam/core/auth.rb +91 -0
  30. data/lib/megam/core/boltdefns.rb +198 -0
  31. data/lib/megam/core/boltdefns_collection.rb +148 -0
  32. data/lib/megam/core/boltreqs.rb +224 -0
  33. data/lib/megam/core/boltreqs_collection.rb +148 -0
  34. data/lib/megam/core/cloudinstruction.rb +110 -0
  35. data/lib/megam/core/cloudinstruction_collection.rb +145 -0
  36. data/lib/megam/core/cloudinstruction_group.rb +99 -0
  37. data/lib/megam/core/cloudtemplate.rb +127 -0
  38. data/lib/megam/core/cloudtemplate_collection.rb +145 -0
  39. data/lib/megam/core/cloudtool.rb +153 -0
  40. data/lib/megam/core/cloudtool_collection.rb +145 -0
  41. data/lib/megam/core/config.rb +44 -0
  42. data/lib/megam/core/error.rb +99 -0
  43. data/lib/megam/core/json_compat.rb +183 -0
  44. data/lib/megam/core/log.rb +33 -0
  45. data/lib/megam/core/node.rb +347 -0
  46. data/lib/megam/core/node_collection.rb +166 -0
  47. data/lib/megam/core/predef.rb +208 -0
  48. data/lib/megam/core/predef_collection.rb +164 -0
  49. data/lib/megam/core/predefcloud.rb +229 -0
  50. data/lib/megam/core/predefcloud_collection.rb +168 -0
  51. data/lib/megam/core/request.rb +187 -0
  52. data/lib/megam/core/request_collection.rb +145 -0
  53. data/lib/megam/core/stuff.rb +69 -0
  54. data/lib/megam/core/text.rb +88 -0
  55. data/lib/megam_api.rb +1 -0
  56. data/megam_api.gemspec +26 -0
  57. data/test/test_accounts.rb +46 -0
  58. data/test/test_appdefns.rb +23 -0
  59. data/test/test_appreqs.rb +28 -0
  60. data/test/test_boltdefns.rb +23 -0
  61. data/test/test_boltreqs.rb +28 -0
  62. data/test/test_cloudtools.rb +22 -0
  63. data/test/test_helper.rb +67 -0
  64. data/test/test_login.rb +12 -0
  65. data/test/test_logs.rb +15 -0
  66. data/test/test_nodes.rb +141 -0
  67. data/test/test_predefclouds.rb +67 -0
  68. data/test/test_predefs.rb +72 -0
  69. data/test/test_requests.rb +85 -0
  70. metadata +213 -0
@@ -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 BoltreqsCollection
18
+ include Enumerable
19
+
20
+
21
+ attr_reader :iterator
22
+ def initialize
23
+ @boltreqs = Array.new
24
+ @boltreqs_by_name = Hash.new
25
+ @insert_after_idx = nil
26
+ end
27
+
28
+ def all_boltreqs
29
+ @boltreqs
30
+ end
31
+
32
+ def [](index)
33
+ @boltreqs[index]
34
+ end
35
+
36
+ def []=(index, arg)
37
+ is_megam_boltreq(arg)
38
+ @boltreqs[index] = arg
39
+ @boltreqs_by_name[arg.id] = index
40
+ end
41
+
42
+ def <<(*args)
43
+ args.flatten.each do |a|
44
+ is_megam_boltreq(a)
45
+ @boltreqs << a
46
+ @boltreqs_by_name[a.id] = @boltreqs.length - 1
47
+ end
48
+ self
49
+ end
50
+
51
+ # 'push' is an alias method to <<
52
+ alias_method :push, :<<
53
+
54
+ def insert(boltreq)
55
+ is_megam_boltreq(boltreq)
56
+ if @insert_after_idx
57
+ # in the middle of executing a run, so any boltreqss inserted now should
58
+ # be placed after the most recent addition done by the currently executing
59
+ # boltreqs
60
+ @boltreqs.insert(@insert_after_idx + 1, boltreq)
61
+ # update name -> location mboltings and register new boltreqs
62
+ @boltreqs_by_name.each_key do |key|
63
+ @boltreqs_by_name[key] += 1 if @boltreqs_by_name[key] > @insert_after_idx
64
+ end
65
+ @boltreqs_by_name[boltreq.id] = @insert_after_idx + 1
66
+ @insert_after_idx += 1
67
+ else
68
+ @boltreqs << boltreq
69
+ @boltreqs_by_name[boltreq.id] = @boltreqs.length - 1
70
+ end
71
+ end
72
+
73
+ def each
74
+ @boltreqs.each do |boltreq|
75
+ yield boltreq
76
+ end
77
+ end
78
+
79
+ def each_index
80
+ @boltreqs.each_index do |i|
81
+ yield i
82
+ end
83
+ end
84
+
85
+ def empty?
86
+ @boltreqs.empty?
87
+ end
88
+
89
+ def lookup(boltreq)
90
+ lookup_by = nil
91
+ if boltreq.kind_of?(Megam::Boltreqs)
92
+ lookup_by = boltreq.id
93
+ elsif boltreq.kind_of?(String)
94
+ lookup_by = boltreq
95
+ else
96
+ raise ArgumentError, "Must pass a Megam::Boltreqs or String to lookup"
97
+ end
98
+ res = @boltreqs_by_name[lookup_by]
99
+ unless res
100
+ raise ArgumentError, "Cannot find a boltreq matching #{lookup_by} (did you define it first?)"
101
+ end
102
+ @boltreqs[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 |boltreq|
109
+ index_hash[boltreq.id] = boltreq.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 |boltreqs_list|
124
+ boltreqs_array = boltreqs_list.kind_of?(Array) ? boltreqs_list : [ boltreqs_list ]
125
+ boltreqs_array.each do |boltreq|
126
+ collection.insert(boltreq)
127
+ end
128
+ end
129
+ collection
130
+ end
131
+
132
+ private
133
+
134
+
135
+
136
+ def is_megam_boltreq(arg)
137
+ unless arg.kind_of?(Megam::Boltreqs)
138
+ raise ArgumentError, "Members must be Megam::Boltreq'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,110 @@
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 CloudInstruction
18
+ def initialize
19
+ @action = nil
20
+ @command = nil
21
+ @name = nil
22
+ end
23
+
24
+ def cloud_instruction
25
+ self
26
+ end
27
+
28
+
29
+ def action(arg=nil)
30
+ if arg != nil
31
+ @action = arg
32
+ else
33
+ @action
34
+ end
35
+ end
36
+
37
+ def command(arg=nil)
38
+ if arg != nil
39
+ @command = arg
40
+ else
41
+ @command
42
+ end
43
+ end
44
+
45
+ def name(arg=nil)
46
+ if arg != nil
47
+ @name = arg
48
+ else
49
+ @name
50
+ end
51
+ end
52
+
53
+ def error?
54
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
55
+ end
56
+
57
+ # Transform the ruby obj -> to a Hash
58
+ def to_hash
59
+ index_hash = Hash.new
60
+ index_hash["json_claz"] = self.class.name
61
+ index_hash["action"] = action
62
+ index_hash["command"] = command
63
+ index_hash["name"] = name
64
+ index_hash
65
+ end
66
+
67
+ # Serialize this object as a hash: called from JsonCompat.
68
+ # Verify if this called from JsonCompat during testing.
69
+ def to_json(*a)
70
+ for_json.to_json(*a)
71
+ end
72
+
73
+ def for_json
74
+ result = {
75
+ "action" => action,
76
+ "command" => command,
77
+ "name" => name
78
+ }
79
+ result
80
+ end
81
+
82
+ #
83
+ def self.json_create(o)
84
+ cloudinstruction = new
85
+ cloudinstruction.action(o["action"]) if o.has_key?("action")
86
+ cloudinstruction.command(o["command"]) if o.has_key?("command")
87
+ cloudinstruction.name(o["name"]) if o.has_key?("name")
88
+ cloudinstruction
89
+ end
90
+
91
+ def self.from_hash(o)
92
+ cloudinstruction = self.new()
93
+ cloudinstruction.from_hash(o)
94
+ cloudinstruction
95
+ end
96
+
97
+ def from_hash(o)
98
+ @action = o[:action] if o.has_key?(:action)
99
+ @command = o[:command] if o.has_key?(:command)
100
+ @name = o[:name] if o.has_key?(:name)
101
+ self
102
+ end
103
+
104
+
105
+ def to_s
106
+ Megam::Stuff.styled_hash(to_hash)
107
+ end
108
+
109
+ end
110
+ end
@@ -0,0 +1,145 @@
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 CloudInstructionCollection
18
+ include Enumerable
19
+
20
+ attr_reader :iterator
21
+ def initialize
22
+ @cloudinstructions = Array.new
23
+ @cloudinstructions_by_name = Hash.new
24
+ @insert_after_idx = nil
25
+ end
26
+
27
+ def all_cloudinstructions
28
+ @cloudinstructions
29
+ end
30
+
31
+ def [](index)
32
+ @cloudinstructions[index]
33
+ end
34
+
35
+ def []=(index, arg)
36
+ is_megam_cloudinstruction(arg)
37
+ @cloudinstructions[index] = arg
38
+ @cloudinstructions_by_name[arg.action] = index
39
+ end
40
+
41
+ def <<(*args)
42
+ args.flatten.each do |a|
43
+ is_megam_cloudinstruction(a)
44
+ @cloudinstructions << a
45
+ @cloudinstructions_by_name[a.action] =@cloudinstructions.length - 1
46
+ end
47
+ self
48
+ end
49
+
50
+ # 'push' is an alias method to <<
51
+ alias_method :push, :<<
52
+
53
+ def insert(cloudinstruction)
54
+ is_megam_cloudinstruction(cloudinstruction)
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
+ # cloudinstructions
59
+ @cloudinstructions.insert(@insert_after_idx + 1, cloudinstruction)
60
+ # update name -> location mappings and register new cloudinstructions
61
+ @cloudinstructions_by_name.each_key do |key|
62
+ @cloudinstructions_by_name[key] += 1 if@cloudinstructions_by_name[key] > @insert_after_idx
63
+ end
64
+ @cloudinstructions_by_name[cloudinstruction.action] = @insert_after_idx + 1
65
+ @insert_after_idx += 1
66
+ else
67
+ @cloudinstructions << cloudinstruction
68
+ @cloudinstructions_by_name[cloudinstruction.action] =@cloudinstructions.length - 1
69
+ end
70
+ end
71
+
72
+ def each
73
+ @cloudinstructions.each do |cloudinstruction|
74
+ yield cloudinstruction
75
+ end
76
+ end
77
+
78
+ def each_index
79
+ @cloudinstructions.each_index do |i|
80
+ yield i
81
+ end
82
+ end
83
+
84
+ def empty?
85
+ @cloudinstructions.empty?
86
+ end
87
+
88
+ def lookup(cloudinstruction)
89
+ lookup_by = nil
90
+ if cloudinstruction.kind_of?(Megam::CloudInstruction)
91
+ lookup_by = cloudinstruction.action
92
+ elsif cloudinstruction.kind_of?(String)
93
+ lookup_by = cloudinstruction
94
+ else
95
+ raise ArgumentError, "Must pass a Megam::CloudInstruction or String to lookup"
96
+ end
97
+ res =@cloudinstructions_by_name[lookup_by]
98
+ unless res
99
+ raise ArgumentError, "Cannot find a cloudinstruction matching #{lookup_by} (did you define it first?)"
100
+ end
101
+ @cloudinstructions[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 |cloudinstruction|
108
+ index_hash[cloudinstruction.action] = cloudinstruction
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 |cloudinstructions_list|
123
+ cloudinstructions_array = cloudinstructions_list.kind_of?(Array) ? cloudinstructions_list : [ cloudinstructions_list ]
124
+ cloudinstructions_array.each do |cloudinstruction|
125
+ collection.insert(cloudinstruction)
126
+ end
127
+ end
128
+ collection
129
+ end
130
+
131
+ private
132
+
133
+ def is_megam_cloudinstruction(arg)
134
+ unless arg.kind_of?(Megam::CloudInstruction)
135
+ raise ArgumentError, "Members must be Megam::CloudInstruction'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
@@ -0,0 +1,99 @@
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 CloudInstructionGroup
18
+ def initialize
19
+ @group = nil
20
+ @cloud_instructions_array = nil
21
+ end
22
+
23
+ def cloudinstruction_group
24
+ self
25
+ end
26
+
27
+ def group(arg=nil)
28
+ if arg != nil
29
+ @group = arg
30
+ else
31
+ @group
32
+ end
33
+ end
34
+
35
+ def cloud_instructions_array(arg=nil)
36
+ if arg != nil
37
+ @cloud_instructions_array = arg
38
+ else
39
+ @cloud_instructions_array
40
+ end
41
+ end
42
+
43
+
44
+ def error?
45
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
46
+ end
47
+
48
+
49
+
50
+ # Transform the ruby obj -> to a Hash
51
+ def to_hash
52
+ index_hash = Hash.new
53
+ index_hash["json_claz"] = self.class.name
54
+ index_hash["group"] = group
55
+ cloud_instructions_array.each do |single_cig|
56
+ index_hash[""] = single_cig
57
+ end
58
+ index_hash
59
+ end
60
+
61
+ # Serialize this object as a hash: called from JsonCompat.
62
+ # Verify if this called from JsonCompat during testing.
63
+ def to_json(*a)
64
+ for_json.to_json(*a)
65
+ end
66
+
67
+ def for_json
68
+ result = {
69
+ "group" => group
70
+ }
71
+ result
72
+ end
73
+
74
+ #
75
+ def self.json_create(o)
76
+ cloudinstruction_group = new
77
+ cloudinstruction_group.group(o["group"]) if o.has_key?("group")
78
+ cloudinstruction_group.cloud_instructions_array(o["results"]) if o.has_key?("results")
79
+ cloudinstruction_group
80
+ end
81
+
82
+ def self.from_hash(o)
83
+ cloudinstruction_group = self.new()
84
+ cloudinstruction_group.from_hash(o)
85
+ cloudinstruction_group
86
+ end
87
+
88
+ def from_hash(o)
89
+ @group = o[:group] if o.has_key?(:group)
90
+ @cloudinstructions = o[:cloud_instructions_array] if o.has_key?(:cloud_instructions_array)
91
+ self
92
+ end
93
+
94
+ def to_s
95
+ Megam::Stuff.styled_hash(to_hash)
96
+ end
97
+
98
+ end
99
+ end