megam_api 0.22 → 0.23

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: 3467375fa08dc63c609b5eed5d8bfb802909db30
4
- data.tar.gz: 588347a1fed3837f843a64e091b5003046d9194a
3
+ metadata.gz: ed8e85c99104ae0dbc964b06fac754abeb9170e0
4
+ data.tar.gz: 898bb08d102dfd8b7c893d58fcf0333b3583d089
5
5
  SHA512:
6
- metadata.gz: ac270c67423b416c1dd629ba5d935d9017ff5b1e4bc2874e62d36ced26a20e5af7fa426d0d0f73222f71e5537f561348e75871cadab2732dff69cc6a342a4f60
7
- data.tar.gz: 641bfcb0720e77772b11732afa8d19711f3e662c1cdf5f584013cfe664c103e18ce1be2eb31f606877d7dcf0f630a56937930eaf4acc95604222a47f0e2b0b8d
6
+ metadata.gz: 2a6e66718f6d8eb1c8a0c9092d97d1c40224f504793db9284eb3db638670762df74d9c6a7c3522881a27340ef025011eaa6b158579db07d1241ef6d924519c22
7
+ data.tar.gz: be916ffcea604388b8fe46a7e367c7b723b73ccce0955d95f0ca3eec30dbfc62787f58595c7c5aac47453cfd5eea591005e4b5fcf2e46e9108ff8f15eeb4ab8e
data/lib/megam/api.rb CHANGED
@@ -54,6 +54,7 @@ require "megam/core/marketplace_collection"
54
54
  require "megam/core/marketplace_addon"
55
55
  require "megam/core/marketplace_addon_collection"
56
56
  require "megam/core/organizations"
57
+ require "megam/core/organizations_collection"
57
58
  require "megam/core/domains"
58
59
  require "megam/core/assemblies"
59
60
  require "megam/core/assemblies_collection"
@@ -1,5 +1,5 @@
1
1
  module Megam
2
2
  class API
3
- VERSION = "0.22"
3
+ VERSION = "0.23"
4
4
  end
5
5
  end
@@ -34,6 +34,7 @@ module Megam
34
34
  MEGAM_REQUEST = "Megam::Request".freeze
35
35
  MEGAM_REQUESTCOLLECTION = "Megam::RequestCollection".freeze
36
36
  MEGAM_ORGANIZATION = "Megam::Organizations".freeze
37
+ MEGAM_ORGANIZATIONSCOLLECTION = "Megam::OrganizationsCollection".freeze
37
38
  MEGAM_DOMAIN = "Megam::Domains".freeze
38
39
  MEGAM_APPREQUEST = "Megam::AppRequest".freeze
39
40
  MEGAM_APPREQUESTCOLLECTION = "Megam::AppRequestCollection".freeze
@@ -167,6 +168,8 @@ module Megam
167
168
  Megam::MarketPlaceAddonsCollection
168
169
  when MEGAM_ORGANIZATION
169
170
  Megam::Organizations
171
+ when MEGAM_ORGANIZATIONSCOLLECTION
172
+ Megam::OrganizationsCollection
170
173
  when MEGAM_CSAR
171
174
  Megam::CSAR
172
175
  when MEGAM_CSARCOLLECTION
@@ -0,0 +1,168 @@
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 OrganizationsCollection
18
+ include Enumerable
19
+
20
+ attr_reader :iterator
21
+ def initialize
22
+ @organizations = Array.new
23
+ @organizations_by_name = Hash.new
24
+ @insert_after_idx = nil
25
+ end
26
+
27
+ def all_organizations
28
+ @organizations
29
+ end
30
+
31
+ def [](index)
32
+ @organizations[index]
33
+ end
34
+
35
+ def []=(index, arg)
36
+ is_megam_organizations(arg)
37
+ @organizations[index] = arg
38
+ @organizations_by_name[arg.name] = index
39
+ end
40
+
41
+ def <<(*args)
42
+ args.flatten.each do |a|
43
+ is_megam_organizations(a)
44
+ @organizations << a
45
+ @organizations_by_name[a.name] =@organizations.length - 1
46
+ end
47
+ self
48
+ end
49
+
50
+ # 'push' is an alias method to <<
51
+ alias_method :push, :<<
52
+
53
+ def insert(organizations)
54
+ is_megam_organizations(organizations)
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
+ # predefclouds
59
+ @organizations.insert(@insert_after_idx + 1, organizations)
60
+ # update name -> location mappings and register new predefclouds
61
+ @organizations_by_name.each_key do |key|
62
+ @organizations_by_name[key] += 1 if@organizations_by_name[key] > @insert_after_idx
63
+ end
64
+ @organizations_by_name[organizations.name] = @insert_after_idx + 1
65
+ @insert_after_idx += 1
66
+ else
67
+ @organizations << organizations
68
+ @organizations_by_name[organizations.name] =@organizations.length - 1
69
+ end
70
+ end
71
+
72
+ def each
73
+ @organizations.each do |organizations|
74
+ yield organizations
75
+ end
76
+ end
77
+
78
+ def each_index
79
+ @organizations.each_index do |i|
80
+ yield i
81
+ end
82
+ end
83
+
84
+ def empty?
85
+ @organizations.empty?
86
+ end
87
+
88
+ def lookup(organizations)
89
+ lookup_by = nil
90
+ if organizations.kind_of?(Megam::Organizations)
91
+ lookup_by = organizations.name
92
+ elsif organizations.kind_of?(String)
93
+ lookup_by = organizations
94
+ else
95
+ raise ArgumentError, "Must pass a Megam::PredefClouds or String to lookup"
96
+ end
97
+ res =@organizations_by_name[lookup_by]
98
+ unless res
99
+ raise ArgumentError, "Cannot find a predefclouds matching #{lookup_by} (did you define it first?)"
100
+ end
101
+ @organizations[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 |organizations|
108
+ index_hash[organizations.name] = organizations.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::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
+ def self.json_create(o)
144
+ collection = self.new()
145
+ o["results"].each do |organizations_list|
146
+ organizations_array = organizations_list.kind_of?(Array) ? organizations_list : [ organizations_list ]
147
+ organizations_array.each do |organizations|
148
+ collection.insert(organizations)
149
+ end
150
+ end
151
+ collection
152
+ end
153
+
154
+ private
155
+
156
+ def is_megam_organizations(arg)
157
+ unless arg.kind_of?(Megam::Organizations)
158
+ raise ArgumentError, "Members must be Megam::Organizations's"
159
+ end
160
+ true
161
+ end
162
+
163
+ def to_s
164
+ Megam::Stuff.styled_hash(to_hash)
165
+ end
166
+
167
+ end
168
+ end
@@ -7,15 +7,10 @@ class TestOrganizations < MiniTest::Unit::TestCase
7
7
  $tom_email = "tom@gomegam.com"
8
8
  $bob_email = "bob@gomegam.com"
9
9
 
10
- def test_get_organizations_good1
11
- response =megams.get_organizations
12
- response.body.to_s
13
- assert_equal(200, response.status)
14
- end
15
10
 
16
- =begin
17
-
18
11
 
12
+
13
+ =begin
19
14
  def test_get_organizations_good
20
15
  response =megams.get_organization(sandbox_name)
21
16
  response.body.to_s
@@ -25,10 +20,16 @@ class TestOrganizations < MiniTest::Unit::TestCase
25
20
 
26
21
  def test_post_organizations_good
27
22
  tmp_hash = {
28
- "name" => "orgname3"}
23
+ "name" => "org.megam"}
29
24
  response =megams.post_organization(tmp_hash)
30
25
  response.body.to_s
31
26
  assert_equal(201, response.status)
32
27
  end
33
- =end
28
+ =end
29
+
30
+ def test_get_organizations_good1
31
+ response =megams.get_organizations
32
+ assert_equal(200, response.status)
33
+ end
34
+
34
35
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
2
 
3
3
  class TestApps < MiniTest::Unit::TestCase
4
-
4
+ =begin
5
5
  def test_post_predefcloud1
6
6
  tmp_hash = { :name => "aws_ec2_predef_medium", :spec => {
7
7
  :type_name => "aws-ec2",
@@ -26,6 +26,8 @@ class TestApps < MiniTest::Unit::TestCase
26
26
  response = megams.post_predefcloud(tmp_hash)
27
27
  assert_equal(201, response.status)
28
28
  end
29
+ =end
30
+ =begin
29
31
  #=end
30
32
  def test_post_predefcloud2
31
33
  tmp_hash = { :name => "rkspce_sundown_play", :spec => {
@@ -50,7 +52,7 @@ class TestApps < MiniTest::Unit::TestCase
50
52
  response = megams.post_predefcloud(tmp_hash)
51
53
  assert_equal(201, response.status)
52
54
  end
53
-
55
+ =end
54
56
  #=begin
55
57
 
56
58
  def test_get_predefclouds
@@ -58,7 +60,7 @@ class TestApps < MiniTest::Unit::TestCase
58
60
  assert_equal(200, response.status)
59
61
  end
60
62
  #=end
61
-
63
+ =begin
62
64
  def test_get_predefcloud2
63
65
  response = megams.get_predefcloud("rkspce_sundown_play")
64
66
  assert_equal(200, response.status)
@@ -74,6 +76,6 @@ assert_raises(Megam::API::Errors::NotFound) do
74
76
  megams.get_predefcloud("stupid.megam.co")
75
77
  end
76
78
  end
77
- #=end
79
+ =end
78
80
  end
79
81
 
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.22'
4
+ version: '0.23'
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-10-25 00:00:00.000000000 Z
11
+ date: 2014-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -172,6 +172,7 @@ files:
172
172
  - lib/megam/core/marketplace_collection.rb
173
173
  - lib/megam/core/monologger.rb
174
174
  - lib/megam/core/organizations.rb
175
+ - lib/megam/core/organizations_collection.rb
175
176
  - lib/megam/core/predefcloud.rb
176
177
  - lib/megam/core/predefcloud_collection.rb
177
178
  - lib/megam/core/request.rb