qtc-sdk 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7670fe44cccc0a8a866ddffcb6d50d261d41e562
4
- data.tar.gz: 18b7cbd99727bdd467ba2980f808b877870361bc
3
+ metadata.gz: df30db23cfd3384178524f6005f02033801dd00d
4
+ data.tar.gz: f8ef66175ea3afc26af7d9d3d914659d9de7942c
5
5
  SHA512:
6
- metadata.gz: 80522e72595546c33febb7433a1745108293ac9751ee5df9f031fad5fc3791fa688c3cf7154710ed46859bd12d2d2fe6d39912f471e0b1466d7abb01e29b6fec
7
- data.tar.gz: 6ec3a2c658e9db8436ff1f73ff52a04c9325602e0dbe3a3137ce5b2a5a02a2bedef630945864d9e461aff00d7e3a7a291b1835885c0d34485b8bb2b137cd306e
6
+ metadata.gz: f019c0a37f010d511ddc5107fc7bd655a2017a3dfd9d046cf0c9c5b579ce8852d2eb987c97b2a0cfe4c860b909a1a17fde515a34fd403cd038b6ed4f36ab20b7
7
+ data.tar.gz: 851b91ada6b47e1e7a1a4ff6d4d2d39ebc1b40c65ec48500940f3ec61f58439389bd38091af6abc53acad25e7a54b5c1b0cf23f2fe064be48f5a7dab2a8c4c69
@@ -3,6 +3,8 @@ module Qtc
3
3
  module Cli
4
4
  module Common
5
5
 
6
+ attr_accessor :datacenter_id
7
+
6
8
  def instance_info(instance_id)
7
9
  instance_data = platform_client.get("/instances/#{instance_id}")
8
10
  if instance_data
@@ -81,10 +83,6 @@ module Qtc
81
83
  @client
82
84
  end
83
85
 
84
- def base_url
85
- ENV['QTC_MAR_URL'] || 'https://mar-eu-1.qtc.io/v1'
86
- end
87
-
88
86
  def platform_base_url
89
87
  ENV['QTC_PLATFORM_URL'] || 'https://api.qtc.io/v1'
90
88
  end
@@ -7,14 +7,14 @@ module Qtc
7
7
  def list
8
8
  accounts = platform_client.get('/user/accounts')
9
9
  accounts['results'].each do |account|
10
- print color("== #{account['name']}: #{account['id']}")
11
10
  instances = platform_client.get("/accounts/#{account['id']}/instances", {provider: 'mar'})
12
- instances['results'].each do |instance|
13
- if instance['config']['MAR_GIT_ADDRESS']
11
+ if instances['results'].size > 0
12
+ print color("== #{account['name']} (#{account['datacenter']['id']}): #{account['id']}")
13
+ instances['results'].each do |instance|
14
14
  say(" ~ <%= color('#{instance['id']}', :green) %> #{instance['name']} <%= color('#{instance['tags'].join(', ')}', :yellow) %>")
15
15
  end
16
+ puts ''
16
17
  end
17
- puts ''
18
18
  end
19
19
  end
20
20
 
@@ -25,9 +25,9 @@ module Qtc
25
25
  if instance_data
26
26
  token = instance_data['authorizations'][0]['access_token']
27
27
  result = client.get("/apps/#{instance_id}", nil, {'Authorization' => "Bearer #{token}"})
28
- say "Id: #{result['id']}"
28
+ puts "Id: #{result['id']}"
29
29
  puts "Name: #{result['name']}"
30
- puts "Size: #{result['size']}"
30
+ puts "Size: #{size_mapping[result['size'].to_s] || result['size']}"
31
31
  puts "State: #{result['state']}"
32
32
  puts "Structure: #{JSON.pretty_generate(result['structure'])}"
33
33
  status = client.get("/apps/#{instance_id}/status", nil, {'Authorization' => "Bearer #{token}"})
@@ -41,7 +41,6 @@ module Qtc
41
41
  data = {
42
42
  name: name,
43
43
  serviceProviderId: 'mar',
44
- datacenterId: options.datacenter || 'eu-1',
45
44
  config: {
46
45
  runtimeSize: size,
47
46
  runtimeType: 'app'
@@ -98,6 +97,15 @@ module Qtc
98
97
  client.post("/apps/#{instance_id}/scale", scale, {}, {'Authorization' => "Bearer #{token}"})
99
98
  end
100
99
  end
100
+
101
+ def size_mapping
102
+ {
103
+ '1' => 'mini',
104
+ '2' => 'small',
105
+ '4' => 'medium',
106
+ '8' => 'large'
107
+ }
108
+ end
101
109
  end
102
110
  end
103
111
  end
@@ -19,9 +19,21 @@ module Qtc
19
19
  raise ArgumentError.new('Cannot resolve current app, please use --app APP')
20
20
  end
21
21
 
22
+ self.datacenter_id = resolve_datacenter_id(instance_id)
23
+
22
24
  instance_id
23
25
  end
24
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
+
25
37
  ##
26
38
  # @return [Qtc::Client]
27
39
  def client
@@ -32,8 +44,15 @@ module Qtc
32
44
  @client
33
45
  end
34
46
 
47
+ private
48
+
35
49
  def base_url
36
- ENV['QTC_MAR_URL'] || 'https://mar-eu-1.qtc.io/v1'
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
37
56
  end
38
57
  end
39
58
  end
@@ -37,7 +37,6 @@ command 'mar create' do |c|
37
37
  c.syntax = 'qtc-cli mar create CLOUD_ID NAME'
38
38
  c.description = 'Create a new app instance'
39
39
  c.option '--size SIZE', String, 'App runtime size'
40
- c.option '--datacenter DATACENTER', String, 'Datacenter id'
41
40
  c.action do |args, options|
42
41
  raise ArgumentError.new('CLOUD_ID is required') if args[0].nil?
43
42
  raise ArgumentError.new('NAME is required') if args[1].nil?
@@ -11,22 +11,5 @@ module Qtc::Cli::Platform
11
11
  print color("~ #{account['name']} (#{account['id']})", :bold)
12
12
  end
13
13
  end
14
-
15
- def login
16
- pass = password("Personal Access Token (copy from https://console.qtcloudservices.com/#/user/profile):")
17
- inifile['platform']['token'] = pass
18
-
19
- response = platform_client(pass).get('/user/accounts', {}) rescue nil
20
- if response
21
- inifile.save(filename: ini_filename)
22
- else
23
- print color('Invalid Personal Access Token', :red)
24
- end
25
- end
26
-
27
- def logout
28
- inifile['platform'].delete('token')
29
- inifile.save(filename: ini_filename)
30
- end
31
14
  end
32
15
  end
@@ -1,9 +1,18 @@
1
1
  module Qtc::Cli::Platform; end;
2
2
 
3
+ require_relative 'datacenters'
3
4
  require_relative 'clouds'
4
5
  require_relative 'user'
5
6
  require_relative 'ssh_keys'
6
7
 
8
+ command 'datacenters' do |c|
9
+ c.syntax = 'qtc-cli datacenters'
10
+ c.description = 'List all datacenters'
11
+ c.action do |args, options|
12
+ Qtc::Cli::Platform::Datacenters.new.list
13
+ end
14
+ end
15
+
7
16
  command 'clouds' do |c|
8
17
  c.syntax = 'qtc-cli clouds'
9
18
  c.description = 'List all clouds'
@@ -0,0 +1,21 @@
1
+ require 'qtc/client'
2
+ require_relative '../common'
3
+
4
+ module Qtc::Cli::Platform
5
+ class Datacenters
6
+ include Qtc::Cli::Common
7
+
8
+ def list
9
+ datacenters = platform_client.get('/datacenters')
10
+ inifile['datacenters'] = {}
11
+
12
+ datacenters['results'].each do |datacenter|
13
+ datacenter['services'].each do |service|
14
+ inifile['datacenters']["#{service['id']}-#{datacenter['id']}"] = service['url']
15
+ end
16
+ print color("~ #{datacenter['id']} (#{datacenter['description']})", :bold)
17
+ end
18
+ inifile.save(filename: ini_filename)
19
+ end
20
+ end
21
+ end
@@ -16,9 +16,10 @@ module Qtc
16
16
  # @param [String] gateway_id
17
17
  # @param [Hash] options
18
18
  def initialize(gateway_id, options = {})
19
- self.gateway_id = opts[:gateway_id]
19
+ self.gateway_id = gateway_id
20
20
  self.options = DEFAULT_OPTIONS.merge(options)
21
21
  self.http_client = Qtc::Client.new(http_client_url)
22
+ self.access_token = options[:access_token]
22
23
  end
23
24
 
24
25
  ##
@@ -33,13 +34,45 @@ module Qtc
33
34
  self.http_client.post('/messages', data)
34
35
  end
35
36
 
37
+ ##
38
+ # Create a new websocket object
39
+ #
40
+ # @param [Array<String>] tags
41
+ # @return [Hash]
42
+ def create_socket(tags = [])
43
+ data = {tags: tags}
44
+ self.http_client.post('/sockets', data)
45
+ end
46
+
47
+ ##
48
+ # Get websocket uri
49
+ #
50
+ # @return [Hash]
51
+ def websocket_uri
52
+ self.http_client.get('/websocket_uri')
53
+ end
54
+
36
55
  ##
37
56
  # Get websocket client
38
57
  #
58
+ # @param [String] uri
39
59
  # @return [Faye::WebSocket::Client]
40
- def websocket_client
41
- uri = self.http_client.get('/websocket_uri')
42
- Faye::WebSocket::Client.new(uri["uri"])
60
+ def websocket_client(uri = nil)
61
+ uri = websocket_uri["uri"] if uri.nil?
62
+
63
+ Faye::WebSocket::Client.new(uri)
64
+ end
65
+
66
+ ##
67
+ # Set access token
68
+ #
69
+ # @param [String] access_token
70
+ def access_token=(access_token)
71
+ if !access_token.nil?
72
+ self.http_client.default_headers['Authorization'] = "Bearer #{access_token}"
73
+ else
74
+ self.http_client.default_headers.delete('Authorization')
75
+ end
43
76
  end
44
77
 
45
78
  private
@@ -53,4 +86,4 @@ module Qtc
53
86
  end
54
87
  end
55
88
  end
56
- end
89
+ end
data/lib/qtc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qtc
2
- VERSION = '0.0.5'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qtc-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Kolehmainen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -165,6 +165,7 @@ files:
165
165
  - lib/qtc/cli/mar/ssl_certificates.rb
166
166
  - lib/qtc/cli/platform/clouds.rb
167
167
  - lib/qtc/cli/platform/commands.rb
168
+ - lib/qtc/cli/platform/datacenters.rb
168
169
  - lib/qtc/cli/platform/ssh_keys.rb
169
170
  - lib/qtc/cli/platform/user.rb
170
171
  - lib/qtc/client.rb