virtengine_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE +21 -0
  6. data/README.md +27 -0
  7. data/Rakefile +10 -0
  8. data/lib/megam/api.rb +329 -0
  9. data/lib/megam/api/accounts.rb +96 -0
  10. data/lib/megam/api/addons.rb +27 -0
  11. data/lib/megam/api/assemblies.rb +49 -0
  12. data/lib/megam/api/assembly.rb +56 -0
  13. data/lib/megam/api/backups.rb +57 -0
  14. data/lib/megam/api/balances.rb +45 -0
  15. data/lib/megam/api/billedhistories.rb +35 -0
  16. data/lib/megam/api/billingtransactions.rb +25 -0
  17. data/lib/megam/api/components.rb +24 -0
  18. data/lib/megam/api/credits.rb +34 -0
  19. data/lib/megam/api/disks.rb +44 -0
  20. data/lib/megam/api/domains.rb +25 -0
  21. data/lib/megam/api/errors.rb +29 -0
  22. data/lib/megam/api/eventsall.rb +36 -0
  23. data/lib/megam/api/eventsbilling.rb +35 -0
  24. data/lib/megam/api/eventscontainer.rb +35 -0
  25. data/lib/megam/api/eventsmarketplace.rb +35 -0
  26. data/lib/megam/api/eventsstorage.rb +24 -0
  27. data/lib/megam/api/eventsvm.rb +35 -0
  28. data/lib/megam/api/flavors.rb +56 -0
  29. data/lib/megam/api/license.rb +26 -0
  30. data/lib/megam/api/marketplaces.rb +68 -0
  31. data/lib/megam/api/organizations.rb +50 -0
  32. data/lib/megam/api/promos.rb +18 -0
  33. data/lib/megam/api/quotas.rb +47 -0
  34. data/lib/megam/api/rawimages.rb +36 -0
  35. data/lib/megam/api/reports.rb +24 -0
  36. data/lib/megam/api/requests.rb +36 -0
  37. data/lib/megam/api/sensors.rb +35 -0
  38. data/lib/megam/api/snapshots.rb +46 -0
  39. data/lib/megam/api/sshkeys.rb +35 -0
  40. data/lib/megam/api/subscriptions.rb +26 -0
  41. data/lib/megam/api/version.rb +6 -0
  42. data/lib/megam/core/account.rb +245 -0
  43. data/lib/megam/core/account_collection.rb +122 -0
  44. data/lib/megam/core/addons.rb +169 -0
  45. data/lib/megam/core/addons_collection.rb +121 -0
  46. data/lib/megam/core/assemblies.rb +191 -0
  47. data/lib/megam/core/assemblies_collection.rb +122 -0
  48. data/lib/megam/core/assembly.rb +226 -0
  49. data/lib/megam/core/assembly_collection.rb +122 -0
  50. data/lib/megam/core/backups.rb +259 -0
  51. data/lib/megam/core/backups_collection.rb +122 -0
  52. data/lib/megam/core/balances.rb +187 -0
  53. data/lib/megam/core/balances_collection.rb +121 -0
  54. data/lib/megam/core/billedhistories.rb +190 -0
  55. data/lib/megam/core/billedhistories_collection.rb +121 -0
  56. data/lib/megam/core/billingtransactions.rb +214 -0
  57. data/lib/megam/core/billingtransactions_collection.rb +122 -0
  58. data/lib/megam/core/components.rb +326 -0
  59. data/lib/megam/core/components_collection.rb +123 -0
  60. data/lib/megam/core/credits.rb +146 -0
  61. data/lib/megam/core/credits_collection.rb +121 -0
  62. data/lib/megam/core/disks.rb +199 -0
  63. data/lib/megam/core/disks_collection.rb +122 -0
  64. data/lib/megam/core/domain_collection.rb +122 -0
  65. data/lib/megam/core/domains.rb +118 -0
  66. data/lib/megam/core/error.rb +70 -0
  67. data/lib/megam/core/eventsall.rb +186 -0
  68. data/lib/megam/core/eventsall_collection.rb +122 -0
  69. data/lib/megam/core/eventsbilling.rb +174 -0
  70. data/lib/megam/core/eventsbilling_collection.rb +122 -0
  71. data/lib/megam/core/eventscontainer.rb +187 -0
  72. data/lib/megam/core/eventscontainer_collection.rb +122 -0
  73. data/lib/megam/core/eventsmarketplace.rb +187 -0
  74. data/lib/megam/core/eventsmarketplace_collection.rb +122 -0
  75. data/lib/megam/core/eventsstorage.rb +156 -0
  76. data/lib/megam/core/eventsstorage_collection.rb +122 -0
  77. data/lib/megam/core/eventsvm.rb +187 -0
  78. data/lib/megam/core/eventsvm_collection.rb +122 -0
  79. data/lib/megam/core/flavors.rb +294 -0
  80. data/lib/megam/core/flavors_collection.rb +121 -0
  81. data/lib/megam/core/json_compat.rb +289 -0
  82. data/lib/megam/core/konipai.rb +42 -0
  83. data/lib/megam/core/license.rb +101 -0
  84. data/lib/megam/core/license_collection.rb +122 -0
  85. data/lib/megam/core/log.rb +19 -0
  86. data/lib/megam/core/marketplace.rb +308 -0
  87. data/lib/megam/core/marketplace_collection.rb +123 -0
  88. data/lib/megam/core/monologger.rb +89 -0
  89. data/lib/megam/core/organizations.rb +142 -0
  90. data/lib/megam/core/organizations_collection.rb +121 -0
  91. data/lib/megam/core/promos.rb +145 -0
  92. data/lib/megam/core/quotas.rb +215 -0
  93. data/lib/megam/core/quotas_collection.rb +121 -0
  94. data/lib/megam/core/rawimages.rb +194 -0
  95. data/lib/megam/core/rawimages_collection.rb +121 -0
  96. data/lib/megam/core/reports.rb +176 -0
  97. data/lib/megam/core/reports_collection.rb +121 -0
  98. data/lib/megam/core/request.rb +197 -0
  99. data/lib/megam/core/request_collection.rb +121 -0
  100. data/lib/megam/core/rest_adapter.rb +44 -0
  101. data/lib/megam/core/sensors.rb +141 -0
  102. data/lib/megam/core/sensors_collection.rb +121 -0
  103. data/lib/megam/core/snapshots.rb +268 -0
  104. data/lib/megam/core/snapshots_collection.rb +122 -0
  105. data/lib/megam/core/sshkey.rb +173 -0
  106. data/lib/megam/core/sshkey_collection.rb +122 -0
  107. data/lib/megam/core/stuff.rb +22 -0
  108. data/lib/megam/core/subscriptions.rb +167 -0
  109. data/lib/megam/core/subscriptions_collection.rb +121 -0
  110. data/lib/megam/core/text.rb +87 -0
  111. data/lib/megam/core/text_formatter.rb +64 -0
  112. data/lib/megam/mixins/assemblies.rb +16 -0
  113. data/lib/megam/mixins/assembly.rb +59 -0
  114. data/lib/megam/mixins/common_deployable.rb +78 -0
  115. data/lib/megam/mixins/components.rb +182 -0
  116. data/lib/megam/mixins/megam_attributes.rb +30 -0
  117. data/lib/megam/mixins/outputs.rb +23 -0
  118. data/lib/megam/mixins/policies.rb +27 -0
  119. data/lib/megam_api.rb +1 -0
  120. data/megam_api.gemspec +26 -0
  121. data/test/mixins/test_assemblies.rb +113 -0
  122. data/test/mixins/test_assembly.rb +74 -0
  123. data/test/mixins/test_component.rb +19 -0
  124. data/test/test_accounts.rb +127 -0
  125. data/test/test_addons.rb +26 -0
  126. data/test/test_assemblies.rb +88 -0
  127. data/test/test_assembly.rb +37 -0
  128. data/test/test_backups.rb +29 -0
  129. data/test/test_balances.rb +38 -0
  130. data/test/test_billedhistories.rb +30 -0
  131. data/test/test_billingtranscations.rb +35 -0
  132. data/test/test_components.rb +42 -0
  133. data/test/test_credits.rb +28 -0
  134. data/test/test_disks.rb +25 -0
  135. data/test/test_domains.rb +29 -0
  136. data/test/test_eventsbilling.rb +30 -0
  137. data/test/test_eventscontainer.rb +26 -0
  138. data/test/test_eventsstorage.rb +12 -0
  139. data/test/test_eventsvm.rb +26 -0
  140. data/test/test_helper.rb +77 -0
  141. data/test/test_marketplaces.rb +38 -0
  142. data/test/test_organizations.rb +45 -0
  143. data/test/test_promos.rb +11 -0
  144. data/test/test_quotas.rb +33 -0
  145. data/test/test_reports.rb +32 -0
  146. data/test/test_requests.rb +95 -0
  147. data/test/test_sensors.rb +50 -0
  148. data/test/test_snapshots.rb +30 -0
  149. data/test/test_sshkeys.rb +50 -0
  150. data/test/test_subscriptions.rb +22 -0
  151. metadata +325 -0
@@ -0,0 +1,194 @@
1
+ module Megam
2
+ class Rawimages < Megam::RestAdapter
3
+ def initialize(o)
4
+ @id = nil
5
+ @account_id = nil
6
+ @name = nil
7
+ @repos = nil
8
+ @status = nil
9
+ @inputs = []
10
+ @created_at = nil
11
+ @updated_at = nil
12
+ @org_id = nil
13
+ super(o)
14
+ end
15
+
16
+ def rawimages
17
+ self
18
+ end
19
+
20
+ def id(arg = nil)
21
+ if !arg.nil?
22
+ @id = arg
23
+ else
24
+ @id
25
+ end
26
+ end
27
+
28
+ def name(arg = nil)
29
+ if !arg.nil?
30
+ @name = arg
31
+ else
32
+ @name
33
+ end
34
+ end
35
+
36
+ def account_id(arg=nil)
37
+ if arg != nil
38
+ @account_id = arg
39
+ else
40
+ @account_id
41
+ end
42
+ end
43
+
44
+ def repos(arg = nil)
45
+ if !arg.nil?
46
+ @repos = arg
47
+ else
48
+ @repos
49
+ end
50
+ end
51
+
52
+ def inputs(arg = [])
53
+ if arg != []
54
+ @inputs = arg
55
+ else
56
+ @inputs
57
+ end
58
+ end
59
+
60
+ def status(arg = nil)
61
+ if !arg.nil?
62
+ @status = arg
63
+ else
64
+ @status
65
+ end
66
+ end
67
+
68
+ def created_at(arg = nil)
69
+ if !arg.nil?
70
+ @created_at = arg
71
+ else
72
+ @created_at
73
+ end
74
+ end
75
+
76
+ def updated_at(arg = nil)
77
+ if !arg.nil?
78
+ @updated_at = arg
79
+ else
80
+ @updated_at
81
+ end
82
+ end
83
+
84
+ def org_id(arg = nil)
85
+ if !arg.nil?
86
+ @org_id = arg
87
+ else
88
+ @org_id
89
+ end
90
+ end
91
+
92
+ def error?
93
+ crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error'
94
+ end
95
+
96
+ # Transform the ruby obj -> to a Hash
97
+ def to_hash
98
+ index_hash = {}
99
+ index_hash['json_claz'] = self.class.name
100
+ index_hash['id'] = id
101
+ index_hash['org_id'] = org_id
102
+ index_hash["account_id"] = account_id
103
+ index_hash['name'] = name
104
+ index_hash['repos'] = repos
105
+ index_hash['status'] = status
106
+ index_hash['inputs'] = inputs
107
+ index_hash['created_at'] = created_at
108
+ index_hash['updated_at'] = updated_at
109
+ index_hash
110
+ end
111
+
112
+ # Serialize this object as a hash: called from JsonCompat.
113
+ # Verify if this called from JsonCompat during testing.
114
+ def to_json(*a)
115
+ for_json.to_json(*a)
116
+ end
117
+
118
+ def for_json
119
+ result = {
120
+ 'id' => id,
121
+ 'account_id' => account_id,
122
+ 'name' => name,
123
+ 'org_id' => org_id,
124
+ 'repos' => repos,
125
+ 'inputs' => inputs,
126
+ 'status' => status,
127
+ 'created_at' => created_at,
128
+ 'updated_at' => updated_at
129
+ }
130
+
131
+ result
132
+ end
133
+
134
+ def self.json_create(o)
135
+ quo = new({})
136
+ quo.id(o['id']) if o.key?('id')
137
+ quo.org_id(o['org_id']) if o.key?('org_id')
138
+ quo.account_id(o["account_id"]) if o.has_key?("account_id")
139
+ quo.name(o['name']) if o.key?('name')
140
+ quo.repos(o['repos']) if o.key?('repos')
141
+ quo.inputs(o['inputs']) if o.key?('inputs')
142
+ quo.status(o['status']) if o.key?('status')
143
+ quo.created_at(o['created_at']) if o.key?('created_at')
144
+ quo.updated_at(o['updated_at']) if o.key?('updated_at')
145
+ quo
146
+ end
147
+
148
+ def self.from_hash(o)
149
+ quo = new(o)
150
+ quo.from_hash(o)
151
+ quo
152
+ end
153
+
154
+ def from_hash(o)
155
+ @id = o['id'] if o.key?('id')
156
+ @org_id = o['org_id'] if o.key?('org_id')
157
+ @account_id = o["account_id"] if o.has_key?("account_id")
158
+ @name = o['name'] if o.key?('name')
159
+ @region = o['region'] if o.key?('region')
160
+ @repos = o['repos'] if o.key?('repos')
161
+ @inputs = o['inputs'] if o.key?('inputs')
162
+ @status = o['status'] if o.key?('status')
163
+ @created_at = o['created_at'] if o.key?('created_at')
164
+ @updated_at = o['updated_at'] if o.key?('updated_at')
165
+ self
166
+ end
167
+
168
+
169
+ def self.show(params)
170
+ quo = new(params)
171
+ quo.megam_rest.get_one_rawimage(params['id'])
172
+ end
173
+
174
+ def self.list(params)
175
+ quo = self.new(params)
176
+ quo.megam_rest.list_rawimages
177
+ end
178
+
179
+ def self.create(params)
180
+ quo = from_hash(params)
181
+ quo.create
182
+ end
183
+
184
+ def create
185
+ megam_rest.post_rawimages(to_hash)
186
+ end
187
+
188
+ # Create the node via the REST API
189
+
190
+ def to_s
191
+ Megam::Stuff.styled_hash(to_hash)
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,121 @@
1
+ module Megam
2
+ class RawimagesCollection
3
+ include Enumerable
4
+
5
+ attr_reader :iterator
6
+ def initialize
7
+ @rawimages = Array.new
8
+ @rawimages_by_name = Hash.new
9
+ @insert_after_idx = nil
10
+ end
11
+
12
+ def all_rawimages
13
+ @rawimages
14
+ end
15
+
16
+ def [](index)
17
+ @rawimages[index]
18
+ end
19
+
20
+ def []=(index, arg)
21
+ is_megam_rawimages(arg)
22
+ @rawimages[index] = arg
23
+ @rawimages_by_name[arg.id] = index
24
+ end
25
+
26
+ def <<(*args)
27
+ args.flatten.each do |a|
28
+ is_megam_rawimages(a)
29
+ @rawimages << a
30
+ @rawimages_by_name[a.id] = @rawimages.length - 1
31
+ end
32
+ self
33
+ end
34
+
35
+ # 'push' is an alias method to <<
36
+ alias_method :push, :<<
37
+
38
+ def insert(rawimages)
39
+ is_megam_rawimages(rawimages)
40
+ if @insert_after_idx
41
+ # in the middle of executing a run, so any nodes inserted now should
42
+ # be placed after the most recent addition done by the currently executing
43
+ # node
44
+ @rawimages.insert(@insert_after_idx + 1, rawimages)
45
+ # update name -> location mappings and register new node
46
+ @rawimages_by_name.each_key do |key|
47
+ @rawimages_by_name[key] += 1 if @rawimages_by_name[key] > @insert_after_idx
48
+ end
49
+ @rawimages_by_name[rawimages.id] = @insert_after_idx + 1
50
+ @insert_after_idx += 1
51
+ else
52
+ @rawimages << rawimages
53
+ @rawimages_by_name[rawimages.id] = @rawimages.length - 1
54
+ end
55
+ end
56
+
57
+ def each
58
+ @rawimages.each do |rawimages|
59
+ yield rawimages
60
+ end
61
+ end
62
+
63
+ def each_index
64
+ @rawimages.each_index do |i|
65
+ yield i
66
+ end
67
+ end
68
+
69
+ def empty?
70
+ @rawimages.empty?
71
+ end
72
+
73
+ def lookup(rawimages)
74
+ lookup_by = nil
75
+ if rawimages.kind_of?(Megam::Rawimages)
76
+ lookup_by = rawimages.id
77
+ elsif rawimages.kind_of?(String)
78
+ lookup_by = rawimages
79
+ else
80
+ raise ArgumentError, "Must pass a Megam::Rawimages or String to lookup"
81
+ end
82
+ res = @rawimages_by_name[lookup_by]
83
+ unless res
84
+ raise ArgumentError, "Cannot find a node matching #{lookup_by} (did you define it first?)"
85
+ end
86
+ @rawimages[res]
87
+ end
88
+
89
+ def to_s
90
+ @rawimages.join(", ")
91
+ end
92
+
93
+ def for_json
94
+ to_a.map { |item| item.to_s }
95
+ end
96
+
97
+ def to_json(*a)
98
+ Megam::JSONCompat.to_json(for_json, *a)
99
+ end
100
+
101
+ def self.json_create(o)
102
+ collection = self.new()
103
+ o["results"].each do |rawimages_list|
104
+ rawimages_array = rawimages_list.kind_of?(Array) ? rawimages_list : [ rawimages_list ]
105
+ rawimages_array.each do |rawimages|
106
+ collection.insert(rawimages)
107
+ end
108
+ end
109
+ collection
110
+ end
111
+
112
+ private
113
+
114
+ def is_megam_rawimages(arg)
115
+ unless arg.kind_of?(Megam::Rawimages)
116
+ raise ArgumentError, "Members must be Megam::Rawimages's"
117
+ end
118
+ true
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,176 @@
1
+ module Megam
2
+ class Reports < Megam::RestAdapter
3
+
4
+ def initialize(o)
5
+ @id = nil
6
+ @start_date = nil
7
+ @end_date = nil
8
+ @type_of = nil
9
+ @data = []
10
+ @category = nil
11
+ @group = nil
12
+ @created_at = nil
13
+ @some_msg = {}
14
+ super(o)
15
+ end
16
+
17
+ def reports
18
+ self
19
+ end
20
+
21
+ def id(arg=nil)
22
+ if arg != nil
23
+ @id = arg
24
+ else
25
+ @id
26
+ end
27
+ end
28
+
29
+ def start_date(arg=nil)
30
+ if arg != nil
31
+ @start_date = arg
32
+ else
33
+ @start_date
34
+ end
35
+ end
36
+
37
+ def end_date(arg=nil)
38
+ if arg != nil
39
+ @end_date = arg
40
+ else
41
+ @end_date
42
+ end
43
+ end
44
+
45
+ def type_of(arg=nil)
46
+ if arg != nil
47
+ @type_of = arg
48
+ else
49
+ @type_of
50
+ end
51
+ end
52
+
53
+ def data(arg = [])
54
+ if arg != []
55
+ @data = arg
56
+ else
57
+ @data
58
+ end
59
+ end
60
+
61
+ def category(arg=nil)
62
+ if arg !=nil
63
+ @category = arg
64
+ else
65
+ @category
66
+ end
67
+ end
68
+
69
+ def group(arg=nil)
70
+ if arg !=nil
71
+ @group = arg
72
+ else
73
+ @group
74
+ end
75
+ end
76
+
77
+ def created_at(arg=nil)
78
+ if arg != nil
79
+ @created_date = arg
80
+ else
81
+ @created_date
82
+ end
83
+ end
84
+
85
+ def some_msg(arg=nil)
86
+ if arg != nil
87
+ @some_msg = arg
88
+ else
89
+ @some_msg
90
+ end
91
+ end
92
+
93
+ def error?
94
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
95
+ end
96
+
97
+ def to_hash
98
+ index_hash = Hash.new
99
+ index_hash["start_date"] = start_date
100
+ index_hash["end_date"] = end_date
101
+ index_hash["type_of"] = type_of
102
+ index_hash["category"] = category
103
+ index_hash["group"] = group
104
+ index_hash
105
+ end
106
+
107
+ def to_json(*a)
108
+ for_json.to_json(*a)
109
+ end
110
+
111
+ def for_json
112
+ result = {
113
+ "id" => id,
114
+ "start_date" => start_date,
115
+ "end_date" => end_date,
116
+ "type_of" => type_of,
117
+ "data" => data,
118
+ "category" => category,
119
+ "group" => group,
120
+ "created_at" => created_at
121
+ }
122
+ result
123
+ end
124
+
125
+ def self.json_create(o)
126
+ sps = new({})
127
+ sps.id(o["id"]) if o.has_key?("id")
128
+ sps.start_date(o["start_date"]) if o.has_key?("start_date")
129
+ sps.end_date(o["end_date"]) if o.has_key?("end_date")
130
+ sps.type_of(o["type_of"]) if o.has_key?("type_of")
131
+ sps.data(o["data"]) if o.has_key?("data")
132
+ sps.category(o["category"]) if o.has_key?("category")
133
+ sps.group(o["group"]) if o.has_key?("group")
134
+ sps.created_at(o["created_at"]) if o.has_key?("created_at")
135
+ sps
136
+ end
137
+
138
+ def self.from_hash(o)
139
+ sps = self.new(o)
140
+ sps.from_hash(o)
141
+ sps
142
+ end
143
+
144
+ def from_hash(o)
145
+ @start_date = o[:start_date] if o.has_key?(:start_date)
146
+ @end_date = o[:end_date] if o.has_key?(:end_date)
147
+ @type_of = o[:type_of] if o.has_key?(:type_of)
148
+ @category = o[:category] if o.has_key?(:category)
149
+ @group = o[:group] if o.has_key?(:group)
150
+ self
151
+ end
152
+
153
+ def self.create(params)
154
+ sps = from_hash(params)
155
+ sps.create
156
+ end
157
+
158
+ def self.show(params)
159
+ sps = from_hash(params)
160
+ sps.show
161
+ end
162
+
163
+ def create
164
+ megam_rest.post_reports(to_hash)
165
+ end
166
+
167
+ def show
168
+ megam_rest.get_reports(to_hash)
169
+ end
170
+
171
+ def to_s
172
+ Megam::Stuff.styled_hash(to_hash)
173
+ end
174
+
175
+ end
176
+ end