qtc-sdk 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +18 -18
- data/Changelog.md +14 -6
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +44 -44
- data/Rakefile +1 -1
- data/bin/qtc-cli +13 -13
- data/lib/qtc/cli/commands.rb +15 -15
- data/lib/qtc/cli/common.rb +146 -91
- data/lib/qtc/cli/eds/base.rb +27 -27
- data/lib/qtc/cli/eds/commands.rb +20 -20
- data/lib/qtc/cli/eds/instances.rb +30 -30
- data/lib/qtc/cli/mar/apps.rb +116 -125
- data/lib/qtc/cli/mar/base.rb +60 -60
- data/lib/qtc/cli/mar/commands.rb +221 -199
- data/lib/qtc/cli/mar/debug.rb +87 -86
- data/lib/qtc/cli/mar/domains.rb +35 -38
- data/lib/qtc/cli/mar/env.rb +38 -40
- data/lib/qtc/cli/mar/repository.rb +24 -26
- data/lib/qtc/cli/mar/ssl_certificates.rb +40 -42
- data/lib/qtc/cli/mar/stack.rb +29 -0
- data/lib/qtc/cli/mdb/base.rb +47 -43
- data/lib/qtc/cli/mdb/commands.rb +43 -31
- data/lib/qtc/cli/mdb/instances.rb +79 -60
- data/lib/qtc/cli/platform/clouds.rb +33 -15
- data/lib/qtc/cli/platform/commands.rb +132 -65
- data/lib/qtc/cli/platform/datacenters.rb +23 -21
- data/lib/qtc/cli/platform/ssh_keys.rb +41 -41
- data/lib/qtc/cli/platform/user.rb +25 -25
- data/lib/qtc/cli/platform/vpn.rb +93 -0
- data/lib/qtc/client.rb +170 -170
- data/lib/qtc/eds/client.rb +116 -116
- data/lib/qtc/eds/collection.rb +124 -124
- data/lib/qtc/eds/user_collection.rb +13 -13
- data/lib/qtc/eds/usergroup_collection.rb +41 -41
- data/lib/qtc/errors.rb +13 -11
- data/lib/qtc/version.rb +3 -3
- data/lib/qtc-sdk.rb +1 -1
- data/qtc-sdk.gemspec +28 -28
- data/spec/unit/qtc/client_spec.rb +147 -147
- metadata +20 -19
- 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
|
data/lib/qtc/cli/mar/apps.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
|
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
|
data/lib/qtc/cli/mar/base.rb
CHANGED
@@ -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
|