megam_api 0.17 → 0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/megam/api.rb +20 -35
- data/lib/megam/api/{nodes.rb → assemblies.rb} +9 -9
- data/lib/megam/api/domains.rb +30 -0
- data/lib/megam/api/organizations.rb +30 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/assemblies.rb +180 -0
- data/lib/megam/core/{node_collection.rb → assemblies_collection.rb} +44 -65
- data/lib/megam/core/csar.rb +0 -1
- data/lib/megam/core/domains.rb +129 -0
- data/lib/megam/core/json_compat.rb +17 -4
- data/lib/megam/core/organizations.rb +129 -0
- data/test/test_accounts.rb +1 -1
- data/test/test_assemblies.rb +10 -0
- data/test/test_domains.rb +27 -0
- data/test/test_helper.rb +25 -16
- data/test/test_organizations.rb +26 -0
- metadata +12 -38
- data/lib/megam/api/app_request.rb +0 -27
- data/lib/megam/api/appdefns.rb +0 -47
- data/lib/megam/api/bolt_request.rb +0 -27
- data/lib/megam/api/boltdefns.rb +0 -39
- data/lib/megam/api/cloud_tools.rb +0 -35
- data/lib/megam/api/logs.rb +0 -18
- data/lib/megam/api/predefs.rb +0 -35
- data/lib/megam/builder/delete_node.rb +0 -107
- data/lib/megam/builder/make_node.rb +0 -133
- data/lib/megam/core/app_request.rb +0 -227
- data/lib/megam/core/app_request_collection.rb +0 -148
- data/lib/megam/core/appdefns.rb +0 -182
- data/lib/megam/core/appdefns_collection.rb +0 -148
- data/lib/megam/core/bolt_request.rb +0 -225
- data/lib/megam/core/bolt_request_collection.rb +0 -148
- data/lib/megam/core/boltdefns.rb +0 -207
- data/lib/megam/core/boltdefns_collection.rb +0 -148
- data/lib/megam/core/cloudinstruction.rb +0 -110
- data/lib/megam/core/cloudinstruction_collection.rb +0 -145
- data/lib/megam/core/cloudinstruction_group.rb +0 -99
- data/lib/megam/core/cloudtemplate.rb +0 -127
- data/lib/megam/core/cloudtemplate_collection.rb +0 -145
- data/lib/megam/core/cloudtool.rb +0 -152
- data/lib/megam/core/cloudtool_collection.rb +0 -145
- data/lib/megam/core/node.rb +0 -366
- data/lib/megam/core/predef.rb +0 -201
- data/lib/megam/core/predef_collection.rb +0 -164
- data/test/test_appdefns.rb +0 -35
- data/test/test_appreqs.rb +0 -25
- data/test/test_boltdefns.rb +0 -32
- data/test/test_boltreqs.rb +0 -26
- data/test/test_cloudtools.rb +0 -22
- data/test/test_nodes.rb +0 -140
- data/test/test_predefs.rb +0 -72
@@ -1,164 +0,0 @@
|
|
1
|
-
# Copyright:: Copyright (c) 2012, 2014 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 PredefCollection
|
18
|
-
include Enumerable
|
19
|
-
|
20
|
-
attr_reader :iterator
|
21
|
-
def initialize
|
22
|
-
@predefs = Array.new
|
23
|
-
@predefs_by_name = Hash.new
|
24
|
-
@insert_after_idx = nil
|
25
|
-
end
|
26
|
-
|
27
|
-
def all_predefs
|
28
|
-
@predefs
|
29
|
-
end
|
30
|
-
|
31
|
-
def [](index)
|
32
|
-
@predefs[index]
|
33
|
-
end
|
34
|
-
|
35
|
-
def []=(index, arg)
|
36
|
-
is_megam_predef(arg)
|
37
|
-
@predefs[index] = arg
|
38
|
-
@predefs_by_name[arg.name] = index
|
39
|
-
end
|
40
|
-
|
41
|
-
def <<(*args)
|
42
|
-
args.flatten.each do |a|
|
43
|
-
is_megam_predef(a)
|
44
|
-
@predefs << a
|
45
|
-
@predefs_by_name[a.name] = @predefs.length - 1
|
46
|
-
end
|
47
|
-
self
|
48
|
-
end
|
49
|
-
|
50
|
-
# 'push' is an alias method to <<
|
51
|
-
alias_method :push, :<<
|
52
|
-
|
53
|
-
def insert(predef)
|
54
|
-
is_megam_predef(predef)
|
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
|
-
# predef
|
59
|
-
@predefs.insert(@insert_after_idx + 1, predef)
|
60
|
-
# update name -> location mappings and register new predef
|
61
|
-
@predefs_by_name.each_key do |key|
|
62
|
-
@predefs_by_name[key] += 1 if @predefs_by_name[key] > @insert_after_idx
|
63
|
-
end
|
64
|
-
@predefs_by_name[predef.name] = @insert_after_idx + 1
|
65
|
-
@insert_after_idx += 1
|
66
|
-
else
|
67
|
-
@predefs << predef
|
68
|
-
@predefs_by_name[predef.name] = @predefs.length - 1
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def each
|
73
|
-
@predefs.each do |predef|
|
74
|
-
yield predef
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def each_index
|
79
|
-
@predefs.each_index do |i|
|
80
|
-
yield i
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def empty?
|
85
|
-
@predefs.empty?
|
86
|
-
end
|
87
|
-
|
88
|
-
def lookup(predef)
|
89
|
-
lookup_by = nil
|
90
|
-
if predef.kind_of?(Megam::Predef)
|
91
|
-
lookup_by = predef.name
|
92
|
-
elsif predef.kind_of?(String)
|
93
|
-
lookup_by = predef
|
94
|
-
else
|
95
|
-
raise ArgumentError, "Must pass a Megam::Predef or String to lookup"
|
96
|
-
end
|
97
|
-
res = @predefs_by_name[lookup_by]
|
98
|
-
unless res
|
99
|
-
raise ArgumentError, "Cannot find a predef matching #{lookup_by} (did you define it first?)"
|
100
|
-
end
|
101
|
-
@predefs[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 |predef|
|
108
|
-
index_hash[predef.name] = predef.to_s
|
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
|
-
=begin
|
120
|
-
{
|
121
|
-
"json_claz":"Megam::PredefCollection",
|
122
|
-
"results":[{
|
123
|
-
"id":"PRE362554468593565696",
|
124
|
-
"name":"rabbitmq",
|
125
|
-
"provider":"chef",
|
126
|
-
"provider_role":"rabbitmq",
|
127
|
-
"build_monkey":"none",
|
128
|
-
"json_claz":"Megam::Predef"
|
129
|
-
},{
|
130
|
-
"id":"PRE362554470090932224",
|
131
|
-
"name":"mobhtml5",
|
132
|
-
"provider":"chef",
|
133
|
-
"provider_role":"sencha",
|
134
|
-
"build_monkey":"none",
|
135
|
-
"json_claz":"Megam::Predef"
|
136
|
-
}]
|
137
|
-
}
|
138
|
-
=end
|
139
|
-
def self.json_create(o)
|
140
|
-
collection = self.new()
|
141
|
-
o["results"].each do |predefs_list|
|
142
|
-
predefs_array = predefs_list.kind_of?(Array) ? predefs_list : [ predefs_list ]
|
143
|
-
predefs_array.each do |predef|
|
144
|
-
collection.insert(predef)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
collection
|
148
|
-
end
|
149
|
-
|
150
|
-
private
|
151
|
-
|
152
|
-
def is_megam_predef(arg)
|
153
|
-
unless arg.kind_of?(Megam::Predef)
|
154
|
-
raise ArgumentError, "Members must be Megam::Predef's"
|
155
|
-
end
|
156
|
-
true
|
157
|
-
end
|
158
|
-
|
159
|
-
def to_s
|
160
|
-
Megam::Stuff.styled_hash(to_hash)
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
end
|
data/test/test_appdefns.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
-
|
3
|
-
class TestApps < MiniTest::Unit::TestCase
|
4
|
-
=begin
|
5
|
-
def test_post_appdefns
|
6
|
-
tmp_hash = {
|
7
|
-
"node_name" => "black1.megam.co",
|
8
|
-
"appdefns" => {"timetokill" => "test1", "metered" => "test1", "logging" => "test1", "runtime_exec" => "test", "env_sh" => "changed env_sh"}
|
9
|
-
}
|
10
|
-
response = megams.post_appdefn(tmp_hash)
|
11
|
-
assert_equal(201, response.status)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_get_appdefns_node
|
15
|
-
response = megams.get_appdefn("black1.megam.co")
|
16
|
-
assert_equal(200, response.status)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_get_appdefns
|
20
|
-
response = megams.get_appdefn("asphyxiated1.megam.co","ADF412857952341327872")
|
21
|
-
assert_equal(200, response.status)
|
22
|
-
end
|
23
|
-
=end
|
24
|
-
def test_post_appdefns
|
25
|
-
tmp_hash = {
|
26
|
-
"appdefn_id" => "ADF456016953832636416",
|
27
|
-
"node_name" => "appsample1.megam.co",
|
28
|
-
"runtime_exec" => "test",
|
29
|
-
"env_sh" => "changed env_sh"
|
30
|
-
}
|
31
|
-
response = megams.update_appdefn(tmp_hash)
|
32
|
-
assert_equal(201, response.status)
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
data/test/test_appreqs.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
-
|
3
|
-
class TestApps < MiniTest::Unit::TestCase
|
4
|
-
def test_post_appreqs
|
5
|
-
|
6
|
-
tmp_hash = {
|
7
|
-
"req_type" => "NStart",
|
8
|
-
"node_name" => "black1.megam.co",
|
9
|
-
"appdefns_id" => "12455",
|
10
|
-
"lc_apply" => "APPly",
|
11
|
-
"lc_additional" => "ADDition",
|
12
|
-
"lc_when" => "When"
|
13
|
-
}
|
14
|
-
|
15
|
-
response = megams.post_appreq(tmp_hash)
|
16
|
-
assert_equal(201, response.status)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_get_appreqs
|
20
|
-
response = megams.get_appreq("oceanographer1.megam.co")
|
21
|
-
assert_equal(200, response.status)
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
end
|
data/test/test_boltdefns.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
-
|
3
|
-
class TestApps < MiniTest::Unit::TestCase
|
4
|
-
=begin
|
5
|
-
def test_post_boltdefns
|
6
|
-
|
7
|
-
tmp_hash = {
|
8
|
-
"node_name" => "black1.megam.co",
|
9
|
-
"boltdefns" => {"username" => "new", "apikey" => "new", "store_name" => "", "url" => "", "prime" => "", "timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => "", "env_sh" => "changed env_sh"}
|
10
|
-
}
|
11
|
-
|
12
|
-
response = megams.post_boltdefn(tmp_hash)
|
13
|
-
assert_equal(201, response.status)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_get_boltdefns
|
17
|
-
response = megams.get_boltdefn("black1.megam.co")
|
18
|
-
assert_equal(200, response.status)
|
19
|
-
end
|
20
|
-
=end
|
21
|
-
def test_post_boltdefns
|
22
|
-
tmp_hash = {
|
23
|
-
"boltdefn_id" => "BDF456048363326930944",
|
24
|
-
"node_name" => "appsample1.megam.co",
|
25
|
-
"runtime_exec" => "test",
|
26
|
-
"env_sh" => "changed env_sh"
|
27
|
-
}
|
28
|
-
response = megams.update_boltdefn(tmp_hash)
|
29
|
-
assert_equal(201, response.status)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/test/test_boltreqs.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
-
|
3
|
-
class TestApps < MiniTest::Unit::TestCase
|
4
|
-
|
5
|
-
def test_post_boltreqs
|
6
|
-
|
7
|
-
tmp_hash = {
|
8
|
-
"req_type" => "NStart",
|
9
|
-
"node_name" => "black1.megam.co",
|
10
|
-
"boltdefns_id" => "12455454",
|
11
|
-
"lc_apply" => "APPly",
|
12
|
-
"lc_additional" => "ADDition",
|
13
|
-
"lc_when" => "When"
|
14
|
-
}
|
15
|
-
|
16
|
-
response = megams.post_boltreq(tmp_hash)
|
17
|
-
assert_equal(201, response.status)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_get_boltreqs
|
21
|
-
response = megams.get_boltreq("black1.megam.co")
|
22
|
-
assert_equal(200, response.status)
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
end
|
data/test/test_cloudtools.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
-
|
3
|
-
class TestApps < MiniTest::Unit::TestCase
|
4
|
-
|
5
|
-
def test_get_cloudtools
|
6
|
-
response = megams.get_cloudtools
|
7
|
-
assert_equal(200, response.status)
|
8
|
-
end
|
9
|
-
=begin
|
10
|
-
def test_get_cloudtools1
|
11
|
-
response = megams.get_cloudtool("chef")
|
12
|
-
assert_equal(200, response.status)
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
def test_get_cloudtool_not_found
|
17
|
-
assert_raises(Megam::API::Errors::NotFound) do
|
18
|
-
megams.get_cloudtool("stupid.megam.co")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
=end
|
22
|
-
end
|
data/test/test_nodes.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
-
|
3
|
-
class TestApps < MiniTest::Unit::TestCase
|
4
|
-
|
5
|
-
=begin
|
6
|
-
def test_post_node1
|
7
|
-
@com = {
|
8
|
-
"systemprovider" => {
|
9
|
-
"provider" => {
|
10
|
-
"prov" => "chef"
|
11
|
-
}
|
12
|
-
},
|
13
|
-
"compute" => {
|
14
|
-
"cctype" => "ec2",
|
15
|
-
"cc" => {
|
16
|
-
"groups" => "megam",
|
17
|
-
"image" => "ami-d783cd85",
|
18
|
-
"flavor" => "t1.micro",
|
19
|
-
"tenant_id" => ""
|
20
|
-
},
|
21
|
-
"access" => {
|
22
|
-
"ssh_key" => "megam_ec2",
|
23
|
-
"identity_file" => "~/.ssh/megam_ec2.pem",
|
24
|
-
"ssh_user" => "ubuntu",
|
25
|
-
"vault_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/megam@mypaas.io/default",
|
26
|
-
"sshpub_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/megam@mypaas.io/default",
|
27
|
-
"zone" => "",
|
28
|
-
"region" => "region"
|
29
|
-
}
|
30
|
-
},
|
31
|
-
"cloudtool" => {
|
32
|
-
"chef" => {
|
33
|
-
"command" => "knife",
|
34
|
-
"plugin" => "ec2 server create -c megam@mypaas.io/default", #ec2 server delete or create
|
35
|
-
"run_list" => "role[opendj]",
|
36
|
-
"name" => "-N TestOverAll"
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
tmp_hash = {
|
42
|
-
"node_name" => "black.megam.co",
|
43
|
-
"node_type" => "APP", #APP or Bolt
|
44
|
-
"req_type" => "create", #CREATE OR DELETE
|
45
|
-
"noofinstances" => 2, # integer
|
46
|
-
"command" => @com,
|
47
|
-
"predefs" => {"name" => "rails", "scm" => "",
|
48
|
-
"db" => "postgres@postgresql1.megam.com/night.megam.co", "war" => "http://s3pub.com/0.1/granny.war", "queue" => "queue@queue1", "runtime_exec" => "sudo start rails"},
|
49
|
-
"appdefns" => {"timetokill" => "0", "metered" => "megam", "logging" => "megam", "runtime_exec" => "start unicorn_<projectname>", "env_sh" => "changed env_sh"},
|
50
|
-
"boltdefns" => {"username" => "", "apikey" => "", "store_name" => "", "url" => "", "prime" => "", "timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => "", "env_sh" => "changed env_sh"},
|
51
|
-
"appreq" => {},
|
52
|
-
"boltreq" => {}
|
53
|
-
}
|
54
|
-
|
55
|
-
response = megams.post_node(tmp_hash)
|
56
|
-
assert_equal(201, response.status)
|
57
|
-
end
|
58
|
-
=begin
|
59
|
-
def test_post_node2
|
60
|
-
tmp_hash = {
|
61
|
-
"node_name" => "sundown.megam.co",
|
62
|
-
"command" => "commands2",
|
63
|
-
"predefs" => {"name" => "rails", "scm" => "https://github.com/awesome.git",
|
64
|
-
"db" => "postgres@postgresql2.megam.com/morning.megam.co", "war" => "http://s3pub.com/0.1/orion.war", "queue" => "rabbit@queue1"}
|
65
|
-
}
|
66
|
-
response = megams.post_node(tmp_hash)
|
67
|
-
assert_equal(201, response.status)
|
68
|
-
end
|
69
|
-
=end
|
70
|
-
=begin
|
71
|
-
def test_get_nodes
|
72
|
-
response = megams.get_nodes
|
73
|
-
assert_equal(200, response.status)
|
74
|
-
end
|
75
|
-
=end
|
76
|
-
#=begin
|
77
|
-
def test_get_node0
|
78
|
-
response = megams.get_node("appsample1.megam.co")
|
79
|
-
assert_equal(200, response.status)
|
80
|
-
end
|
81
|
-
#=end
|
82
|
-
=begin
|
83
|
-
def test_get_node1
|
84
|
-
response = megams.get_node("night.megam.co")
|
85
|
-
assert_equal(200, response.status)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_get_node_not_found
|
89
|
-
assert_raises(Megam::API::Errors::NotFound) do
|
90
|
-
megams.get_node("stupid.megam.co")
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_delete_node1
|
95
|
-
|
96
|
-
@com = {
|
97
|
-
"systemprovider" => {
|
98
|
-
"provider" => {
|
99
|
-
"prov" => "chef"
|
100
|
-
}
|
101
|
-
},
|
102
|
-
"compute" => {
|
103
|
-
"cctype" => "ec2",
|
104
|
-
"cc" => {
|
105
|
-
"groups" => "",
|
106
|
-
"image" => "",
|
107
|
-
"flavor" => "",
|
108
|
-
"tenant_id" => ""
|
109
|
-
},
|
110
|
-
"access" => {
|
111
|
-
"ssh_key" => "megam_ec2",
|
112
|
-
"identity_file" => "~/.ssh/megam_ec2.pem",
|
113
|
-
"ssh_user" => "",
|
114
|
-
"vault_location" => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/megam@mypaas.io/default",
|
115
|
-
"sshpub_location" => "",
|
116
|
-
"zone" => "",
|
117
|
-
"region" => "region"
|
118
|
-
}
|
119
|
-
},
|
120
|
-
"cloudtool" => {
|
121
|
-
"chef" => {
|
122
|
-
"command" => "knife",
|
123
|
-
"plugin" => "ec2 server delete", #ec2 server delete or create
|
124
|
-
"run_list" => "",
|
125
|
-
"name" => ""
|
126
|
-
}
|
127
|
-
}
|
128
|
-
}
|
129
|
-
|
130
|
-
tmp_hash = {
|
131
|
-
"node_name" => "black1.megam.co",
|
132
|
-
"req_type" => "delete", #CREATE OR DELETE
|
133
|
-
"command" => @com
|
134
|
-
}
|
135
|
-
|
136
|
-
response = megams.post_request(tmp_hash)
|
137
|
-
assert_equal(201, response.status)
|
138
|
-
end
|
139
|
-
=end
|
140
|
-
end
|