megam_api 0.7.9 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 770ab35153e2d560927412af49b8394e6558f46f
4
- data.tar.gz: d56bc2b84f1d9bfe2aaa14f0486fa6751c7854d3
3
+ metadata.gz: c0001f507173e65034c03d8b4e2ddc93e856aff4
4
+ data.tar.gz: 43137c2ac2f362c21f0561b3d90cef17dd380301
5
5
  SHA512:
6
- metadata.gz: 9b78257ac885ba2190f3fb2e461b7bd144d8a16e62c1198f195ae74f7ff333bbdf2615c5b5c5af94983745c7465a4526ec2b5952d6eaf1dd629c77d51d16ea6b
7
- data.tar.gz: eda1bbd9afed71d9e3b2f86d22e6fc5dc468e846bef41bebdd88c80c4216ae9b4ad0796970b3ada412bf5014cef7398df33afa045c2682632b0b16909c4db4bb
6
+ metadata.gz: 3b7cb2d6fd275d8dc21546bf058e2d8c6a1a9efe5c5d4c46132df4bc46a4b30db05b0bd269690a1071a0d4bf6c4447c1442270afb3dd330542b5d1ac17eda33e
7
+ data.tar.gz: b7b73b4252f19260679771c83e42400011bf3d778c091b2e1a39ad5fb80bc8cbf285584cfd2b18c23775c11a1908805469185a9366679b83fe11e92024703d17
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "0.7.9"
3
+ VERSION = "0.8.0"
4
4
  end
5
5
  end
data/lib/megam/api.rb CHANGED
@@ -27,6 +27,7 @@ require "megam/api/predefs"
27
27
  require "megam/api/predef_clouds"
28
28
  require "megam/api/cloud_tools"
29
29
  require "megam/api/cloud_tool_settings"
30
+ require "megam/api/sshkeys"
30
31
  require "megam/core/server_api"
31
32
  require "megam/core/config"
32
33
  require "megam/core/stuff"
@@ -63,6 +64,8 @@ require "megam/core/cloudinstruction_collection"
63
64
  require "megam/core/cloudinstruction"
64
65
  require "megam/core/cloudtoolsetting"
65
66
  require "megam/core/cloudtoolsetting_collection"
67
+ require "megam/core/sshkey"
68
+ require "megam/core/sshkey_collection"
66
69
 
67
70
  #we may nuke logs out of the api
68
71
  #require "megam/api/logs"
@@ -49,10 +49,10 @@ module Megam
49
49
  ci_command = "#{cloud_instruction.command}"
50
50
  if ci_command["<node_name>"].present?
51
51
  ci_command["<node_name>"] = "#{data[:node_name]}"
52
- end
53
- if ci_command["-c"].present?
54
- ci_command["-c"] = "-c #{cts.conf_location}"
55
52
  end
53
+ if ci_command["-c"].present?
54
+ ci_command["-c"] = "-c #{cts.conf_location}"
55
+ end
56
56
  command_hash = {
57
57
  "systemprovider" => {
58
58
  "provider" => {
@@ -100,7 +100,7 @@ module Megam
100
100
  "noofinstances" => data[:no_of_instances],
101
101
  "command" => command_hash,
102
102
  "predefs" => {"name" => data[:predef_name], "scm" => "#{data[:deps_scm]}",
103
- "db" => "postgres@postgresql1.megam.com/morning.megam.co", "war" => "#{data[:deps_war]}", "queue" => "queue@queue1", "runtime_exec" => data[:runtime_exec]},
103
+ "db" => "postgres@postgresql1.megam.com/morning.megam.co", "war" => "#{data[:deps_war]}", "queue" => "queue@queue1", "runtime_exec" => data[:runtime_exec]},
104
104
  "appdefns" => {"timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => ""},
105
105
  "boltdefns" => {"username" => "", "apikey" => "", "store_name" => "", "url" => "", "prime" => "", "timetokill" => "", "metered" => "", "logging" => "", "runtime_exec" => ""},
106
106
  "appreq" => {},
@@ -51,6 +51,8 @@ module Megam
51
51
  MEGAM_CLOUDINSTRUCTION = "Megam::CloudInstruction".freeze
52
52
  MEGAM_CLOUDINSTRUCTIONCOLLECTION = "Megam::CloudInstructionCollection".freeze
53
53
  MEGAM_CLOUDINSTRUCTIONGROUP = "Megam::CloudInstructionGroup".freeze
54
+ MEGAM_SSHKEY = "Megam::SshKey".freeze
55
+ MEGAM_SSHKEYCOLLECTION = "Megam::SshKeyCollection".freeze
54
56
  class <<self
55
57
  # Increase the max nesting for JSON, which defaults
56
58
  # to 19, and isn't enough for some (for example, a Node within a Node)
@@ -179,6 +181,10 @@ module Megam
179
181
  Megam::CloudInstructionGroup
180
182
  when MEGAM_CLOUDINSTRUCTIONCOLLECTION
181
183
  Megam::CloudInstructionCollection
184
+ when MEGAM_SSHKEY
185
+ Megam::SshKey
186
+ when MEGAM_SSHKEYCOLLECTION
187
+ Megam::SshKeyCollection
182
188
  else
183
189
  raise JSON::ParserError, "Unsupported `json_class` type '#{json_class}'"
184
190
  end
@@ -0,0 +1,176 @@
1
+
2
+ # Copyright:: Copyright (c) 2012, 2013 Megam Systems
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module Megam
18
+ class SshKey < Megam::ServerAPI
19
+ def initialize(email=nil, api_key=nil)
20
+ @id = nil
21
+ @name = nil
22
+ @accounts_id = nil
23
+ @path=nil
24
+ @created_at = nil
25
+ @some_msg = {}
26
+ super(email, api_key)
27
+ end
28
+
29
+ def sshkey
30
+ self
31
+ end
32
+
33
+
34
+ def id(arg=nil)
35
+ if arg != nil
36
+ @id = arg
37
+ else
38
+ @id
39
+ end
40
+ end
41
+
42
+ def name(arg=nil)
43
+ if arg != nil
44
+ @name = arg
45
+ else
46
+ @name
47
+ end
48
+ end
49
+
50
+ def accounts_id(arg=nil)
51
+ if arg != nil
52
+ @accounts_id= arg
53
+ else
54
+ @accounts_id
55
+ end
56
+ end
57
+
58
+
59
+ def path(arg=nil)
60
+ if arg != nil
61
+ @path= arg
62
+ else
63
+ @path
64
+ end
65
+ end
66
+
67
+ def created_at(arg=nil)
68
+ if arg != nil
69
+ @created_at = arg
70
+ else
71
+ @created_at
72
+ end
73
+ end
74
+
75
+ def some_msg(arg=nil)
76
+ if arg != nil
77
+ @some_msg = arg
78
+ else
79
+ @some_msg
80
+ end
81
+ end
82
+
83
+ def error?
84
+ crocked = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
85
+ end
86
+
87
+ # Transform the ruby obj -> to a Hash
88
+ def to_hash
89
+ index_hash = Hash.new
90
+ index_hash["json_claz"] = self.class.name
91
+ index_hash["id"] = id
92
+ index_hash["name"] = name
93
+ index_hash["accounts_id"] = accounts_id
94
+ index_hash["path"] = path
95
+ index_hash["created_at"] = created_at
96
+ index_hash
97
+ end
98
+
99
+ # Serialize this object as a hash: called from JsonCompat.
100
+ # Verify if this called from JsonCompat during testing.
101
+ def to_json(*a)
102
+ for_json.to_json(*a)
103
+ end
104
+
105
+ def for_json
106
+ result = {
107
+ "id" => id,
108
+ "name" => name,
109
+ "accounts_id" => accounts_id,
110
+ "path" => path,
111
+ "created_at" => created_at
112
+ }
113
+ result
114
+ end
115
+
116
+ #
117
+ def self.json_create(o)
118
+ sshKey = new
119
+ sshKey.id(o["id"]) if o.has_key?("id")
120
+ sshKey.name(o["name"]) if o.has_key?("name")
121
+ sshKey.path(o["path"]) if o.has_key?("path")
122
+ sshKey.created_at(o["created_at"]) if o.has_key?("created_at")
123
+ #success or error
124
+ sshKey.some_msg[:code] = o["code"] if o.has_key?("code")
125
+ sshKey.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
126
+ sshKey.some_msg[:msg]= o["msg"] if o.has_key?("msg")
127
+ sshKey.some_msg[:links] = o["links"] if o.has_key?("links")
128
+ sshKey
129
+ end
130
+
131
+ def self.from_hash(o,tmp_email=nil, tmp_api_key=nil)
132
+ sshKey = self.new(tmp_email, tmp_api_key)
133
+ sshKey.from_hash(o)
134
+ sshKey
135
+ end
136
+
137
+ def from_hash(o)
138
+ @id = o[:id] if o.has_key?(:id)
139
+ @name = o[:name] if o.has_key?(:name)
140
+ @path = o[:path] if o.has_key?(:path)
141
+ @created_at = o[:created_at] if o.has_key?(:created_at)
142
+ self
143
+ end
144
+
145
+ def self.create(o,tmp_email=nil, tmp_api_key=nil)
146
+ acct = from_hash(o,tmp_email, tmp_api_key)
147
+ acct.create
148
+ end
149
+
150
+ # Create the predef via the REST API
151
+ def create
152
+ megam_rest.post_sshkey(to_hash)
153
+ end
154
+
155
+ # Load all sshkeys -
156
+ # returns a sshkeysCollection
157
+ # don't return self. check if the Megam::SshKeyCollection is returned.
158
+ def self.list(tmp_email=nil, tmp_api_key=nil)
159
+ sshKey = self.new(tmp_email,tmp_api_key)
160
+ sshKey.megam_rest.get_sshkeys
161
+ end
162
+
163
+ # Show a particular sshKey by name,
164
+ # Megam::SshKey
165
+ def self.show(p_name,tmp_email=nil, tmp_api_key=nil)
166
+ pre = self.new(tmp_email,tmp_api_key)
167
+ pre.megam_rest.get_sshkey(p_name)
168
+ end
169
+
170
+ def to_s
171
+ Megam::Stuff.styled_hash(to_hash)
172
+ #"---> Megam::Account:[error=#{error?}]\n"+
173
+ end
174
+
175
+ end
176
+ end
@@ -0,0 +1,144 @@
1
+ # Copyright:: Copyright (c) 2012, 2013 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 SshKeyCollection
18
+ include Enumerable
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
26
+
27
+ def all_sshkeys
28
+ @sshkeys
29
+ end
30
+
31
+ def [](index)
32
+ @sshkeys[index]
33
+ end
34
+
35
+ def []=(index, arg)
36
+ is_megam_sshkeys(arg)
37
+ @sshkeys[index] = arg
38
+ @sshkeys_by_name[arg.name] = index
39
+ end
40
+
41
+ def <<(*args)
42
+ args.flatten.each do |a|
43
+ is_megam_sshkeys(a)
44
+ @sshkeys << a
45
+ @sshkeys_by_name[a.name] =@sshkeys.length - 1
46
+ end
47
+ self
48
+ end
49
+
50
+ # 'push' is an alias method to <<
51
+ alias_method :push, :<<
52
+
53
+ def insert(sshkeys)
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
63
+ 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
+
72
+ def each
73
+ @sshkeys.each do |sshkeys|
74
+ yield sshkeys
75
+ end
76
+ end
77
+
78
+ def each_index
79
+ @sshkeys.each_index do |i|
80
+ yield i
81
+ end
82
+ end
83
+
84
+ def empty?
85
+ @sshkeys.empty?
86
+ end
87
+
88
+ def lookup(sshkeys)
89
+ lookup_by = nil
90
+ if sshkeys.kind_of?(Megam::SshKey)
91
+ lookup_by = sshkeys.name
92
+ elsif sshkeys.kind_of?(String)
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
103
+
104
+ # Transform the ruby obj -> to a Hash
105
+ def to_hash
106
+ index_hash = Hash.new
107
+ self.each do |sshkeys|
108
+ index_hash[sshkeys.name] = sshkeys.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
+ def self.json_create(o)
120
+ collection = self.new()
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)
125
+ end
126
+ end
127
+ collection
128
+ end
129
+
130
+ private
131
+
132
+ def is_megam_sshkeys(arg)
133
+ unless arg.kind_of?(Megam::SshKey)
134
+ raise ArgumentError, "Members must be Megam::SshKeys's"
135
+ end
136
+ true
137
+ end
138
+
139
+ def to_s
140
+ Megam::Stuff.styled_hash(to_hash)
141
+ end
142
+
143
+ end
144
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ class TestApps < MiniTest::Unit::TestCase
4
+ def test_post_sshkey2
5
+ tmp_hash = { :name => "test_sample", :path => "https://s3-ap-southeast-1.amazonaws.com/cloudkeys/sandy@megamsandbox.com/default" }
6
+ response = megams.post_sshkey(tmp_hash)
7
+ assert_equal(201, response.status)
8
+ end
9
+
10
+ =begin
11
+ def test_get_sshkeys
12
+ response = megams.get_sshkeys
13
+ assert_equal(200, response.status)
14
+ end
15
+ =end
16
+ =begin
17
+ def test_get_sshkey2
18
+ response = megams.get_sshkey("rkspce_sundown_play")
19
+ assert_equal(200, response.status)
20
+ end
21
+ =end
22
+ =begin
23
+ def test_get_sshkey1
24
+ response = megams.get_sshkey("iaas_default")
25
+ assert_equal(200, response.status)
26
+ end
27
+
28
+ def test_get_sshkey_not_found
29
+ assert_raises(Megam::API::Errors::NotFound) do
30
+ megams.get_sshkey("stupid.megam.co")
31
+ end
32
+ end
33
+ =end
34
+ end
35
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megam_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.9
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kishorekumar Neelamegam, Thomas Alrin, Subash Sethurajan, Rajthilak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-17 00:00:00.000000000 Z
11
+ date: 2014-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -142,6 +142,7 @@ files:
142
142
  - lib/megam/api/predef_clouds.rb
143
143
  - lib/megam/api/predefs.rb
144
144
  - lib/megam/api/requests.rb
145
+ - lib/megam/api/sshkeys.rb
145
146
  - lib/megam/api/version.rb
146
147
  - lib/megam/builder/delete_node.rb
147
148
  - lib/megam/builder/make_node.rb
@@ -178,6 +179,8 @@ files:
178
179
  - lib/megam/core/request.rb
179
180
  - lib/megam/core/request_collection.rb
180
181
  - lib/megam/core/server_api.rb
182
+ - lib/megam/core/sshkey.rb
183
+ - lib/megam/core/sshkey_collection.rb
181
184
  - lib/megam/core/stuff.rb
182
185
  - lib/megam/core/text.rb
183
186
  - lib/megam/core/text_formatter.rb
@@ -197,6 +200,7 @@ files:
197
200
  - test/test_predefclouds.rb
198
201
  - test/test_predefs.rb
199
202
  - test/test_requests.rb
203
+ - test/test_sshkeys.rb
200
204
  homepage: http://github.com/indykish/megam_api
201
205
  licenses:
202
206
  - Apache V2