megam_api 0.75 → 0.77
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/lib/megam/api.rb +7 -8
- data/lib/megam/api/discounts.rb +2 -7
- data/lib/megam/api/errors.rb +4 -2
- data/lib/megam/api/sensors.rb +35 -0
- data/lib/megam/api/version.rb +1 -1
- data/lib/megam/core/json_compat.rb +21 -19
- data/lib/megam/core/promos.rb +6 -8
- data/lib/megam/core/request.rb +0 -1
- data/lib/megam/core/sensors.rb +157 -0
- data/lib/megam/core/sensors_collection.rb +143 -0
- data/lib/megam/mixins/assemblies.rb +17 -0
- data/lib/megam/mixins/assemblys.rb +42 -0
- data/lib/megam/mixins/common_deployable.rb +72 -0
- data/lib/megam/mixins/components.rb +85 -0
- data/lib/megam/mixins/megam_attributes.rb +30 -0
- data/lib/megam/mixins/outputs.rb +24 -0
- data/lib/megam/mixins/policies.rb +29 -0
- data/test/mixins/test_assemblies.rb +110 -0
- data/test/mixins/test_assembly.rb +74 -0
- data/test/mixins/test_component.rb +56 -0
- data/test/test_helper.rb +5 -5
- data/test/test_invoices.rb +1 -1
- data/test/test_sensors.rb +50 -0
- metadata +20 -8
- data/lib/megam/api/event.rb +0 -23
- data/lib/megam/core/event.rb +0 -145
- data/test/test_event.rb +0 -21
- data/test/test_logs.rb +0 -15
@@ -0,0 +1,143 @@
|
|
1
|
+
##
|
2
|
+
## Copyright [2013-2015] [Megam Systems]
|
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 SensorsCollection
|
18
|
+
include Enumerable
|
19
|
+
|
20
|
+
attr_reader :iterator
|
21
|
+
def initialize
|
22
|
+
@sensors = []
|
23
|
+
@sensors_by_name = {}
|
24
|
+
@insert_after_idx = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_sensor
|
28
|
+
@sensors
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](index)
|
32
|
+
@sensors[index]
|
33
|
+
end
|
34
|
+
|
35
|
+
def []=(index, arg)
|
36
|
+
is_megam_sensors(arg)
|
37
|
+
@sensors[index] = arg
|
38
|
+
@sensors_by_name[arg.id] = index
|
39
|
+
end
|
40
|
+
|
41
|
+
def <<(*args)
|
42
|
+
args.flatten.each do |a|
|
43
|
+
is_megam_sensors(a)
|
44
|
+
@sensors << a
|
45
|
+
@sensors_by_name[a.id] = @sensors.length - 1
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# 'push' is an alias method to <<s
|
51
|
+
alias_method :push, :<<
|
52
|
+
|
53
|
+
def insert(sensors)
|
54
|
+
is_megam_sensors(sensors)
|
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
|
+
# sensors
|
59
|
+
@sensors.insert(@insert_after_idx + 1, sensors)
|
60
|
+
# update name -> location mappings and register new sensors
|
61
|
+
@sensors_by_name.each_key do |key|
|
62
|
+
@sensors_by_name[key] += 1 if@sensors_by_name[key] > @insert_after_idx
|
63
|
+
end
|
64
|
+
@sensors_by_name[sensors.id] = @insert_after_idx + 1
|
65
|
+
@insert_after_idx += 1
|
66
|
+
else
|
67
|
+
@sensors << sensors
|
68
|
+
@sensors_by_name[sensors.id] = @sensors.length - 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def each
|
73
|
+
@sensors.each do |sensors|
|
74
|
+
yield sensors
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def each_index
|
79
|
+
@sensors.each_index do |i|
|
80
|
+
yield i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def empty?
|
85
|
+
@sensors.empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
def lookup(sensors)
|
89
|
+
lookup_by = nil
|
90
|
+
if sensors.is_a?(Megam.sensors)
|
91
|
+
lookup_by = sensors.id
|
92
|
+
elsif sensors.is_a?(String)
|
93
|
+
lookup_by = sensors
|
94
|
+
else
|
95
|
+
fail ArgumentError, 'Must pass a Megam::sensors or String to lookup'
|
96
|
+
end
|
97
|
+
res = @sensors_by_name[lookup_by]
|
98
|
+
unless res
|
99
|
+
fail ArgumentError, "Cannot find a sensors matching #{lookup_by} (did you define it first?)"
|
100
|
+
end
|
101
|
+
@sensors[res]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Transform the ruby obj -> to a Hash
|
105
|
+
def to_hash
|
106
|
+
index_hash = {}
|
107
|
+
each do |sensors|
|
108
|
+
index_hash[sensors.id] = sensors.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 = new
|
121
|
+
o['results'].each do |sensors_list|
|
122
|
+
sensors_array = sensors_list.is_a?(Array) ? sensors_list : [sensors_list]
|
123
|
+
sensors_array.each do |sensors|
|
124
|
+
collection.insert(sensors)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
collection
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def is_megam_sensors(arg)
|
133
|
+
unless arg.is_a?(Megam::Sensors)
|
134
|
+
fail ArgumentError, "Members must be Megam::sensors's"
|
135
|
+
end
|
136
|
+
true
|
137
|
+
end
|
138
|
+
|
139
|
+
def to_s
|
140
|
+
Megam::Stuff.styled_hash(to_hash)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/common_deployable")
|
2
|
+
|
3
|
+
module Megam
|
4
|
+
class Mixins
|
5
|
+
class Assemblies
|
6
|
+
attr_reader :assemblys
|
7
|
+
|
8
|
+
def initialize(params)
|
9
|
+
@assemblys = CommonDeployable.new(params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_hash
|
13
|
+
{:assemblys => assemblys.to_hash}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/common_deployable")
|
2
|
+
require File.expand_path("#{File.dirname(__FILE__)}/components")
|
3
|
+
require File.expand_path("#{File.dirname(__FILE__)}/outputs")
|
4
|
+
|
5
|
+
module Megam
|
6
|
+
class Mixins
|
7
|
+
class Assemblys
|
8
|
+
attr_reader :components, :policies, :outputs, :mixins
|
9
|
+
|
10
|
+
def initialize(params)
|
11
|
+
params = Hash[params.map{ |k, v| [k.to_sym, v] }]
|
12
|
+
@mixins = CommonDeployable.new(params)
|
13
|
+
@outputs = Outputs.new(params)
|
14
|
+
@components = add_components(params)
|
15
|
+
@policies = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
result = @mixins.to_hash
|
20
|
+
result[:components] = @components if @components
|
21
|
+
result[:outputs] = @outputs.to_array if @outputs
|
22
|
+
result[:policies] = @policies if @policies
|
23
|
+
[result]
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
# If @components_enabled for type
|
28
|
+
def components_enabled?
|
29
|
+
true # enable if its not a TORPEDO
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_components(params)
|
33
|
+
unless components_enabled?
|
34
|
+
@components = Components.new(params)
|
35
|
+
else
|
36
|
+
@components = []
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/megam_attributes")
|
2
|
+
|
3
|
+
module Megam
|
4
|
+
class Mixins
|
5
|
+
class CommonDeployable
|
6
|
+
include Nilavu::MegamAttributes
|
7
|
+
attr_reader :assemblyname, :componentname, :status, :inputs, :tosca_type
|
8
|
+
|
9
|
+
DEFAULT_TOSCA_PREFIX = 'tosca'.freeze
|
10
|
+
# this is a mutable string, if nothing exists then we use ubuntu
|
11
|
+
DEFAULT_TOSCA_SUFFIX = 'ubuntu'.freeze
|
12
|
+
|
13
|
+
ATTRIBUTES = [
|
14
|
+
:assemblyname,
|
15
|
+
:componentname,
|
16
|
+
:tosca_type,
|
17
|
+
:status,
|
18
|
+
:inputs]
|
19
|
+
|
20
|
+
def attributes
|
21
|
+
ATTRIBUTES
|
22
|
+
end
|
23
|
+
def initialize(params)
|
24
|
+
@assemblyname = ""
|
25
|
+
@tosca_type = ""
|
26
|
+
@status = "launching"
|
27
|
+
bld_toscatype(params)
|
28
|
+
@inputs = InputGroupData.new(params)
|
29
|
+
set_attributes(params)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def to_hash
|
34
|
+
h = {
|
35
|
+
:name => assemblyname,
|
36
|
+
:status => status,
|
37
|
+
:tosca_type => tosca_type,
|
38
|
+
:inputs => inputs.to_hash
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def bld_toscatype(mkp)
|
43
|
+
tosca_suffix = DEFAULT_TOSCA_SUFFIX
|
44
|
+
tosca_suffix = "#{mkp[:mkp_name]}" unless mkp[:cattype] != 'TORPEDO'.freeze
|
45
|
+
@tosca_type = DEFAULT_TOSCA_PREFIX + ".#{mkp[:cattype].downcase}.#{mkp[:mkp_name].downcase}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class InputGroupData
|
50
|
+
include Nilavu::MegamAttributes
|
51
|
+
attr_reader :domain, :sshkey, :provider, :cpu, :ram, :hdd, :version, :display_name, :password
|
52
|
+
ATTRIBUTES = [
|
53
|
+
:domain,
|
54
|
+
:sshkey,
|
55
|
+
:provider,
|
56
|
+
:cpu,
|
57
|
+
:ram,
|
58
|
+
:hdd,
|
59
|
+
:version,
|
60
|
+
:display_name,
|
61
|
+
:password]
|
62
|
+
|
63
|
+
def attributes
|
64
|
+
ATTRIBUTES
|
65
|
+
end
|
66
|
+
|
67
|
+
def initialize(params)
|
68
|
+
set_attributes(params)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/megam_attributes")
|
2
|
+
module Megam
|
3
|
+
class Mixins
|
4
|
+
class Components
|
5
|
+
attr_reader :mixins, :repo, :related_components, :operations, :artifacts
|
6
|
+
|
7
|
+
def initialize(params)
|
8
|
+
@mixins = CommonDeployable.new(params)
|
9
|
+
@artifacts = Outputs.new(params)
|
10
|
+
add_repo(params)
|
11
|
+
add_operations(params)
|
12
|
+
add_related_components(params)
|
13
|
+
add_artifacts(params)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def add_repo(params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_related_components(params)
|
21
|
+
related_components = [ "#{params[:assemblyname]}.#{params[:domain]}/#{params[:componentname]}"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_operations(params)
|
25
|
+
create_operation(Operations.CI, Operations.CI_DESCRIPTON, [:type, :token, :username])
|
26
|
+
create_operation(Operations.BIND, Operations.BIND_DESCRIPTON, [:type, :token, :username])
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_operation(type, desc,properties)
|
30
|
+
Operations.new.add_operation(type, desc, properties)
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_artifacts(params)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Repo
|
38
|
+
include Nilavu::MegamAttributes
|
39
|
+
ATTRIBUTES = [
|
40
|
+
:type,
|
41
|
+
:source,
|
42
|
+
:oneclick,
|
43
|
+
:url]
|
44
|
+
|
45
|
+
def initialize(params)
|
46
|
+
set_attributes(params)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Operations
|
51
|
+
include Nilavu::MegamAttributes
|
52
|
+
ATTRIBUTES = []
|
53
|
+
|
54
|
+
CI = "ci".freeze
|
55
|
+
CI_DESCRIPTON = "always up to date code. sweet."
|
56
|
+
|
57
|
+
def initialize(params)
|
58
|
+
set_attributes(params)
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_operation(type, desc, properties)
|
62
|
+
ATTRIBUTES.merge(properties)
|
63
|
+
set_attributes(properties)
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_hash
|
67
|
+
#{ 'type' => 'ci',
|
68
|
+
# 'description' => 'Continous Integration',
|
69
|
+
# 'properties' => self.to_hash
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Artifacts
|
74
|
+
include Nilavu::MegamAttributes
|
75
|
+
ATTRIBUTES = [
|
76
|
+
:type,
|
77
|
+
:content,
|
78
|
+
:requirements]
|
79
|
+
|
80
|
+
def initialize(params)
|
81
|
+
set_attributes(params)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Nilavu
|
2
|
+
module MegamAttributes
|
3
|
+
ATTRIBUTES = []
|
4
|
+
KEY = "key".freeze
|
5
|
+
VALUE = "value".freeze
|
6
|
+
attr_accessor *ATTRIBUTES
|
7
|
+
|
8
|
+
def attributes
|
9
|
+
NotImplementedError
|
10
|
+
end
|
11
|
+
def initialize(control_data={})
|
12
|
+
set_attributes(control_data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_attributes(control_data)
|
16
|
+
#control_data.symbolize_keys!
|
17
|
+
#control_data = Hash[control_data.map{ |k, v| [k.to_sym, v] }]
|
18
|
+
attributes.each { |a| instance_variable_set("@#{a}", control_data[a]) unless control_data[a].nil? }
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
h = attributes.reduce([]) do |res, key|
|
23
|
+
val = instance_variable_get("@#{key}".to_sym)
|
24
|
+
res << { KEY => key.to_s, VALUE => val } unless val.nil?
|
25
|
+
res
|
26
|
+
end
|
27
|
+
h
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/megam_attributes")
|
2
|
+
module Megam
|
3
|
+
class Outputs
|
4
|
+
include Nilavu::MegamAttributes
|
5
|
+
|
6
|
+
attr_reader :nodeip, :publicip, :privateip, :lastsuccessfulupdate, :laststatus
|
7
|
+
|
8
|
+
ATTRIBUTES = [
|
9
|
+
]
|
10
|
+
|
11
|
+
def attributes
|
12
|
+
ATTRIBUTES
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(params)
|
16
|
+
set_attributes(params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_array
|
20
|
+
array = []
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Megam
|
2
|
+
class Mixins
|
3
|
+
class Policies
|
4
|
+
attr_reader :bind_type, :policymembers
|
5
|
+
|
6
|
+
def initialize(params)
|
7
|
+
@bind_type = params[:bind_type] if params.key?(:bind_type)
|
8
|
+
@policymembers = params[:policymembers] if params.key?(:policymembers)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_array
|
12
|
+
com = []
|
13
|
+
if @bind_type && @bind_type != 'Unbound service'
|
14
|
+
value = {
|
15
|
+
name: 'bind policy',
|
16
|
+
ptype: 'colocated',
|
17
|
+
members: [
|
18
|
+
@policymembers
|
19
|
+
]
|
20
|
+
}
|
21
|
+
com << value
|
22
|
+
end
|
23
|
+
com
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|