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