lmc 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/encodings.xml +4 -0
- data/.rubocop.yml +3 -1
- data/PATTERNS.md +26 -0
- data/{README.md → README.rdoc} +0 -0
- data/Rakefile +30 -7
- data/coverage/.last_run.json +1 -1
- data/lib/lmc.rb +2 -3
- data/lib/lmc/Account.rb +44 -46
- data/lib/lmc/Cloud.rb +19 -13
- data/lib/lmc/Configstates.rb +3 -5
- data/lib/lmc/Device.rb +17 -23
- data/lib/lmc/Response.rb +2 -4
- data/lib/lmc/Site.rb +10 -21
- data/lib/lmc/User.rb +9 -11
- data/lib/lmc/account_manager.rb +28 -28
- data/lib/lmc/auth/auth_action.rb +2 -2
- data/lib/lmc/authority.rb +10 -9
- data/lib/lmc/config/device_config.rb +192 -0
- data/lib/lmc/config/device_dsc_ui.rb +93 -0
- data/lib/lmc/device_config_state.rb +0 -1
- data/lib/lmc/entity.rb +7 -8
- data/lib/lmc/exceptions/lmc_outdated_terms_of_use_exception.rb +2 -3
- data/lib/lmc/logger.rb +1 -1
- data/lib/lmc/membership.rb +4 -5
- data/lib/lmc/mixins/json_able.rb +2 -2
- data/lib/lmc/mixins/service_resource.rb +6 -5
- data/lib/lmc/monitoring/monitoring_record.rb +4 -4
- data/lib/lmc/principal.rb +8 -8
- data/lib/lmc/uuid.rb +16 -0
- data/lib/lmc/version.rb +1 -1
- data/lmc.gemspec +14 -13
- metadata +26 -8
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf28191aafd359f60cc8d8d3eb7b9c4ffb4ff6a
|
4
|
+
data.tar.gz: 109b27a7784b63820b94a63d04ca53174a59a687
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ce921af5e82516e865bb5241719f7efb09b90dfac67d6d82402ffa06bc4b27bd108735784b25cccff56e0c2193e8c8c198ad879d443b9ea723353b93bb0a1bc
|
7
|
+
data.tar.gz: db341afd04ed21951870cd9a982c27d0bf93eee1a9872dce292bc6c9f324e27d62ca66021709cb7d9a04a09d709f2ca1154bb7eec7cb18a22baece62f4775492
|
data/.idea/encodings.xml
ADDED
data/.rubocop.yml
CHANGED
data/PATTERNS.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Should establish
|
2
|
+
## URLs in ressource classes
|
3
|
+
Add methods to build urls
|
4
|
+
|
5
|
+
def url_configbuilder
|
6
|
+
['cloud-service-config', 'configbuilder', 'accounts',
|
7
|
+
@account.id, 'devices', @device.id, 'ui']
|
8
|
+
end
|
9
|
+
|
10
|
+
Not decided yet if private or public
|
11
|
+
|
12
|
+
## Parameter ordering for initialize methods
|
13
|
+
|
14
|
+
Library/API objects ordered from least to most specific.
|
15
|
+
Object specific data hashes go last.
|
16
|
+
|
17
|
+
### Embedding the Cloud object in ressources
|
18
|
+
* First parameter in initalizer
|
19
|
+
* Saved in @cloud instance var
|
20
|
+
* Should be exposed via getter (attr_reader)
|
21
|
+
|
22
|
+
It' is also okay to use Cloud object from parent object if a reasonable one is passed.
|
23
|
+
|
24
|
+
|
25
|
+
# Unsolved, bad
|
26
|
+
* Cloud http methods (get, etc.) return response object. 99% of the time, have to call .body on it
|
data/{README.md → README.rdoc}
RENAMED
File without changes
|
data/Rakefile
CHANGED
@@ -1,17 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
5
|
require 'rubocop/rake_task'
|
6
|
+
require 'rdoc/task'
|
6
7
|
|
7
8
|
Rake::TestTask.new(:test) do |t|
|
8
|
-
t.libs <<
|
9
|
-
t.libs <<
|
10
|
-
t.test_files = FileList[
|
9
|
+
t.libs << 'test'
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.test_files = FileList['test/**/*_test.rb']
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
14
|
RuboCop::RakeTask.new(:autocop) do |t|
|
15
|
-
|
15
|
+
autofix = [
|
16
|
+
'Layout/EmptyLines',
|
17
|
+
'Layout/EmptyLinesAroundClassBody',
|
18
|
+
'Layout/EmptyLinesAroundModuleBody',
|
19
|
+
'Layout/EmptyLineBetweenDefs',
|
20
|
+
'Layout/LeadingCommentSpace',
|
21
|
+
'Layout/SpaceAroundOperators',
|
22
|
+
'Layout/SpaceInsideBlockBraces',
|
23
|
+
'Layout/SpaceInsideHashLiteralBraces',
|
24
|
+
'Layout/TrailingBlankLines',
|
25
|
+
'Style/BracesAroundHashParameters',
|
26
|
+
'Style/CommentAnnotation',
|
27
|
+
'Style/FrozenStringLiteralComment',
|
28
|
+
'Style/MethodDefParentheses',
|
29
|
+
'Style/RedundantSelf',
|
30
|
+
'Style/RedundantReturn',
|
31
|
+
'Style/StringLiterals',
|
32
|
+
'Style/StringLiteralsInInterpolation']
|
33
|
+
t.options = ['--only', autofix.join(','), '--auto-correct', 'lib', 'test', 'Rakefile', 'lmc.gemspec']
|
16
34
|
end
|
17
35
|
task :default => :test
|
36
|
+
|
37
|
+
RDoc::Task.new do |rdoc|
|
38
|
+
rdoc.main = 'README.rdoc'
|
39
|
+
rdoc.rdoc_files.include('README.rdoc', 'lib/**/*.rb')
|
40
|
+
end
|
data/coverage/.last_run.json
CHANGED
data/lib/lmc.rb
CHANGED
@@ -11,7 +11,7 @@ module LMC
|
|
11
11
|
'cloud-service-licenses']
|
12
12
|
|
13
13
|
def self.useful
|
14
|
-
|
14
|
+
true
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -23,9 +23,8 @@ Dir.glob(File.expand_path('../lmc/*.rb', __FILE__)).each do |file|
|
|
23
23
|
require file
|
24
24
|
end
|
25
25
|
|
26
|
-
['exceptions', 'auth', 'monitoring'].each do |folder|
|
26
|
+
['exceptions', 'auth', 'config', 'monitoring'].each do |folder|
|
27
27
|
Dir.glob(File.expand_path("../lmc/#{folder}/*.rb", __FILE__)).each do |file|
|
28
28
|
require file
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
data/lib/lmc/Account.rb
CHANGED
@@ -10,17 +10,17 @@ module LMC
|
|
10
10
|
|
11
11
|
def self.get(id)
|
12
12
|
cloud = Cloud.instance
|
13
|
-
result = cloud.get [
|
14
|
-
|
13
|
+
result = cloud.get ['cloud-service-auth', 'accounts', id.to_s]
|
14
|
+
Account.new(cloud, result.body)
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.get_by_uuid
|
18
|
-
raise
|
19
|
-
|
17
|
+
def self.get_by_uuid(uuid)
|
18
|
+
raise 'Missing argument' if uuid.nil?
|
19
|
+
get uuid
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.get_by_name(name, type = nil)
|
23
|
-
raise
|
23
|
+
raise 'Missing argument' if name.nil?
|
24
24
|
accounts = Cloud.instance.get_accounts_objects.select do |a|
|
25
25
|
(name.nil? || a.name == name) && (type.nil? || a.type == type)
|
26
26
|
end
|
@@ -33,21 +33,21 @@ module LMC
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def initialize(data)
|
37
|
-
@cloud =
|
36
|
+
def initialize(cloud, data)
|
37
|
+
@cloud = cloud
|
38
38
|
apply_data(data)
|
39
39
|
end
|
40
40
|
|
41
|
-
#returns itself, allows chaining
|
41
|
+
# returns itself, allows chaining
|
42
42
|
def save
|
43
43
|
response = if @id.nil?
|
44
44
|
@cloud.auth_for_accounts [@parent]
|
45
|
-
@cloud.post [
|
45
|
+
@cloud.post ['cloud-service-auth', 'accounts'], self
|
46
46
|
else
|
47
47
|
@cloud.post path, self
|
48
48
|
end
|
49
49
|
apply_data(response.body)
|
50
|
-
|
50
|
+
self
|
51
51
|
end
|
52
52
|
|
53
53
|
def delete!
|
@@ -56,11 +56,11 @@ module LMC
|
|
56
56
|
delete_action = AuthAction.new @cloud
|
57
57
|
delete_action.type = AuthAction::ACCOUNT_DELETE
|
58
58
|
delete_action.name = Cloud.user
|
59
|
-
delete_action.data = {'password' => Cloud.password,
|
60
|
-
'accountId' => @id}
|
59
|
+
delete_action.data = { 'password' => Cloud.password,
|
60
|
+
'accountId' => @id }
|
61
61
|
delete_action.post
|
62
62
|
@id = nil
|
63
|
-
|
63
|
+
true
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -71,32 +71,32 @@ module LMC
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def members
|
74
|
-
ids = Cloud.instance.get [
|
74
|
+
ids = Cloud.instance.get ['cloud-service-auth', 'accounts', @id, 'members'], 'select' => 'id'
|
75
75
|
puts ids.inspect if Cloud.debug
|
76
76
|
principals = ids.map do |principal_id|
|
77
|
-
response = Cloud.instance.get [
|
77
|
+
response = Cloud.instance.get ['cloud-service-auth', 'accounts', @id, 'members', principal_id]
|
78
78
|
principal = response.body
|
79
79
|
puts principal.inspect if Cloud.debug
|
80
80
|
principal
|
81
81
|
end
|
82
|
-
|
82
|
+
principals
|
83
83
|
end
|
84
84
|
|
85
|
-
def find_member_by_name
|
86
|
-
members.find {|m| m.name == name}
|
85
|
+
def find_member_by_name(name)
|
86
|
+
members.find { |m| m.name == name }
|
87
87
|
end
|
88
88
|
|
89
|
-
#def update_member(principal_id, data)
|
89
|
+
# def update_member(principal_id, data)
|
90
90
|
# response = @cloud.post ["cloud-service-auth", "accounts", id, 'members', principal_id], data
|
91
91
|
# return response
|
92
|
-
#end
|
92
|
+
# end
|
93
93
|
|
94
94
|
def remove_membership(member_id)
|
95
|
-
@cloud.delete [
|
95
|
+
@cloud.delete ['cloud-service-auth', 'accounts', id, 'members', member_id]
|
96
96
|
end
|
97
97
|
|
98
98
|
def remove_membership_self
|
99
|
-
@cloud.delete [
|
99
|
+
@cloud.delete ['cloud-service-auth', 'accounts', id, 'members', 'self']
|
100
100
|
end
|
101
101
|
|
102
102
|
def authority(authority_id)
|
@@ -112,30 +112,29 @@ module LMC
|
|
112
112
|
authorities = response.body.map do |r|
|
113
113
|
Authority.new r, self
|
114
114
|
end
|
115
|
-
|
115
|
+
authorities
|
116
116
|
end
|
117
117
|
|
118
118
|
def children
|
119
|
-
@cloud.auth_for_accounts([
|
119
|
+
@cloud.auth_for_accounts([id, ROOT_ACCOUNT_UUID])
|
120
120
|
response = @cloud.get ['cloud-service-auth', 'accounts', id, 'children']
|
121
|
-
response.map {|child| Account.new child}
|
121
|
+
response.map { |child| Account.new @cloud, child }
|
122
122
|
end
|
123
123
|
|
124
|
-
|
125
124
|
def logs
|
126
125
|
# https://lmctest/cloud-service-logging/accounts/6392b234-b11c-498a-a077-a5f5b23c54a0/logs?lang=DE
|
127
126
|
cloud = Cloud.instance
|
128
127
|
cloud.auth_for_accounts [id]
|
129
|
-
cloud.get([
|
128
|
+
cloud.get(['cloud-service-logging', 'accounts', id, 'logs?lang=DE']).body
|
130
129
|
end
|
131
130
|
|
132
131
|
def sites
|
133
132
|
# private clouds can not have sites
|
134
|
-
return [] if @type ==
|
133
|
+
return [] if @type == 'PRIVATE_CLOUD'
|
135
134
|
@cloud.auth_for_accounts([id])
|
136
|
-
response = @cloud.get [
|
137
|
-
|
138
|
-
Site.new(data, self)
|
135
|
+
response = @cloud.get ['cloud-service-devices', 'accounts', id, 'sites'], {:select => :id}
|
136
|
+
response.body.map { |data|
|
137
|
+
Site.new(UUID.new(data), self)
|
139
138
|
}
|
140
139
|
end
|
141
140
|
|
@@ -145,16 +144,16 @@ module LMC
|
|
145
144
|
|
146
145
|
def config_updatestates
|
147
146
|
@cloud.auth_for_accounts([id])
|
148
|
-
response = @cloud.get [
|
149
|
-
|
147
|
+
response = @cloud.get ['cloud-service-config', 'configdevice', 'accounts', id, 'updatestates']
|
148
|
+
LMC::Configstates.new response.body
|
150
149
|
end
|
151
150
|
|
152
151
|
def to_json(*a)
|
153
152
|
{
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
153
|
+
'name' => @name,
|
154
|
+
'state' => @state,
|
155
|
+
'type' => @type,
|
156
|
+
'parent' => @parent
|
158
157
|
}.to_json(*a)
|
159
158
|
end
|
160
159
|
|
@@ -166,17 +165,16 @@ module LMC
|
|
166
165
|
|
167
166
|
## should be put into entity or such
|
168
167
|
def path
|
169
|
-
[
|
168
|
+
['cloud-service-auth', 'accounts', @id].join('/')
|
170
169
|
end
|
171
170
|
|
172
171
|
def apply_data(data)
|
173
|
-
@id = data[
|
174
|
-
@parent = data[
|
175
|
-
@name = data[
|
176
|
-
@state = data[
|
177
|
-
@type = data[
|
178
|
-
@identifier = data[
|
172
|
+
@id = data['id']
|
173
|
+
@parent = data['parent']
|
174
|
+
@name = data['name']
|
175
|
+
@state = data['state']
|
176
|
+
@type = data['type']
|
177
|
+
@identifier = data['identifier']
|
179
178
|
end
|
180
|
-
|
181
179
|
end
|
182
180
|
end
|
data/lib/lmc/Cloud.rb
CHANGED
@@ -12,9 +12,10 @@ module LMC
|
|
12
12
|
Cloud.verify_tls = true
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.instance(opts = {authorize: true})
|
16
|
-
@@inst ||=
|
15
|
+
def self.instance(opts = { authorize: true })
|
16
|
+
@@inst ||= new(@cloud_host, @user, @password, opts[:authorize])
|
17
17
|
end
|
18
|
+
|
18
19
|
attr_reader :auth_ok, :cloud_host, :user, :password
|
19
20
|
|
20
21
|
def initialize(cloud_host, user, pass, auth = true)
|
@@ -47,17 +48,17 @@ module LMC
|
|
47
48
|
result = get ['cloud-service-auth', 'accounts']
|
48
49
|
if result.code == 200
|
49
50
|
accounts = result.map do |aj|
|
50
|
-
Account.new(aj)
|
51
|
+
Account.new(self, aj)
|
51
52
|
end
|
52
53
|
else
|
53
54
|
raise "Unable to fetch accounts: #{result.body.message}"
|
54
55
|
end
|
55
56
|
|
56
|
-
|
57
|
+
accounts
|
57
58
|
end
|
58
59
|
|
59
60
|
def invite_user_to_account(email, account_id, type, authorities = [])
|
60
|
-
body = {name: email, state: 'ACTIVE', type: type}
|
61
|
+
body = { name: email, state: 'ACTIVE', type: type }
|
61
62
|
body['authorities'] = authorities
|
62
63
|
post ['cloud-service-auth', 'accounts', account_id, 'members'], body
|
63
64
|
end
|
@@ -117,26 +118,31 @@ module LMC
|
|
117
118
|
["#{protocol}://#{@cloud_host}", path_components].flatten.compact.join('/')
|
118
119
|
end
|
119
120
|
|
120
|
-
def auth_for_accounts(
|
121
|
-
|
122
|
-
authorize(account_ids)
|
121
|
+
def auth_for_accounts(accounts)
|
122
|
+
authorize(accounts)
|
123
123
|
end
|
124
124
|
|
125
125
|
def auth_for_account(account)
|
126
|
-
|
126
|
+
authorize([account])
|
127
127
|
end
|
128
128
|
|
129
129
|
def accept_tos(tos)
|
130
130
|
authorize([], tos)
|
131
131
|
end
|
132
132
|
|
133
|
-
|
134
133
|
private
|
135
134
|
|
136
|
-
def authorize(
|
135
|
+
def authorize(accounts = [], tos = [])
|
136
|
+
account_ids = accounts.map { |a|
|
137
|
+
if a.respond_to? :id
|
138
|
+
a.id
|
139
|
+
else
|
140
|
+
a
|
141
|
+
end
|
142
|
+
}
|
137
143
|
if account_ids != @last_authorized_account_ids
|
138
144
|
begin
|
139
|
-
reply = post(['cloud-service-auth', 'auth'],
|
145
|
+
reply = post(['cloud-service-auth', 'auth'], name: @user, password: @password, accountIds: account_ids, termsOfUse: tos)
|
140
146
|
puts 'authorize reply ' + reply.inspect if Cloud.debug
|
141
147
|
@last_authorized_account_ids = account_ids
|
142
148
|
@auth_token = reply
|
@@ -160,7 +166,7 @@ module LMC
|
|
160
166
|
if @auth_ok
|
161
167
|
headers[:Authorization] = auth_bearer
|
162
168
|
end
|
163
|
-
|
169
|
+
headers
|
164
170
|
end
|
165
171
|
|
166
172
|
def rest_options
|
data/lib/lmc/Configstates.rb
CHANGED
@@ -5,12 +5,10 @@ module LMC
|
|
5
5
|
attr_reader :actual, :outdated
|
6
6
|
|
7
7
|
def initialize(data)
|
8
|
-
@actual = data[
|
9
|
-
@outdated = data[
|
8
|
+
@actual = data['ACTUAL']
|
9
|
+
@outdated = data['OUTDATED']
|
10
10
|
@actual ||= 0
|
11
11
|
@outdated ||= 0
|
12
12
|
end
|
13
|
-
|
14
13
|
end
|
15
|
-
|
16
|
-
end
|
14
|
+
end
|
data/lib/lmc/Device.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module LMC
|
4
4
|
class Device
|
5
|
-
attr_reader :id, :name, :model, :serial, :heartbeatstate
|
5
|
+
attr_reader :id, :name, :model, :serial, :heartbeatstate, :cloud, :account, :status
|
6
6
|
|
7
7
|
def initialize(data)
|
8
8
|
@id = data['id']
|
@@ -17,51 +17,42 @@ module LMC
|
|
17
17
|
@cloud ||= Cloud.instance
|
18
18
|
end
|
19
19
|
|
20
|
-
def get_config_for_account(account)
|
21
|
-
response = @cloud.get ["cloud-service-config", "configbuilder", "accounts", account.id, "devices", @id, "ui"]
|
22
|
-
JSON.parse(JSON.generate(response.body.to_h)) #terrible hack to get it to work for now. needs way to get more raw body_object from Response
|
23
|
-
end
|
24
|
-
|
25
20
|
def set_config_for_account(config, account)
|
26
|
-
@cloud.put [
|
21
|
+
@cloud.put ['cloud-service-config', 'configbuilder', 'accounts', account.id, 'devices', @id, 'ui'], config
|
27
22
|
end
|
28
23
|
|
29
24
|
def get_monitor_widgets(widget_item_ids)
|
30
|
-
@cloud.get [
|
25
|
+
@cloud.get ['cloud-service-monitoring', @account.id, 'devices', @id, 'monitordata'], :widgetItemIds => widget_item_ids.join(',')
|
31
26
|
end
|
32
27
|
|
33
28
|
def self.get_for_account(account)
|
34
29
|
cloud = Cloud.instance
|
35
30
|
cloud.auth_for_accounts [account.id]
|
36
|
-
list = cloud.get [
|
31
|
+
list = cloud.get ['cloud-service-devices', 'accounts', account.id, 'devices']
|
37
32
|
if list.code != 200
|
38
33
|
puts "Error getting devices: #{list.body.message}"
|
39
34
|
exit 1
|
40
35
|
end
|
41
36
|
devices = list.map do |data|
|
42
|
-
data[
|
37
|
+
data['account'] = account
|
43
38
|
LMC::Device.new(data)
|
44
39
|
end
|
45
|
-
|
40
|
+
devices
|
46
41
|
end
|
47
42
|
|
48
43
|
def self.get_for_account_id(account_id)
|
49
|
-
|
44
|
+
get_for_account Account.get(account_id)
|
50
45
|
end
|
51
46
|
|
52
47
|
def config_state
|
53
48
|
@config_state ||= get_config_state
|
54
49
|
end
|
55
50
|
|
56
|
-
def
|
57
|
-
|
58
|
-
#cloud = Cloud.instance
|
59
|
-
##cloud.auth_for_accounts [id]
|
60
|
-
#cloud.get ["cloud-service-logging", "accounts", id, "logs?lang=DE"]
|
61
|
-
raise "device logs not supported"
|
51
|
+
def config
|
52
|
+
LMC::DeviceConfig.new(@cloud, @account, self)
|
62
53
|
end
|
63
54
|
|
64
|
-
def record
|
55
|
+
def record(name)
|
65
56
|
MonitoringRecord.new(@cloud, @account, self, name)
|
66
57
|
end
|
67
58
|
|
@@ -69,17 +60,20 @@ module LMC
|
|
69
60
|
'DEVICE'
|
70
61
|
end
|
71
62
|
|
63
|
+
def hwmask_hex
|
64
|
+
format format '%#010x', status['hwMask']
|
65
|
+
end
|
66
|
+
|
72
67
|
private
|
73
68
|
|
69
|
+
##
|
70
|
+
# TODO: This functionality is now duplicated in the DeviceConfig class and it's worse there.
|
74
71
|
def get_config_state
|
75
|
-
reply = @cloud.get [
|
72
|
+
reply = @cloud.get ['cloud-service-config', 'configdevice', 'accounts', @account.id, 'state'], 'deviceIds' => @id
|
76
73
|
if reply.code == 200
|
77
74
|
# binding.pry
|
78
75
|
DeviceConfigState.new reply.body[@id]
|
79
76
|
end
|
80
77
|
end
|
81
|
-
|
82
|
-
|
83
78
|
end
|
84
|
-
|
85
79
|
end
|