qtc-sdk 0.4.0 → 0.4.1
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/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Changelog.md +28 -23
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +42 -44
- data/Rakefile +1 -1
- data/bin/qtc-cli +13 -13
- data/lib/qtc-sdk.rb +1 -1
- data/lib/qtc/cli/commands.rb +15 -15
- data/lib/qtc/cli/common.rb +146 -146
- 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 -116
- data/lib/qtc/cli/mar/base.rb +60 -60
- data/lib/qtc/cli/mar/commands.rb +268 -266
- data/lib/qtc/cli/mar/debug.rb +94 -88
- data/lib/qtc/cli/mar/domains.rb +35 -35
- data/lib/qtc/cli/mar/env.rb +38 -38
- data/lib/qtc/cli/mar/repository.rb +24 -24
- data/lib/qtc/cli/mar/slugs.rb +80 -80
- data/lib/qtc/cli/mar/ssl_certificates.rb +40 -40
- data/lib/qtc/cli/mar/stack.rb +29 -29
- data/lib/qtc/cli/mdb/base.rb +47 -47
- data/lib/qtc/cli/mdb/commands.rb +43 -43
- data/lib/qtc/cli/mdb/instances.rb +79 -79
- data/lib/qtc/cli/platform/clouds.rb +33 -33
- data/lib/qtc/cli/platform/commands.rb +133 -132
- data/lib/qtc/cli/platform/datacenters.rb +23 -23
- data/lib/qtc/cli/platform/ssh_keys.rb +41 -41
- data/lib/qtc/cli/platform/user.rb +29 -25
- data/lib/qtc/cli/platform/vpn.rb +93 -93
- 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 -13
- data/lib/qtc/version.rb +3 -3
- data/qtc-sdk.gemspec +28 -28
- data/spec/spec_helper.rb +17 -0
- data/spec/unit/qtc/client_spec.rb +147 -147
- metadata +5 -3
data/lib/qtc/cli/eds/base.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
require 'qtc/client'
|
2
|
-
require_relative '../common'
|
3
|
-
|
4
|
-
module Qtc
|
5
|
-
module Cli
|
6
|
-
module Eds
|
7
|
-
class Base
|
8
|
-
include Cli::Common
|
9
|
-
|
10
|
-
protected
|
11
|
-
|
12
|
-
##
|
13
|
-
# @return [Qtc::Client]
|
14
|
-
def client
|
15
|
-
if @client.nil?
|
16
|
-
@client = Qtc::Client.new(base_url)
|
17
|
-
end
|
18
|
-
|
19
|
-
@client
|
20
|
-
end
|
21
|
-
|
22
|
-
def base_url
|
23
|
-
ENV['QTC_EDS_URL'] || 'https://api.engin.io/v1'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
1
|
+
require 'qtc/client'
|
2
|
+
require_relative '../common'
|
3
|
+
|
4
|
+
module Qtc
|
5
|
+
module Cli
|
6
|
+
module Eds
|
7
|
+
class Base
|
8
|
+
include Cli::Common
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
##
|
13
|
+
# @return [Qtc::Client]
|
14
|
+
def client
|
15
|
+
if @client.nil?
|
16
|
+
@client = Qtc::Client.new(base_url)
|
17
|
+
end
|
18
|
+
|
19
|
+
@client
|
20
|
+
end
|
21
|
+
|
22
|
+
def base_url
|
23
|
+
ENV['QTC_EDS_URL'] || 'https://api.engin.io/v1'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
28
|
end
|
data/lib/qtc/cli/eds/commands.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require_relative 'instances'
|
2
|
-
|
3
|
-
command 'eds list' do |c|
|
4
|
-
c.syntax = 'qtc-cli eds list'
|
5
|
-
c.description = 'List all EDS instances'
|
6
|
-
c.action do |args, options|
|
7
|
-
Qtc::Cli::Eds::Instances.new.list
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
command 'eds create' do |c|
|
12
|
-
c.syntax = 'qtc-cli eds create <CLOUD_ID> <NAME>'
|
13
|
-
c.description = 'Create a new EDS instance'
|
14
|
-
c.example 'Create new EDS instance "My Backend" to cloud "46738209-a745-4841-8eeb-1ca0672aa6v8"', 'qtc-cli eds create 46738209-a745-4841-8eeb-1ca0672aa6v8 "My Backend"'
|
15
|
-
c.action do |args, options|
|
16
|
-
raise ArgumentError.new('CLOUD_ID is required') if args[0].nil?
|
17
|
-
raise ArgumentError.new('NAME is required') if args[1].nil?
|
18
|
-
Qtc::Cli::Eds::Instances.new.create(args[0], args[1])
|
19
|
-
end
|
20
|
-
end
|
1
|
+
require_relative 'instances'
|
2
|
+
|
3
|
+
command 'eds list' do |c|
|
4
|
+
c.syntax = 'qtc-cli eds list'
|
5
|
+
c.description = 'List all EDS instances'
|
6
|
+
c.action do |args, options|
|
7
|
+
Qtc::Cli::Eds::Instances.new.list
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
command 'eds create' do |c|
|
12
|
+
c.syntax = 'qtc-cli eds create <CLOUD_ID> <NAME>'
|
13
|
+
c.description = 'Create a new EDS instance'
|
14
|
+
c.example 'Create new EDS instance "My Backend" to cloud "46738209-a745-4841-8eeb-1ca0672aa6v8"', 'qtc-cli eds create 46738209-a745-4841-8eeb-1ca0672aa6v8 "My Backend"'
|
15
|
+
c.action do |args, options|
|
16
|
+
raise ArgumentError.new('CLOUD_ID is required') if args[0].nil?
|
17
|
+
raise ArgumentError.new('NAME is required') if args[1].nil?
|
18
|
+
Qtc::Cli::Eds::Instances.new.create(args[0], args[1])
|
19
|
+
end
|
20
|
+
end
|
@@ -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,116 +1,116 @@
|
|
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
|
+
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
|