qtc-sdk 0.2.0 → 0.3.0

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +18 -18
  3. data/Changelog.md +14 -6
  4. data/Gemfile +4 -4
  5. data/LICENSE.txt +22 -22
  6. data/README.md +44 -44
  7. data/Rakefile +1 -1
  8. data/bin/qtc-cli +13 -13
  9. data/lib/qtc/cli/commands.rb +15 -15
  10. data/lib/qtc/cli/common.rb +146 -91
  11. data/lib/qtc/cli/eds/base.rb +27 -27
  12. data/lib/qtc/cli/eds/commands.rb +20 -20
  13. data/lib/qtc/cli/eds/instances.rb +30 -30
  14. data/lib/qtc/cli/mar/apps.rb +116 -125
  15. data/lib/qtc/cli/mar/base.rb +60 -60
  16. data/lib/qtc/cli/mar/commands.rb +221 -199
  17. data/lib/qtc/cli/mar/debug.rb +87 -86
  18. data/lib/qtc/cli/mar/domains.rb +35 -38
  19. data/lib/qtc/cli/mar/env.rb +38 -40
  20. data/lib/qtc/cli/mar/repository.rb +24 -26
  21. data/lib/qtc/cli/mar/ssl_certificates.rb +40 -42
  22. data/lib/qtc/cli/mar/stack.rb +29 -0
  23. data/lib/qtc/cli/mdb/base.rb +47 -43
  24. data/lib/qtc/cli/mdb/commands.rb +43 -31
  25. data/lib/qtc/cli/mdb/instances.rb +79 -60
  26. data/lib/qtc/cli/platform/clouds.rb +33 -15
  27. data/lib/qtc/cli/platform/commands.rb +132 -65
  28. data/lib/qtc/cli/platform/datacenters.rb +23 -21
  29. data/lib/qtc/cli/platform/ssh_keys.rb +41 -41
  30. data/lib/qtc/cli/platform/user.rb +25 -25
  31. data/lib/qtc/cli/platform/vpn.rb +93 -0
  32. data/lib/qtc/client.rb +170 -170
  33. data/lib/qtc/eds/client.rb +116 -116
  34. data/lib/qtc/eds/collection.rb +124 -124
  35. data/lib/qtc/eds/user_collection.rb +13 -13
  36. data/lib/qtc/eds/usergroup_collection.rb +41 -41
  37. data/lib/qtc/errors.rb +13 -11
  38. data/lib/qtc/version.rb +3 -3
  39. data/lib/qtc-sdk.rb +1 -1
  40. data/qtc-sdk.gemspec +28 -28
  41. data/spec/unit/qtc/client_spec.rb +147 -147
  42. metadata +20 -19
  43. data/lib/qtc/mws/client.rb +0 -89
@@ -1,30 +1,30 @@
1
- require_relative 'base'
2
-
3
- module Qtc
4
- module Cli
5
- class Eds::Instances < Eds::Base
6
-
7
- def list
8
- accounts = platform_client.get('/user/accounts')
9
- accounts['results'].each do |account|
10
- print color("== #{account['name']}: #{account['id']}", :cyan)
11
- instances = platform_client.get("/accounts/#{account['id']}/instances", {provider: 'eds'})
12
- instances['results'].each do |instance|
13
- say(" ~ <%= color('#{instance['id']}', :green) %> #{instance['name']} <%= color('#{instance['tags'].join(', ')}', :yellow) %>")
14
- end
15
- puts ''
16
- end
17
- end
18
-
19
- def create(cloud_id, name)
20
- data = {
21
- name: name,
22
- serviceProviderId: 'eds',
23
- datacenterId: options.datacenter || 'eu-1'
24
- }
25
- response = platform_client.post("/accounts/#{cloud_id}/instances", data)
26
- puts response['id']
27
- end
28
- end
29
- end
30
- end
1
+ require_relative 'base'
2
+
3
+ module Qtc
4
+ module Cli
5
+ class Eds::Instances < Eds::Base
6
+
7
+ def list
8
+ accounts = platform_client.get('/user/accounts')
9
+ accounts['results'].each do |account|
10
+ print color("== #{account['name']}: #{account['id']}", :cyan)
11
+ instances = platform_client.get("/accounts/#{account['id']}/instances", {provider: 'eds'})
12
+ instances['results'].each do |instance|
13
+ say(" ~ <%= color('#{instance['id']}', :green) %> #{instance['name']} <%= color('#{instance['tags'].join(', ')}', :yellow) %>")
14
+ end
15
+ puts ''
16
+ end
17
+ end
18
+
19
+ def create(cloud_id, name)
20
+ data = {
21
+ name: name,
22
+ serviceProviderId: 'eds',
23
+ datacenterId: options.datacenter || 'eu-1'
24
+ }
25
+ response = platform_client.post("/accounts/#{cloud_id}/instances", data)
26
+ puts response['id']
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,125 +1,116 @@
1
- require_relative 'base'
2
-
3
- module Qtc
4
- module Cli
5
- class Mar::Apps < Mar::Base
6
-
7
- def list
8
- accounts = platform_client.get('/user/accounts')
9
- accounts['results'].each do |account|
10
- instances = platform_client.get("/accounts/#{account['id']}/instances", {provider: 'mar'})
11
- if instances['results'].size > 0
12
- print color("== #{account['name']} (#{account['datacenter']['id']}): #{account['id']}")
13
- instances['results'].each do |instance|
14
- say(" ~ <%= color('#{instance['id']}', :green) %> #{instance['name']} <%= color('#{instance['tags'].join(', ')}', :yellow) %>")
15
- end
16
- puts ''
17
- end
18
- end
19
- end
20
-
21
- def show(options)
22
- instance_id = resolve_instance_id(options)
23
-
24
- instance_data = instance_info(instance_id)
25
- if instance_data
26
- token = instance_data['authorizations'][0]['access_token']
27
- result = client.get("/apps/#{instance_id}", nil, {'Authorization' => "Bearer #{token}"})
28
- puts "Id: #{result['id']}"
29
- puts "Name: #{result['name']}"
30
- puts "Size: #{size_mapping[result['size'].to_s] || result['size']}"
31
- puts "State: #{result['state']}"
32
- puts "Structure: #{JSON.pretty_generate(result['structure'])}"
33
- status = client.get("/apps/#{instance_id}/status", nil, {'Authorization' => "Bearer #{token}"})
34
- puts "Processes: #{JSON.pretty_generate(status['processes'])}"
35
- end
36
- end
37
-
38
- def create(cloud_id, name, options)
39
- sizes = {mini: 1, small: 2, medium: 4}
40
- size = sizes[options.size.to_s.to_sym] || 1
41
- data = {
42
- name: name,
43
- serviceProviderId: 'mar',
44
- config: {
45
- runtimeSize: size,
46
- runtimeType: 'app'
47
- }
48
- }
49
- response = platform_client.post("/accounts/#{cloud_id}/instances", data)
50
- puts response['id']
51
- end
52
-
53
- def restart(options)
54
- instance_id = resolve_instance_id(options)
55
- instance_data = instance_info(instance_id)
56
- if instance_data
57
- token = instance_data['authorizations'][0]['access_token']
58
- client.post("/apps/#{instance_id}/restart", {}, nil, {'Authorization' => "Bearer #{token}"})
59
- end
60
-
61
- end
62
-
63
- def logs(options)
64
- offset = options.offset || 0
65
- limit = options.limit || 100
66
- stream = options.stream || nil
67
-
68
- instance_id = resolve_instance_id(options)
69
- instance_data = instance_info(instance_id)
70
- if instance_data
71
- token = instance_data['authorizations'][0]['access_token']
72
- result = client.get("/apps/#{instance_id}/logs", {offset: offset, limit: limit}, {'Authorization' => "Bearer #{token}"})
73
- result['results'].each do |r|
74
- line = ''
75
- line << "[#{r['time']}] " if options.timestamp == true
76
- line << r['log']
77
- puts line
78
- end
79
- end
80
- end
81
-
82
- def scale(args, options)
83
- instance_id = resolve_instance_id(options)
84
- instance_data = instance_info(instance_id)
85
- if instance_data
86
- token = instance_data['authorizations'][0]['access_token']
87
- app = client.get("/apps/#{instance_id}", nil, {'Authorization' => "Bearer #{token}"})
88
- structure = app['structure']
89
- scale = {}
90
- args.each do |type|
91
- arr = type.strip.split("=")
92
- if arr[0] && arr[1]
93
- raise ArgumentError.new("#{arr[0]} is not defined in Procfile") unless structure.has_key?(arr[0])
94
- scale[arr[0]] = arr[1]
95
- end
96
- end
97
- client.post("/apps/#{instance_id}/scale", scale, {}, {'Authorization' => "Bearer #{token}"})
98
- end
99
- end
100
-
101
- def exec(command, options)
102
- instance_id = resolve_instance_id(options)
103
- instance_data = instance_info(instance_id)
104
- if instance_data
105
- token = instance_data['authorizations'][0]['access_token']
106
- data = {
107
- cmd: command,
108
- processId: options.process
109
- }
110
- result = client.post("/apps/#{instance_id}/exec", data, {}, {'Authorization' => "Bearer #{token}"})
111
- puts result['stdout']
112
- end
113
- end
114
-
115
- def size_mapping
116
- {
117
- '1' => 'mini',
118
- '2' => 'small',
119
- '4' => 'medium',
120
- '8' => 'large'
121
- }
122
- end
123
- end
124
- end
125
- end
1
+ require_relative 'base'
2
+
3
+ module Qtc
4
+ module Cli
5
+ class Mar::Apps < Mar::Base
6
+
7
+ def list
8
+ instances = platform_client(current_cloud_token).get("/accounts/#{current_cloud_id}/instances", {provider: 'mar'})
9
+ if instances['results'].size > 0
10
+ template = "%-20.20s %-30.30s %-20.20s"
11
+ puts template % ["ID", "NAME", "TAGS"]
12
+ instances['results'].each do |instance|
13
+ puts template % [instance['id'], instance['name'], instance['tags'].join(',')]
14
+ end
15
+ end
16
+ end
17
+
18
+ def show(options)
19
+ instance_id = resolve_instance_id(options)
20
+ result = client.get("/apps/#{instance_id}", nil, {'Authorization' => "Bearer #{current_cloud_token}"})
21
+ puts "Id: #{result['id']}"
22
+ puts "Name: #{result['name']}"
23
+ puts "Size: #{size_mapping[result['size'].to_s] || result['size']}"
24
+ puts "State: #{result['state']}"
25
+ puts "Custom SSL: #{result['sslCertificate'].nil? ? 'no': 'yes'}"
26
+ env_vars = client.get("/apps/#{instance_id}/env_vars", {}, {'Authorization' => "Bearer #{current_cloud_token}"})
27
+ puts "Stack: #{env_vars['STACK']}"
28
+ puts "Structure: #{JSON.pretty_generate(result['structure'])}"
29
+ status = client.get("/apps/#{instance_id}/status", nil, {'Authorization' => "Bearer #{current_cloud_token}"})
30
+ puts "Processes: #{JSON.pretty_generate(status['processes'])}"
31
+ end
32
+
33
+ def create(name, options)
34
+ sizes = {mini: 1, small: 2, medium: 4}
35
+ size = sizes[options.size.to_s.to_sym] || 1
36
+ data = {
37
+ name: name,
38
+ serviceProviderId: 'mar',
39
+ config: {
40
+ runtimeSize: size,
41
+ runtimeType: 'app'
42
+ }
43
+ }
44
+ response = platform_client.post("/accounts/#{current_cloud_id}/instances", data)
45
+ puts response['id']
46
+ end
47
+
48
+ def restart(options)
49
+ instance_id = resolve_instance_id(options)
50
+ instance_data = instance_info(instance_id)
51
+ if instance_data
52
+ client.post("/apps/#{instance_id}/restart", {}, nil, {'Authorization' => "Bearer #{current_cloud_token}"})
53
+ end
54
+ end
55
+
56
+ def logs(options)
57
+ offset = options.offset || 0
58
+ limit = options.limit || 100
59
+ stream = options.stream || nil
60
+
61
+ instance_id = resolve_instance_id(options)
62
+ instance_data = instance_info(instance_id)
63
+ if instance_data
64
+ result = client.get("/apps/#{instance_id}/logs", {offset: offset, limit: limit}, {'Authorization' => "Bearer #{current_cloud_token}"})
65
+ result['results'].each do |r|
66
+ line = ''
67
+ line << "[#{r['time']}] " if options.timestamp == true
68
+ line << r['log']
69
+ puts line
70
+ end
71
+ end
72
+ end
73
+
74
+ def scale(args, options)
75
+ instance_id = resolve_instance_id(options)
76
+ instance_data = instance_info(instance_id)
77
+ if instance_data
78
+ app = client.get("/apps/#{instance_id}", nil, {'Authorization' => "Bearer #{current_cloud_token}"})
79
+ structure = app['structure']
80
+ scale = {}
81
+ args.each do |type|
82
+ arr = type.strip.split("=")
83
+ if arr[0] && arr[1]
84
+ raise ArgumentError.new("#{arr[0]} is not defined in Procfile") unless structure.has_key?(arr[0])
85
+ scale[arr[0]] = arr[1]
86
+ end
87
+ end
88
+ client.post("/apps/#{instance_id}/scale", scale, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
89
+ end
90
+ end
91
+
92
+ def exec(command, options)
93
+ instance_id = resolve_instance_id(options)
94
+ instance_data = instance_info(instance_id)
95
+ if instance_data
96
+ data = {
97
+ cmd: command,
98
+ processId: options.process
99
+ }
100
+ result = client.post("/apps/#{instance_id}/exec", data, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
101
+ puts result['stderr']
102
+ puts result['stdout']
103
+ end
104
+ end
105
+
106
+ def size_mapping
107
+ {
108
+ '1' => 'mini',
109
+ '2' => 'small',
110
+ '4' => 'medium',
111
+ '8' => 'large'
112
+ }
113
+ end
114
+ end
115
+ end
116
+ end
@@ -1,60 +1,60 @@
1
- require 'qtc/client'
2
- require_relative '../common'
3
-
4
- module Qtc
5
- module Cli
6
- module Mar
7
- class Base
8
- include Cli::Common
9
-
10
- protected
11
-
12
- def resolve_instance_id(options)
13
- if options.app.nil?
14
- instance_id = extract_app_in_dir(options.remote)
15
- else
16
- instance_id = options.app
17
- end
18
- if instance_id.nil?
19
- raise ArgumentError.new('Cannot resolve current app, please use --app APP')
20
- end
21
-
22
- self.datacenter_id = resolve_datacenter_id(instance_id)
23
-
24
- instance_id
25
- end
26
-
27
- ##
28
- # @param [String] instance_id
29
- # @return [String,NilClass]
30
- def resolve_datacenter_id(instance_id)
31
- match = instance_id.to_s.match(/^(mar-\w+-\w+)-\w+/)
32
- if match[1]
33
- match[1]
34
- end
35
- end
36
-
37
- ##
38
- # @return [Qtc::Client]
39
- def client
40
- if @client.nil?
41
- @client = Qtc::Client.new(base_url)
42
- end
43
-
44
- @client
45
- end
46
-
47
- private
48
-
49
- def base_url
50
- datacenters = inifile['datacenters'] || {}
51
- if !self.datacenter_id.nil? && datacenters.has_key?(self.datacenter_id)
52
- "#{datacenters[self.datacenter_id]}/v1"
53
- else
54
- raise ArgumentError.new('Unknown datacenter. Please run qtc-cli datacenters to get latest list of your datacenters')
55
- end
56
- end
57
- end
58
- end
59
- end
60
- end
1
+ require 'qtc/client'
2
+ require_relative '../common'
3
+
4
+ module Qtc
5
+ module Cli
6
+ module Mar
7
+ class Base
8
+ include Cli::Common
9
+
10
+ protected
11
+
12
+ def resolve_instance_id(options)
13
+ if options.app.nil?
14
+ instance_id = extract_app_in_dir(options.remote)
15
+ else
16
+ instance_id = options.app
17
+ end
18
+ if instance_id.nil?
19
+ raise ArgumentError.new('Cannot resolve current app, please use --app APP')
20
+ end
21
+
22
+ self.datacenter_id = resolve_datacenter_id(instance_id)
23
+
24
+ instance_id
25
+ end
26
+
27
+ ##
28
+ # @param [String] instance_id
29
+ # @return [String,NilClass]
30
+ def resolve_datacenter_id(instance_id)
31
+ match = instance_id.to_s.match(/^(mar-\w+-\w+)-\w+/)
32
+ if match[1]
33
+ match[1]
34
+ end
35
+ end
36
+
37
+ ##
38
+ # @return [Qtc::Client]
39
+ def client
40
+ if @client.nil?
41
+ @client = Qtc::Client.new(base_url)
42
+ end
43
+
44
+ @client
45
+ end
46
+
47
+ private
48
+
49
+ def base_url
50
+ datacenters = inifile['datacenters'] || {}
51
+ if !self.datacenter_id.nil? && datacenters.has_key?(self.datacenter_id)
52
+ "#{datacenters[self.datacenter_id]}/v1"
53
+ else
54
+ raise ArgumentError.new('Unknown datacenter. Please run qtc-cli datacenters to get latest list of your datacenters')
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end