qtc-sdk 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +18 -18
  3. data/Changelog.md +18 -14
  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-sdk.rb +1 -1
  10. data/lib/qtc/cli/commands.rb +15 -15
  11. data/lib/qtc/cli/common.rb +146 -146
  12. data/lib/qtc/cli/eds/base.rb +27 -27
  13. data/lib/qtc/cli/eds/commands.rb +20 -20
  14. data/lib/qtc/cli/eds/instances.rb +30 -30
  15. data/lib/qtc/cli/mar/apps.rb +116 -116
  16. data/lib/qtc/cli/mar/base.rb +60 -60
  17. data/lib/qtc/cli/mar/commands.rb +221 -221
  18. data/lib/qtc/cli/mar/debug.rb +88 -87
  19. data/lib/qtc/cli/mar/domains.rb +35 -35
  20. data/lib/qtc/cli/mar/env.rb +38 -38
  21. data/lib/qtc/cli/mar/repository.rb +24 -24
  22. data/lib/qtc/cli/mar/ssl_certificates.rb +40 -40
  23. data/lib/qtc/cli/mar/stack.rb +29 -29
  24. data/lib/qtc/cli/mdb/base.rb +47 -47
  25. data/lib/qtc/cli/mdb/commands.rb +43 -43
  26. data/lib/qtc/cli/mdb/instances.rb +79 -79
  27. data/lib/qtc/cli/platform/clouds.rb +33 -33
  28. data/lib/qtc/cli/platform/commands.rb +132 -132
  29. data/lib/qtc/cli/platform/datacenters.rb +23 -23
  30. data/lib/qtc/cli/platform/ssh_keys.rb +41 -41
  31. data/lib/qtc/cli/platform/user.rb +25 -25
  32. data/lib/qtc/cli/platform/vpn.rb +93 -93
  33. data/lib/qtc/client.rb +170 -170
  34. data/lib/qtc/eds/client.rb +116 -116
  35. data/lib/qtc/eds/collection.rb +124 -124
  36. data/lib/qtc/eds/user_collection.rb +13 -13
  37. data/lib/qtc/eds/usergroup_collection.rb +41 -41
  38. data/lib/qtc/errors.rb +13 -13
  39. data/lib/qtc/version.rb +3 -3
  40. data/qtc-sdk.gemspec +28 -28
  41. data/spec/unit/qtc/client_spec.rb +147 -147
  42. metadata +18 -18
@@ -1,79 +1,79 @@
1
- require_relative 'base'
2
-
3
- module Qtc
4
- module Cli
5
- class Mdb::Instances < Mdb::Base
6
- include Qtc::Cli::Common
7
-
8
- def list
9
- instances = platform_client(current_cloud_token).get("/accounts/#{current_cloud_id}/instances", {provider: 'mdb'})
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
-
17
- def show(options)
18
- raise ArgumentError.new('--id is required') if options.id.nil?
19
-
20
- self.datacenter_id = self.resolve_datacenter_id(options.id)
21
- instance_id = options.id
22
- instance_data = instance_info(instance_id)
23
- if instance_data
24
- result = client.get("/services/#{instance_id}", nil, {'Authorization' => "Bearer #{current_cloud_token}"})
25
- puts "Id: #{result['id']}"
26
- puts "Name: #{result['name']}"
27
- puts "Type: #{result['image']['name']}"
28
- puts "Size: #{result['size'].to_i * 256}MB"
29
- puts "State: #{result['state']}"
30
- puts "Ip address: #{result['ip_address']}"
31
- puts "Port: #{result['port']}"
32
- if result['username']
33
- puts "Username: #{result['username']}"
34
- end
35
- if result['password']
36
- puts "Password: #{result['password']}"
37
- end
38
- end
39
- end
40
-
41
- def create(name, options)
42
- sizes = {'256m' => 1, '512m' => 2, '768m' => 3, '1024m' => 4}
43
- size = sizes[options.size.to_s.to_sym] || 1
44
- data = {
45
- name: name,
46
- serviceProviderId: 'mdb',
47
- config: {
48
- runtimeSize: size,
49
- serviceImage: "qtcs/#{options.type}"
50
- }
51
- }
52
- response = platform_client.post("/accounts/#{current_cloud_id}/instances", data)
53
- puts response['id']
54
- end
55
-
56
- def logs(options)
57
- raise ArgumentError.new('--id is required') if options.id.nil?
58
-
59
- self.datacenter_id = self.resolve_datacenter_id(options.id)
60
- offset = options.offset || 0
61
- limit = options.limit || 100
62
- stream = options.stream || nil
63
-
64
- instance_id = options.id
65
- instance_data = instance_info(instance_id)
66
- if instance_data
67
- result = client.get("/services/#{instance_id}/logs", {offset: offset, limit: limit}, {'Authorization' => "Bearer #{current_cloud_token}"})
68
- result['results'].each do |r|
69
- line = ''
70
- line << "[#{r['time']}] " if options.timestamp == true
71
- line << r['log']
72
- puts line
73
- end
74
- end
75
- end
76
-
77
- end
78
- end
79
- end
1
+ require_relative 'base'
2
+
3
+ module Qtc
4
+ module Cli
5
+ class Mdb::Instances < Mdb::Base
6
+ include Qtc::Cli::Common
7
+
8
+ def list
9
+ instances = platform_client(current_cloud_token).get("/accounts/#{current_cloud_id}/instances", {provider: 'mdb'})
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
+
17
+ def show(options)
18
+ raise ArgumentError.new('--id is required') if options.id.nil?
19
+
20
+ self.datacenter_id = self.resolve_datacenter_id(options.id)
21
+ instance_id = options.id
22
+ instance_data = instance_info(instance_id)
23
+ if instance_data
24
+ result = client.get("/services/#{instance_id}", nil, {'Authorization' => "Bearer #{current_cloud_token}"})
25
+ puts "Id: #{result['id']}"
26
+ puts "Name: #{result['name']}"
27
+ puts "Type: #{result['image']['name']}"
28
+ puts "Size: #{result['size'].to_i * 256}MB"
29
+ puts "State: #{result['state']}"
30
+ puts "Ip address: #{result['ip_address']}"
31
+ puts "Port: #{result['port']}"
32
+ if result['username']
33
+ puts "Username: #{result['username']}"
34
+ end
35
+ if result['password']
36
+ puts "Password: #{result['password']}"
37
+ end
38
+ end
39
+ end
40
+
41
+ def create(name, options)
42
+ sizes = {'256m' => 1, '512m' => 2, '768m' => 3, '1024m' => 4}
43
+ size = sizes[options.size.to_s.to_sym] || 1
44
+ data = {
45
+ name: name,
46
+ serviceProviderId: 'mdb',
47
+ config: {
48
+ runtimeSize: size,
49
+ serviceImage: "qtcs/#{options.type}"
50
+ }
51
+ }
52
+ response = platform_client.post("/accounts/#{current_cloud_id}/instances", data)
53
+ puts response['id']
54
+ end
55
+
56
+ def logs(options)
57
+ raise ArgumentError.new('--id is required') if options.id.nil?
58
+
59
+ self.datacenter_id = self.resolve_datacenter_id(options.id)
60
+ offset = options.offset || 0
61
+ limit = options.limit || 100
62
+ stream = options.stream || nil
63
+
64
+ instance_id = options.id
65
+ instance_data = instance_info(instance_id)
66
+ if instance_data
67
+ result = client.get("/services/#{instance_id}/logs", {offset: offset, limit: limit}, {'Authorization' => "Bearer #{current_cloud_token}"})
68
+ result['results'].each do |r|
69
+ line = ''
70
+ line << "[#{r['time']}] " if options.timestamp == true
71
+ line << r['log']
72
+ puts line
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+ end
79
+ end
@@ -1,33 +1,33 @@
1
- require 'qtc/client'
2
- require_relative '../common'
3
-
4
- module Qtc::Cli::Platform
5
- class Clouds
6
- include Qtc::Cli::Common
7
-
8
- def list
9
- accounts = platform_client.get('/user/accounts')
10
- template = '%-40.40s %-40.40s'
11
- puts template % ['ID', 'NAME']
12
- accounts['results'].each do |account|
13
- name = account['name']
14
- name = "* #{name}" if account['id'] == inifile['platform']['current_cloud']
15
- puts template % [account['id'], name]
16
- end
17
- end
18
-
19
- def use(id)
20
- account = platform_client.get("/accounts/#{id}")
21
- puts "Using cloud: #{account['name']} (#{id})"
22
- inifile['platform']['current_cloud'] = id
23
- inifile['platform']['current_dc'] = account['datacenter']['id']
24
- inifile.save(filename: ini_filename)
25
- end
26
-
27
- def create(name, opts)
28
- datacenter = opts.datacenter || 'eu-1'
29
- data = {name: name, datacenter: datacenter, vpc: opts.vpc}
30
- platform_client.post('/accounts', data)
31
- end
32
- end
33
- end
1
+ require 'qtc/client'
2
+ require_relative '../common'
3
+
4
+ module Qtc::Cli::Platform
5
+ class Clouds
6
+ include Qtc::Cli::Common
7
+
8
+ def list
9
+ accounts = platform_client.get('/user/accounts')
10
+ template = '%-40.40s %-40.40s'
11
+ puts template % ['ID', 'NAME']
12
+ accounts['results'].each do |account|
13
+ name = account['name']
14
+ name = "* #{name}" if account['id'] == inifile['platform']['current_cloud']
15
+ puts template % [account['id'], name]
16
+ end
17
+ end
18
+
19
+ def use(id)
20
+ account = platform_client.get("/accounts/#{id}")
21
+ puts "Using cloud: #{account['name']} (#{id})"
22
+ inifile['platform']['current_cloud'] = id
23
+ inifile['platform']['current_dc'] = account['datacenter']['id']
24
+ inifile.save(filename: ini_filename)
25
+ end
26
+
27
+ def create(name, opts)
28
+ datacenter = opts.datacenter || 'eu-1'
29
+ data = {name: name, datacenter: datacenter, vpc: opts.vpc}
30
+ platform_client.post('/accounts', data)
31
+ end
32
+ end
33
+ end
@@ -1,132 +1,132 @@
1
- module Qtc::Cli::Platform; end;
2
-
3
- require_relative 'datacenters'
4
- require_relative 'clouds'
5
- require_relative 'vpn'
6
- require_relative 'user'
7
- require_relative 'ssh_keys'
8
-
9
- command 'datacenters' do |c|
10
- c.syntax = 'qtc-cli datacenters'
11
- c.description = 'List all datacenters'
12
- c.action do |args, options|
13
- Qtc::Cli::Platform::Datacenters.new.list
14
- end
15
- end
16
-
17
- command 'clouds:list' do |c|
18
- c.syntax = 'qtc-cli clouds:list'
19
- c.description = 'List all clouds'
20
- c.action do |args, options|
21
- Qtc::Cli::Platform::Clouds.new.list
22
- end
23
- end
24
-
25
- command 'clouds:use' do |c|
26
- c.syntax = 'qtc-cli clouds:use <id>'
27
- c.description = 'Set default cloud to use'
28
- c.action do |args, options|
29
- Qtc::Cli::Platform::Clouds.new.use(args[0])
30
- end
31
- end
32
-
33
- command 'vpn:create' do |c|
34
- c.syntax = 'qtc-cli vpn:create'
35
- c.description = 'Create vpn connection'
36
- c.action do |args, options|
37
- Qtc::Cli::Platform::Vpn.new.create
38
- end
39
- end
40
-
41
- command 'vpn:show' do |c|
42
- c.syntax = 'qtc-cli vpn:show'
43
- c.description = 'Show vpn connection'
44
- c.action do |args, options|
45
- Qtc::Cli::Platform::Vpn.new.show
46
- end
47
- end
48
-
49
- command 'vpn:start' do |c|
50
- c.syntax = 'qtc-cli vpn:start'
51
- c.description = 'Start vpn server'
52
- c.action do |args, options|
53
- Qtc::Cli::Platform::Vpn.new.start
54
- end
55
- end
56
-
57
- command 'vpn:stop' do |c|
58
- c.syntax = 'qtc-cli vpn:stop'
59
- c.description = 'Stop vpn server'
60
- c.action do |args, options|
61
- Qtc::Cli::Platform::Vpn.new.stop
62
- end
63
- end
64
-
65
- command 'vpn:remove' do |c|
66
- c.syntax = 'qtc-cli vpn:remove'
67
- c.description = 'Remove vpn connection'
68
- c.action do |args, options|
69
- Qtc::Cli::Platform::Vpn.new.destroy
70
- end
71
- end
72
-
73
- command 'vpn:config' do |c|
74
- c.syntax = 'qtc-cli vpn:config'
75
- c.description = 'Show vpn configuration'
76
- c.action do |args, options|
77
- Qtc::Cli::Platform::Vpn.new.config
78
- end
79
- end
80
-
81
- command 'clouds:create' do |c|
82
- c.syntax = 'qtc-cli clouds:create name'
83
- c.description = 'Create a new cloud'
84
- c.option '--datacenter STRING', String, 'Specify datacenter for this cloud (default: eu-1)'
85
- c.option '--vpc', 'Enable virtual private cloud'
86
- c.action do |args, options|
87
- Qtc::Cli::Platform::Clouds.new.create(args.join(' '), options)
88
- end
89
- end
90
-
91
- command 'login' do |c|
92
- c.syntax = 'qtc-cli login'
93
- c.description = 'Login to Qt Cloud Services'
94
- c.action do |args, options|
95
- Qtc::Cli::Platform::User.new.login
96
- end
97
- end
98
-
99
- command 'logout' do |c|
100
- c.syntax = 'qtc-cli logout'
101
- c.description = 'Logout from Qt Cloud Services'
102
- c.action do |args, options|
103
- Qtc::Cli::Platform::User.new.logout
104
- end
105
- end
106
-
107
- command 'ssh-keys' do |c|
108
- c.syntax = 'qtc-cli ssh-keys'
109
- c.description = 'List ssh keys'
110
- c.action do |args, options|
111
- Qtc::Cli::Platform::SshKeys.new.list
112
- end
113
- end
114
-
115
- command 'ssh-keys:add' do |c|
116
- c.syntax = 'qtc-cli ssh-keys:add'
117
- c.description = 'Add ssh key'
118
- c.option '--name NAME', String, 'SSH key name'
119
- c.option '--key KEY', String, 'Path to SSH public key file'
120
- c.action do |args, options|
121
- Qtc::Cli::Platform::SshKeys.new.create(options)
122
- end
123
- end
124
-
125
- command 'ssh-keys:remove' do |c|
126
- c.syntax = 'qtc-cli ssh-keys:remove'
127
- c.description = 'Add ssh key'
128
- c.option '--name NAME', String, 'SSH key name'
129
- c.action do |args, options|
130
- Qtc::Cli::Platform::SshKeys.new.destroy(options)
131
- end
132
- end
1
+ module Qtc::Cli::Platform; end;
2
+
3
+ require_relative 'datacenters'
4
+ require_relative 'clouds'
5
+ require_relative 'vpn'
6
+ require_relative 'user'
7
+ require_relative 'ssh_keys'
8
+
9
+ command 'datacenters' do |c|
10
+ c.syntax = 'qtc-cli datacenters'
11
+ c.description = 'List all datacenters'
12
+ c.action do |args, options|
13
+ Qtc::Cli::Platform::Datacenters.new.list
14
+ end
15
+ end
16
+
17
+ command 'clouds:list' do |c|
18
+ c.syntax = 'qtc-cli clouds:list'
19
+ c.description = 'List all clouds'
20
+ c.action do |args, options|
21
+ Qtc::Cli::Platform::Clouds.new.list
22
+ end
23
+ end
24
+
25
+ command 'clouds:use' do |c|
26
+ c.syntax = 'qtc-cli clouds:use <id>'
27
+ c.description = 'Set default cloud to use'
28
+ c.action do |args, options|
29
+ Qtc::Cli::Platform::Clouds.new.use(args[0])
30
+ end
31
+ end
32
+
33
+ command 'vpn:create' do |c|
34
+ c.syntax = 'qtc-cli vpn:create'
35
+ c.description = 'Create vpn connection'
36
+ c.action do |args, options|
37
+ Qtc::Cli::Platform::Vpn.new.create
38
+ end
39
+ end
40
+
41
+ command 'vpn:show' do |c|
42
+ c.syntax = 'qtc-cli vpn:show'
43
+ c.description = 'Show vpn connection'
44
+ c.action do |args, options|
45
+ Qtc::Cli::Platform::Vpn.new.show
46
+ end
47
+ end
48
+
49
+ command 'vpn:start' do |c|
50
+ c.syntax = 'qtc-cli vpn:start'
51
+ c.description = 'Start vpn server'
52
+ c.action do |args, options|
53
+ Qtc::Cli::Platform::Vpn.new.start
54
+ end
55
+ end
56
+
57
+ command 'vpn:stop' do |c|
58
+ c.syntax = 'qtc-cli vpn:stop'
59
+ c.description = 'Stop vpn server'
60
+ c.action do |args, options|
61
+ Qtc::Cli::Platform::Vpn.new.stop
62
+ end
63
+ end
64
+
65
+ command 'vpn:remove' do |c|
66
+ c.syntax = 'qtc-cli vpn:remove'
67
+ c.description = 'Remove vpn connection'
68
+ c.action do |args, options|
69
+ Qtc::Cli::Platform::Vpn.new.destroy
70
+ end
71
+ end
72
+
73
+ command 'vpn:config' do |c|
74
+ c.syntax = 'qtc-cli vpn:config'
75
+ c.description = 'Show vpn configuration'
76
+ c.action do |args, options|
77
+ Qtc::Cli::Platform::Vpn.new.config
78
+ end
79
+ end
80
+
81
+ command 'clouds:create' do |c|
82
+ c.syntax = 'qtc-cli clouds:create name'
83
+ c.description = 'Create a new cloud'
84
+ c.option '--datacenter STRING', String, 'Specify datacenter for this cloud (default: eu-1)'
85
+ c.option '--vpc', 'Enable virtual private cloud'
86
+ c.action do |args, options|
87
+ Qtc::Cli::Platform::Clouds.new.create(args.join(' '), options)
88
+ end
89
+ end
90
+
91
+ command 'login' do |c|
92
+ c.syntax = 'qtc-cli login'
93
+ c.description = 'Login to Qt Cloud Services'
94
+ c.action do |args, options|
95
+ Qtc::Cli::Platform::User.new.login
96
+ end
97
+ end
98
+
99
+ command 'logout' do |c|
100
+ c.syntax = 'qtc-cli logout'
101
+ c.description = 'Logout from Qt Cloud Services'
102
+ c.action do |args, options|
103
+ Qtc::Cli::Platform::User.new.logout
104
+ end
105
+ end
106
+
107
+ command 'ssh-keys' do |c|
108
+ c.syntax = 'qtc-cli ssh-keys'
109
+ c.description = 'List ssh keys'
110
+ c.action do |args, options|
111
+ Qtc::Cli::Platform::SshKeys.new.list
112
+ end
113
+ end
114
+
115
+ command 'ssh-keys:add' do |c|
116
+ c.syntax = 'qtc-cli ssh-keys:add'
117
+ c.description = 'Add ssh key'
118
+ c.option '--name NAME', String, 'SSH key name'
119
+ c.option '--key KEY', String, 'Path to SSH public key file'
120
+ c.action do |args, options|
121
+ Qtc::Cli::Platform::SshKeys.new.create(options)
122
+ end
123
+ end
124
+
125
+ command 'ssh-keys:remove' do |c|
126
+ c.syntax = 'qtc-cli ssh-keys:remove'
127
+ c.description = 'Add ssh key'
128
+ c.option '--name NAME', String, 'SSH key name'
129
+ c.action do |args, options|
130
+ Qtc::Cli::Platform::SshKeys.new.destroy(options)
131
+ end
132
+ end