megam_api 0.100 → 1.5.beta2
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.
- checksums.yaml +4 -4
- data/README.md +5 -69
- data/lib/megam/api.rb +15 -37
- data/lib/megam/api/errors.rb +19 -19
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/account.rb +1 -1
- data/lib/megam/core/assemblies.rb +1 -1
- data/lib/megam/core/assemblies_collection.rb +7 -15
- data/lib/megam/core/assembly.rb +1 -1
- data/lib/megam/core/assembly_collection.rb +7 -15
- data/lib/megam/core/balances.rb +1 -1
- data/lib/megam/core/balances_collection.rb +8 -16
- data/lib/megam/core/billedhistories.rb +1 -1
- data/lib/megam/core/billedhistories_collection.rb +7 -15
- data/lib/megam/core/components.rb +1 -1
- data/lib/megam/core/components_collection.rb +103 -110
- data/lib/megam/core/domain_collection.rb +102 -109
- data/lib/megam/core/domains.rb +1 -1
- data/lib/megam/core/error.rb +1 -15
- data/lib/megam/core/json_compat.rb +170 -208
- data/lib/megam/core/marketplace.rb +1 -1
- data/lib/megam/core/marketplace_collection.rb +7 -16
- data/lib/megam/core/organizations.rb +1 -1
- data/lib/megam/core/organizations_collection.rb +8 -40
- data/lib/megam/core/promos.rb +1 -1
- data/lib/megam/core/request.rb +1 -1
- data/lib/megam/core/request_collection.rb +7 -16
- data/lib/megam/core/rest_adapter.rb +54 -0
- data/lib/megam/core/sensors.rb +1 -1
- data/lib/megam/core/sensors_collection.rb +7 -14
- data/lib/megam/core/sshkey.rb +1 -1
- data/lib/megam/core/sshkey_collection.rb +103 -110
- data/lib/megam/core/stuff.rb +2 -34
- data/lib/megam/core/text.rb +1 -0
- data/lib/megam/core/text_formatter.rb +2 -1
- data/megam_api.gemspec +2 -2
- metadata +10 -56
- data/lib/megam/api/availableunits.rb +0 -50
- data/lib/megam/api/billings.rb +0 -50
- data/lib/megam/api/credithistories.rb +0 -50
- data/lib/megam/api/csars.rb +0 -75
- data/lib/megam/api/discounts.rb +0 -50
- data/lib/megam/api/invoices.rb +0 -50
- data/lib/megam/api/login.rb +0 -29
- data/lib/megam/api/subscriptions.rb +0 -50
- data/lib/megam/core/auth.rb +0 -91
- data/lib/megam/core/availableunits.rb +0 -182
- data/lib/megam/core/availableunits_collection.rb +0 -144
- data/lib/megam/core/billings.rb +0 -242
- data/lib/megam/core/billings_collection.rb +0 -144
- data/lib/megam/core/config.rb +0 -41
- data/lib/megam/core/credithistories.rb +0 -191
- data/lib/megam/core/credithistories_collection.rb +0 -144
- data/lib/megam/core/csar.rb +0 -179
- data/lib/megam/core/csar_collection.rb +0 -148
- data/lib/megam/core/discounts.rb +0 -204
- data/lib/megam/core/discounts_collection.rb +0 -164
- data/lib/megam/core/invoices.rb +0 -231
- data/lib/megam/core/invoices_collection.rb +0 -144
- data/lib/megam/core/server_api.rb +0 -52
- data/lib/megam/core/subscriptions.rb +0 -191
- data/lib/megam/core/subscriptions_collection.rb +0 -144
- data/test/test_availableunits.rb +0 -28
- data/test/test_billings.rb +0 -33
- data/test/test_cat_requests.rb +0 -20
- data/test/test_credithistories.rb +0 -29
- data/test/test_csars.rb +0 -22
- data/test/test_discounts.rb +0 -31
- data/test/test_invoices.rb +0 -31
- data/test/test_login.rb +0 -10
- data/test/test_marketplaceaddons.rb +0 -46
- data/test/test_predefclouds.rb +0 -80
- data/test/test_subscriptions.rb +0 -29
@@ -101,45 +101,18 @@ module Megam
|
|
101
101
|
@organizations[res]
|
102
102
|
end
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
index_hash
|
104
|
+
def to_s
|
105
|
+
@organizations.join(", ")
|
106
|
+
end
|
107
|
+
|
108
|
+
def for_json
|
109
|
+
to_a.map { |item| item.to_s }
|
111
110
|
end
|
112
111
|
|
113
|
-
# Serialize this object as a hash: called from JsonCompat.
|
114
|
-
# Verify if this called from JsonCompat during testing.
|
115
112
|
def to_json(*a)
|
116
|
-
|
113
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
117
114
|
end
|
118
115
|
|
119
|
-
=begin
|
120
|
-
{
|
121
|
-
"json_claz":"Megam::PredefCloudCollection",
|
122
|
-
"results":[{
|
123
|
-
"id":"NOD362554470640386048",
|
124
|
-
"name":"ec2_rails",
|
125
|
-
"account_id":"ACT362544229488001024",
|
126
|
-
"json_claz":"Megam::PredefCloud",
|
127
|
-
"spec":{
|
128
|
-
"type_name":"sensor-type",
|
129
|
-
"groups":"sens-group",
|
130
|
-
"image":"sens-image",
|
131
|
-
"flavor":"sens-flvr"
|
132
|
-
},
|
133
|
-
"access":{
|
134
|
-
"ssh_key":"sens-ssh",
|
135
|
-
"identity_file":"sens-identity-file",
|
136
|
-
"ssh_user":"sens-sshuser"
|
137
|
-
},
|
138
|
-
"ideal":"",
|
139
|
-
"performance":""
|
140
|
-
}]
|
141
|
-
}
|
142
|
-
=end
|
143
116
|
def self.json_create(o)
|
144
117
|
collection = self.new()
|
145
118
|
o["results"].each do |organizations_list|
|
@@ -159,10 +132,5 @@ module Megam
|
|
159
132
|
end
|
160
133
|
true
|
161
134
|
end
|
162
|
-
|
163
|
-
def to_s
|
164
|
-
Megam::Stuff.styled_hash(to_hash)
|
165
|
-
end
|
166
|
-
|
167
135
|
end
|
168
|
-
end
|
136
|
+
end
|
data/lib/megam/core/promos.rb
CHANGED
data/lib/megam/core/request.rb
CHANGED
@@ -101,21 +101,17 @@ module Megam
|
|
101
101
|
@requests[res]
|
102
102
|
end
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
index_hash = Hash.new
|
107
|
-
self.each do |request|
|
108
|
-
index_hash[request.node_name] = request.to_s
|
109
|
-
end
|
110
|
-
index_hash
|
104
|
+
def to_s
|
105
|
+
@requests.join(", ")
|
111
106
|
end
|
112
107
|
|
113
|
-
|
114
|
-
|
115
|
-
def to_json(*a)
|
116
|
-
for_json.to_json(*a)
|
108
|
+
def for_json
|
109
|
+
to_a.map { |item| item.to_s }
|
117
110
|
end
|
118
111
|
|
112
|
+
def to_json(*a)
|
113
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
114
|
+
end
|
119
115
|
|
120
116
|
def self.json_create(o)
|
121
117
|
collection = self.new()
|
@@ -136,10 +132,5 @@ module Megam
|
|
136
132
|
end
|
137
133
|
true
|
138
134
|
end
|
139
|
-
|
140
|
-
def to_s
|
141
|
-
Megam::Stuff.styled_hash(to_hash)
|
142
|
-
end
|
143
|
-
|
144
135
|
end
|
145
136
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2013-2016 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 RestAdapter
|
18
|
+
attr_reader :email
|
19
|
+
attr_reader :api_key
|
20
|
+
attr_reader :host
|
21
|
+
attr_reader :password
|
22
|
+
attr_reader :org_id
|
23
|
+
attr_reader :headers
|
24
|
+
|
25
|
+
|
26
|
+
## clean up this module later.
|
27
|
+
def initialize(o)
|
28
|
+
@email = o[:email]
|
29
|
+
@api_key = o[:api_key] || nil
|
30
|
+
@host = o[:host]
|
31
|
+
@password = o[:password] || nil
|
32
|
+
@org_id = o[:org_id]
|
33
|
+
@headers = o[:headers]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Build a megam api client
|
37
|
+
#
|
38
|
+
# === Parameters
|
39
|
+
# api:: The Megam::API client
|
40
|
+
def megam_rest
|
41
|
+
options = {
|
42
|
+
:email => email,
|
43
|
+
:api_key => api_key,
|
44
|
+
:org_id => org_id,
|
45
|
+
:password => password,
|
46
|
+
:host => host
|
47
|
+
}
|
48
|
+
if headers
|
49
|
+
options[:headers] = headers
|
50
|
+
end
|
51
|
+
Megam::API.new(options)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/megam/core/sensors.rb
CHANGED
@@ -101,19 +101,16 @@ module Megam
|
|
101
101
|
@sensors[res]
|
102
102
|
end
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
index_hash
|
104
|
+
def to_s
|
105
|
+
@sensors.join(", ")
|
106
|
+
end
|
107
|
+
|
108
|
+
def for_json
|
109
|
+
to_a.map { |item| item.to_s }
|
111
110
|
end
|
112
111
|
|
113
|
-
# Serialize this object as a hash: called from JsonCompat.
|
114
|
-
# Verify if this called from JsonCompat during testing.
|
115
112
|
def to_json(*a)
|
116
|
-
|
113
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
117
114
|
end
|
118
115
|
|
119
116
|
def self.json_create(o)
|
@@ -135,9 +132,5 @@ module Megam
|
|
135
132
|
end
|
136
133
|
true
|
137
134
|
end
|
138
|
-
|
139
|
-
def to_s
|
140
|
-
Megam::Stuff.styled_hash(to_hash)
|
141
|
-
end
|
142
135
|
end
|
143
136
|
end
|
data/lib/megam/core/sshkey.rb
CHANGED
@@ -14,131 +14,124 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
module Megam
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
attr_reader :iterator
|
21
|
-
def initialize
|
22
|
-
@sshkeys = Array.new
|
23
|
-
@sshkeys_by_name = Hash.new
|
24
|
-
@insert_after_idx = nil
|
25
|
-
end
|
17
|
+
class SshKeyCollection
|
18
|
+
include Enumerable
|
26
19
|
|
27
|
-
|
28
|
-
@sshkeys
|
29
|
-
end
|
20
|
+
attr_reader :iterator
|
30
21
|
|
31
|
-
|
32
|
-
|
33
|
-
|
22
|
+
def initialize
|
23
|
+
@sshkeys = Array.new
|
24
|
+
@sshkeys_by_name = Hash.new
|
25
|
+
@insert_after_idx = nil
|
26
|
+
end
|
34
27
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@sshkeys_by_name[arg.name] = index
|
39
|
-
end
|
28
|
+
def all_sshkeys
|
29
|
+
@sshkeys
|
30
|
+
end
|
40
31
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@sshkeys << a
|
45
|
-
@sshkeys_by_name[a.name] =@sshkeys.length - 1
|
46
|
-
end
|
47
|
-
self
|
48
|
-
end
|
32
|
+
def [](index)
|
33
|
+
@sshkeys[index]
|
34
|
+
end
|
49
35
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
is_megam_sshkeys(sshkeys)
|
55
|
-
if @insert_after_idx
|
56
|
-
# in the middle of executing a run, so any sshkeys inserted now should
|
57
|
-
# be placed after the most recent addition done by the currently executing
|
58
|
-
# sshkey
|
59
|
-
@sshkeys.insert(@insert_after_idx + 1, sshkeys)
|
60
|
-
# update name -> location mappings and register new sshkeys
|
61
|
-
@sshkeys_by_name.each_key do |key|
|
62
|
-
@sshkeys_by_name[key] += 1 if@sshkeys_by_name[key] > @insert_after_idx
|
36
|
+
def []=(index, arg)
|
37
|
+
is_megam_sshkeys(arg)
|
38
|
+
@sshkeys[index] = arg
|
39
|
+
@sshkeys_by_name[arg.name] = index
|
63
40
|
end
|
64
|
-
@sshkeys_by_name[sshkeys.name] = @insert_after_idx + 1
|
65
|
-
@insert_after_idx += 1
|
66
|
-
else
|
67
|
-
@sshkeys << sshkeys
|
68
|
-
@sshkeys_by_name[sshkeys.name] =@sshkeys.length - 1
|
69
|
-
end
|
70
|
-
end
|
71
41
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
42
|
+
def <<(*args)
|
43
|
+
args.flatten.each do |a|
|
44
|
+
is_megam_sshkeys(a)
|
45
|
+
@sshkeys << a
|
46
|
+
@sshkeys_by_name[a.name] =@sshkeys.length - 1
|
47
|
+
end
|
48
|
+
self
|
49
|
+
end
|
77
50
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
51
|
+
# 'push' is an alias method to <<
|
52
|
+
alias_method :push, :<<
|
53
|
+
|
54
|
+
def insert(sshkeys)
|
55
|
+
is_megam_sshkeys(sshkeys)
|
56
|
+
if @insert_after_idx
|
57
|
+
# in the middle of executing a run, so any sshkeys inserted now should
|
58
|
+
# be placed after the most recent addition done by the currently executing
|
59
|
+
# sshkey
|
60
|
+
@sshkeys.insert(@insert_after_idx + 1, sshkeys)
|
61
|
+
# update name -> location mappings and register new sshkeys
|
62
|
+
@sshkeys_by_name.each_key do |key|
|
63
|
+
@sshkeys_by_name[key] += 1 if@sshkeys_by_name[key] > @insert_after_idx
|
64
|
+
end
|
65
|
+
@sshkeys_by_name[sshkeys.name] = @insert_after_idx + 1
|
66
|
+
@insert_after_idx += 1
|
67
|
+
else
|
68
|
+
@sshkeys << sshkeys
|
69
|
+
@sshkeys_by_name[sshkeys.name] =@sshkeys.length - 1
|
70
|
+
end
|
71
|
+
end
|
83
72
|
|
84
|
-
|
85
|
-
|
86
|
-
|
73
|
+
def each
|
74
|
+
@sshkeys.each do |sshkeys|
|
75
|
+
yield sshkeys
|
76
|
+
end
|
77
|
+
end
|
87
78
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
lookup_by = sshkeys
|
94
|
-
else
|
95
|
-
raise ArgumentError, "Must pass a Megam::sshkeys or String to lookup"
|
96
|
-
end
|
97
|
-
res =@sshkeys_by_name[lookup_by]
|
98
|
-
unless res
|
99
|
-
raise ArgumentError, "Cannot find a sshkeys matching #{lookup_by} (did you define it first?)"
|
100
|
-
end
|
101
|
-
@sshkeys[res]
|
102
|
-
end
|
79
|
+
def each_index
|
80
|
+
@sshkeys.each_index do |i|
|
81
|
+
yield i
|
82
|
+
end
|
83
|
+
end
|
103
84
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
self.each do |sshkeys|
|
108
|
-
index_hash[sshkeys.name] = sshkeys.to_s
|
109
|
-
end
|
110
|
-
index_hash
|
111
|
-
end
|
85
|
+
def empty?
|
86
|
+
@sshkeys.empty?
|
87
|
+
end
|
112
88
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
89
|
+
def lookup(sshkeys)
|
90
|
+
lookup_by = nil
|
91
|
+
if sshkeys.kind_of?(Megam::SshKey)
|
92
|
+
lookup_by = sshkeys.name
|
93
|
+
elsif sshkeys.kind_of?(String)
|
94
|
+
lookup_by = sshkeys
|
95
|
+
else
|
96
|
+
raise ArgumentError, "Must pass a Megam::sshkeys or String to lookup"
|
97
|
+
end
|
98
|
+
res =@sshkeys_by_name[lookup_by]
|
99
|
+
unless res
|
100
|
+
raise ArgumentError, "Cannot find a sshkeys matching #{lookup_by} (did you define it first?)"
|
101
|
+
end
|
102
|
+
@sshkeys[res]
|
103
|
+
end
|
118
104
|
|
119
|
-
|
120
|
-
|
121
|
-
o["results"].each do |sshkeys_list|
|
122
|
-
sshkeys_array = sshkeys_list.kind_of?(Array) ? sshkeys_list : [ sshkeys_list ]
|
123
|
-
sshkeys_array.each do |sshkeys|
|
124
|
-
collection.insert(sshkeys)
|
105
|
+
def to_s
|
106
|
+
@sshkeys.join(", ")
|
125
107
|
end
|
126
|
-
end
|
127
|
-
collection
|
128
|
-
end
|
129
108
|
|
130
|
-
|
109
|
+
def for_json
|
110
|
+
to_a.map { |item| item.to_s }
|
111
|
+
end
|
131
112
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
end
|
136
|
-
true
|
137
|
-
end
|
113
|
+
def to_json(*a)
|
114
|
+
Megam::JSONCompat.to_json(for_json, *a)
|
115
|
+
end
|
138
116
|
|
139
|
-
|
140
|
-
|
141
|
-
|
117
|
+
def self.json_create(o)
|
118
|
+
collection = self.new()
|
119
|
+
o["results"].each do |sshkeys_list|
|
120
|
+
sshkeys_array = sshkeys_list.kind_of?(Array) ? sshkeys_list : [ sshkeys_list ]
|
121
|
+
sshkeys_array.each do |sshkeys|
|
122
|
+
collection.insert(sshkeys)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
collection
|
126
|
+
end
|
142
127
|
|
143
|
-
|
144
|
-
|
128
|
+
private
|
129
|
+
|
130
|
+
def is_megam_sshkeys(arg)
|
131
|
+
unless arg.kind_of?(Megam::SshKey)
|
132
|
+
raise ArgumentError, "Members must be Megam::SshKeys's"
|
133
|
+
end
|
134
|
+
true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|