virtengine_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 (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,36 @@
1
+ module Megam
2
+ class API
3
+
4
+ def get_one_rawimage(name)
5
+ @options = { path: "/rawimages/#{name}", body: '' }.merge(@options)
6
+
7
+ request(
8
+ expects: 200,
9
+ method: :get,
10
+ body: @options[:body]
11
+ )
12
+ end
13
+
14
+ def list_rawimages
15
+ @options = {:path => "/rawimages",:body => ""}.merge(@options)
16
+
17
+ request(
18
+ :expects => 200,
19
+ :method => :get,
20
+ :body => @options[:body]
21
+ )
22
+ end
23
+
24
+ def post_rawimages(rawimage_item)
25
+ @options = {:path => '/rawimages/content',
26
+ :body => Megam::JSONCompat.to_json(rawimage_item)}.merge(@options)
27
+
28
+ request(
29
+ :expects => 201,
30
+ :method => :post,
31
+ :body => @options[:body]
32
+ )
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,24 @@
1
+ module Megam
2
+ class API
3
+
4
+ def post_reports(new_sps)
5
+ @options = {:path => '/admin/reports/content',
6
+ :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)
7
+
8
+ request(
9
+ :expects => 200,
10
+ :method => :post,
11
+ :body => @options[:body]
12
+ )
13
+ end
14
+
15
+ def get_reports(new_sps)
16
+ @options = {:path => '/accounts/reports/content', :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)
17
+ request(
18
+ :expects => 200,
19
+ :method => :post,
20
+ :body => @options[:body]
21
+ )
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ module Megam
2
+ class API
3
+
4
+ # GET /requests
5
+ def get_requests
6
+ @options = {:path => '/requests',:body => ""}.merge(@options)
7
+
8
+ request(
9
+ :expects => 200,
10
+ :method => :get,
11
+ :body => @options[:body]
12
+ )
13
+ end
14
+
15
+ def get_request(node_name)
16
+ @options = {:path => "/requests/#{node_name}",:body => ""}.merge(@options)
17
+
18
+ request(
19
+ :expects => 200,
20
+ :method => :get,
21
+ :body => @options[:body]
22
+ )
23
+ end
24
+
25
+ def post_request(new_req)
26
+ @options = {:path => '/requests/content',
27
+ :body => Megam::JSONCompat.to_json(new_req)}.merge(@options)
28
+ request(
29
+ :expects => 201,
30
+ :method => :post,
31
+ :body => @options[:body]
32
+ )
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ module Megam
2
+ class API
3
+ def get_sensors
4
+ @options = {:path => '/sensors',:body => ""}.merge(@options)
5
+
6
+ request(
7
+ :expects => 200,
8
+ :method => :get,
9
+ :body => @options[:body]
10
+ )
11
+ end
12
+
13
+ def get_sensor(id)
14
+ @options = {:path => "/sensors/#{id}",:body => ""}.merge(@options)
15
+
16
+ request(
17
+ :expects => 200,
18
+ :method => :get,
19
+ :body => @options[:body]
20
+ )
21
+ end
22
+
23
+ def post_sensors(new_sensors)
24
+ @options = {:path => '/sensors/content',
25
+ :body => Megam::JSONCompat.to_json(new_sensors)}.merge(@options)
26
+
27
+ request(
28
+ :expects => 201,
29
+ :method => :post,
30
+ :body => @options[:body]
31
+ )
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,46 @@
1
+ module Megam
2
+ class API
3
+ # GET /nodes
4
+ def list_snapshots
5
+ @options = {:path => "/snapshots",:body => ""}.merge(@options)
6
+
7
+ request(
8
+ :expects => 200,
9
+ :method => :get,
10
+ :body => @options[:body]
11
+ )
12
+ end
13
+
14
+ def get_snapshots(asm_id)
15
+ @options = {:path => "/snapshots/#{asm_id}",:body => ""}.merge(@options)
16
+
17
+ request(
18
+ :expects => 200,
19
+ :method => :get,
20
+ :body => @options[:body]
21
+ )
22
+ end
23
+ def post_snapshots(new_sps)
24
+ @options = {:path => '/snapshots/content',
25
+ :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)
26
+
27
+ request(
28
+ :expects => 201,
29
+ :method => :post,
30
+ :body => @options[:body]
31
+ )
32
+ end
33
+
34
+ def update_snapshots(update_sps)
35
+ @options = {:path => '/snapshots/update',
36
+ :body => Megam::JSONCompat.to_json(update_sps)}.merge(@options)
37
+
38
+ request(
39
+ :expects => 201,
40
+ :method => :post,
41
+ :body => @options[:body]
42
+ )
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ module Megam
2
+ class API
3
+ def get_sshkeys
4
+ @options = {:path => '/sshkeys',:body => ""}.merge(@options)
5
+
6
+ request(
7
+ :expects => 200,
8
+ :method => :get,
9
+ :body => @options[:body]
10
+ )
11
+ end
12
+
13
+ def get_sshkey(sshkey_name)
14
+ @options = {:path => "/sshkeys/#{sshkey_name}",:body => ""}.merge(@options)
15
+
16
+ request(
17
+ :expects => 200,
18
+ :method => :get,
19
+ :body => @options[:body]
20
+ )
21
+ end
22
+
23
+ def post_sshkey(new_sshkey)
24
+ @options = {:path => '/sshkeys/content',
25
+ :body => Megam::JSONCompat.to_json(new_sshkey)}.merge(@options)
26
+
27
+ request(
28
+ :expects => 201,
29
+ :method => :post,
30
+ :body => @options[:body]
31
+ )
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ module Megam
2
+ class API
3
+
4
+ def get_subscription
5
+ @options = {:path => "/subscriptions",:body => ""}.merge(@options)
6
+
7
+ request(
8
+ :expects => 200,
9
+ :method => :get,
10
+ :body => @options[:body]
11
+ )
12
+ end
13
+
14
+ def post_subscriptions(new_subscription)
15
+ @options = {:path => '/subscriptions/content',
16
+ :body => Megam::JSONCompat.to_json(new_subscription)}.merge(@options)
17
+
18
+ request(
19
+ :expects => 201,
20
+ :method => :post,
21
+ :body => @options[:body]
22
+ )
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ module Megam
2
+ class API
3
+ # VERSION = "1.52.6"
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
@@ -0,0 +1,245 @@
1
+ module Megam
2
+ class Account < Megam::RestAdapter
3
+
4
+ attr_accessor :id
5
+ attr_accessor :email
6
+ attr_accessor :password
7
+ attr_accessor :api_key
8
+ attr_accessor :name
9
+ attr_accessor :phone
10
+ attr_accessor :states
11
+ attr_accessor :approval
12
+ attr_accessor :suspend
13
+ attr_accessor :registration_ip_address
14
+ attr_accessor :dates
15
+ attr_accessor :json_claz, :code, :msg_type, :msg, :links, :more, :user_email
16
+ attr_accessor :some_msg
17
+
18
+
19
+ def initialize(o={})
20
+ @id = nil
21
+ @email = nil
22
+ @user_email = nil
23
+ @api_key = nil
24
+ @name = {}
25
+ @phone = {}
26
+ @password = {}
27
+ @states = {}
28
+ @approval = {}
29
+ @suspend = {}
30
+ @dates = {}
31
+ @some_msg = {}
32
+
33
+ super({ email: o[:email], api_key: o[:api_key],
34
+ host: o[:host], password_hash: o[:password_hash], org_id: o[:org_id] })
35
+ end
36
+
37
+ def account
38
+ self
39
+ end
40
+
41
+ def some_msg(arg = nil)
42
+ if !arg.nil?
43
+ @some_msg = arg
44
+ else
45
+ @some_msg
46
+ end
47
+ end
48
+
49
+ def error?
50
+ crocked = true if some_msg.key?(:msg_type) && some_msg[:msg_type] == 'error'
51
+ end
52
+
53
+ def to_json(*a)
54
+ for_json.to_json(*a)
55
+ end
56
+
57
+ def for_json
58
+ result = {
59
+ 'id' => @id,
60
+ 'email' => @email,
61
+ 'api_key' => @api_key,
62
+ 'name' => @name,
63
+ 'phone' => @phone,
64
+ 'password' => @password,
65
+ 'states' => @states,
66
+ 'approval' => @approval,
67
+ 'suspend' => @suspend,
68
+ 'registration_ip_address' => @registration_ip_address,
69
+ 'dates' => @dates
70
+ }
71
+ result
72
+ end
73
+
74
+ def self.json_create(o)
75
+ acct = new()
76
+ o.symbolize_keys!
77
+ o = o[:results] if o.has_key?(:results)
78
+
79
+ o.each { |k, v| acct.send("#{k}=", v) }
80
+
81
+ acct.some_msg[:code] = @code if @code
82
+ acct.some_msg[:msg_type] = @msg_type if @msg_type
83
+ acct.some_msg[:msg] = @msg if @msg
84
+ acct.some_msg[:more] = @more if @more
85
+ acct.some_msg[:links] = @links if @links
86
+
87
+ acct
88
+ end
89
+
90
+
91
+ #Can be used by the calling classes to get the full hash
92
+ # (eg: Nilavu: User model)
93
+ def expanded
94
+ h = Hash.new
95
+ [:id, :email, :api_key, :name, :phone, :password,:states, :approval, :suspend,
96
+ :registration_ip_address, :dates, :some_msg].each do |setting|
97
+ if grouped = self.send("#{setting}").is_a?(Hash)
98
+ self.send("#{setting}").each {|k,v| h[k.to_sym] = v}
99
+ else
100
+ h[setting] = self.send("#{setting}")
101
+ end
102
+ end
103
+ h
104
+ end
105
+
106
+
107
+ def self.from_hash(o)
108
+ acct = new(email: o[:email], api_key: o[:api_key], host: o[:host], password_hash: o[:password_hash], org_id: o[:org_id])
109
+ acct.from_hash(o)
110
+ acct
111
+ end
112
+
113
+ def from_hash(o)
114
+ @id = o[:id] if o.key?(:id)
115
+ @email = o[:email] if o.key?(:email)
116
+ @user_email = o[:user_email] if o.key?(:user_email)
117
+ @api_key = o[:api_key] if o.key?(:api_key)
118
+
119
+ @name[:first_name] = o[:first_name] if o.key?(:first_name)
120
+ @name[:last_name] = o[:last_name] if o.key?(:last_name)
121
+
122
+ @phone[:phone] = o[:phone] if o.key?(:phone)
123
+ @phone[:phone_verified] = o[:phone_verified] if o.key?(:phone_verified)
124
+
125
+ @password[:password_hash] = o[:password_hash] if o.key?(:password_hash)
126
+ @password[:password_reset_key] = o[:password_reset_key] if o.key?(:password_reset_key)
127
+ @password[:password_reset_sent_at] = o[:password_reset_sent_at] if o.key?(:password_reset_sent_at)
128
+
129
+ @states[:authority] = o[:authority] if o.key?(:authority)
130
+ @states[:active] = o[:active] if o.key?(:active)
131
+ @states[:blocked] = o[:blocked] if o.key?(:blocked)
132
+ @states[:staged] = o[:staged] if o.key?(:staged)
133
+
134
+ @approval[:approved] = o[:approved] if o.key?(:approved)
135
+ @approval[:approved_by_id] = o[:approved_by_id] if o.key?(:approved_by_id)
136
+ @approval[:approved_at] = o[:approved_at] if o.key?(:approved_at)
137
+
138
+ @suspend[:suspended] = o[:suspended] if o.key?(:suspended)
139
+ @suspend[:suspended_at] = o[:suspend] if o.key?(:suspended_at)
140
+ @suspend[:suspended_till] = o[:suspended_till] if o.key?(:suspended_till)
141
+ @registration_ip_address = o[:registration_ip_address] if o.key?(:registration_ip_address)
142
+
143
+ @dates[:last_posted_at] = o[:last_posted_at] if o.key?(:last_posted_at)
144
+ @dates[:last_emailed_at] = o[:last_emailed_at] if o.key?(:last_emailed_at)
145
+ @dates[:previous_visit_at] = o[:previous_visit_at] if o.key?(:previous_visit_at)
146
+ @dates[:first_seen_at] = o[:first_seen_at] if o.key?(:first_seen_at)
147
+ @dates[:created_at] = o[:created_at] if o.key?(:created_at)
148
+ self
149
+ end
150
+
151
+ def self.login(o)
152
+ acct = from_hash(o)
153
+ acct.login
154
+ end
155
+
156
+ def login
157
+ megam_rest.login(to_hash)
158
+ end
159
+
160
+
161
+ def self.create(o)
162
+ acct = from_hash(o)
163
+ acct.create
164
+ end
165
+
166
+ def create
167
+ megam_rest.post_accounts(to_hash)
168
+ end
169
+
170
+ def self.show(o)
171
+ acct = from_hash(o)
172
+ acct.megam_rest.get_accounts(o[:email])
173
+ end
174
+
175
+ def self.list(o)
176
+ acct = from_hash(o)
177
+ acct.list
178
+ end
179
+
180
+ def list
181
+ megam_rest.list_accounts
182
+ end
183
+
184
+ def self.update(o)
185
+ acct = from_hash(o)
186
+ acct.update
187
+ end
188
+
189
+ def self.forgot(o)
190
+ acct = from_hash(o)
191
+ acct.forgot
192
+ end
193
+
194
+ def self.remove(o)
195
+ acct = from_hash(o)
196
+ acct.remove
197
+ end
198
+
199
+ def remove
200
+ megam_rest.delete_accounts(to_hash)
201
+ end
202
+
203
+ def self.password_reset(o)
204
+ acct = from_hash(o)
205
+ acct.password_reset
206
+ end
207
+
208
+ def update
209
+ megam_rest.update_accounts(to_hash)
210
+ end
211
+
212
+ def forgot
213
+ megam_rest.forgot(to_hash)
214
+ end
215
+
216
+ def password_reset
217
+ megam_rest.password_reset(to_hash)
218
+ end
219
+
220
+ def to_s
221
+ Megam::Stuff.styled_hash(to_hash)
222
+ end
223
+
224
+ private
225
+
226
+ def to_hash
227
+ h = Hash.new
228
+ h['json_claz'] = self.class.name
229
+ h['id'] = @id
230
+ h['email'] = @email
231
+ h['user_email'] = @user_email
232
+ h['api_key'] = @api_key
233
+ h['name'] = @name
234
+ h['phone'] = @phone
235
+ h['password'] = @password
236
+ h['states'] = @states
237
+ h['approval'] = @approval
238
+ h['suspend'] = @suspend
239
+ h['registration_ip_address'] = @registration_ip_address
240
+ h['dates'] = @dates
241
+ h['some_msg'] = some_msg
242
+ h
243
+ end
244
+ end
245
+ end