Class: Qtc::Cli::Mdb::Instances
- Inherits:
-
Base
- Object
- Base
- Qtc::Cli::Mdb::Instances
show all
- Includes:
- Common
- Defined in:
- lib/qtc/cli/mdb/instances.rb
Instance Attribute Summary
Attributes included from Common
#datacenter_id
Instance Method Summary
collapse
Methods included from Common
#client, #current_cloud_dc, #current_cloud_id, #current_cloud_token, #extract_app_in_dir, #ini_filename, #inifile, #instance_info, #platform_base_url, #platform_client
Instance Method Details
#create(name, options) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/qtc/cli/mdb/instances.rb', line 41
def create(name, options)
sizes = {'256m' => 1, '512m' => 2, '768m' => 3, '1024m' => 4}
size = sizes[options.size.to_s.to_sym] || 1
data = {
name: name,
serviceProviderId: 'mdb',
config: {
runtimeSize: size,
serviceImage: "qtcs/#{options.type}"
}
}
response = platform_client.post("/accounts/#{current_cloud_id}/instances", data)
puts response['id']
end
|
#list ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/qtc/cli/mdb/instances.rb', line 8
def list
instances = platform_client(current_cloud_token).get("/accounts/#{current_cloud_id}/instances", {provider: 'mdb'})
template = "%-20.20s %-30.30s %-20.20s"
puts template % ["ID", "NAME", "TAGS"]
instances['results'].each do |instance|
puts template % [instance['id'], instance['name'], instance['tags'].join(',')]
end
end
|
#logs(options) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/qtc/cli/mdb/instances.rb', line 56
def logs(options)
raise ArgumentError.new('--id is required') if options.id.nil?
self.datacenter_id = self.resolve_datacenter_id(options.id)
offset = options.offset || 0
limit = options.limit || 100
stream = options.stream || nil
instance_id = options.id
instance_data = instance_info(instance_id)
if instance_data
result = client.get("/services/#{instance_id}/logs", {offset: offset, limit: limit}, {'Authorization' => "Bearer #{current_cloud_token}"})
result['results'].each do |r|
line = ''
line << "[#{r['time']}] " if options.timestamp == true
line << r['log']
puts line
end
end
end
|
#show(options) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/qtc/cli/mdb/instances.rb', line 17
def show(options)
raise ArgumentError.new('--id is required') if options.id.nil?
self.datacenter_id = self.resolve_datacenter_id(options.id)
instance_id = options.id
instance_data = instance_info(instance_id)
if instance_data
result = client.get("/services/#{instance_id}", nil, {'Authorization' => "Bearer #{current_cloud_token}"})
puts "Id: #{result['id']}"
puts "Name: #{result['name']}"
puts "Type: #{result['image']['name']}"
puts "Size: #{result['size'].to_i * 256}MB"
puts "State: #{result['state']}"
puts "Ip address: #{result['ip_address']}"
puts "Port: #{result['port']}"
if result['username']
puts "Username: #{result['username']}"
end
if result['password']
puts "Password: #{result['password']}"
end
end
end
|