civo 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/civo/version.rb +1 -1
- metadata +3 -16
- data/bin/civo +0 -25
- data/lib/civo/cli/client.rb +0 -56
- data/lib/civo/cli/commands/accounts.rb +0 -64
- data/lib/civo/cli/commands/instances.rb +0 -140
- data/lib/civo/cli/commands/quota.rb +0 -82
- data/lib/civo/cli/commands/regions.rb +0 -16
- data/lib/civo/cli/commands/sizes.rb +0 -26
- data/lib/civo/cli/commands/sshkeys.rb +0 -53
- data/lib/civo/cli/commands/templates.rb +0 -78
- data/lib/civo/cli/commands/tokens.rb +0 -41
- data/lib/civo/cli/config.rb +0 -53
- data/lib/civo/cli/token.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed8c49dcdc3351d964ad4efd690048469d25730b
|
4
|
+
data.tar.gz: 24eb760096a174ec86a90b0a94a5e0fb879da391
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f733e989736d52767e1dac30288ee3cdc65cc7cc62dc2209657d02533660e69ce812e18cb31935b246832044aa8e46df66543843e721ee0d72baaa57f81fbda
|
7
|
+
data.tar.gz: f95b3224fb2dd1959396f11cfa7423270ee77850ead33bb8302675a347ab674574014e9c89d8832738dda6e3658b8f14253902524e574edf703832dd8bf992c9
|
data/lib/civo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: civo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jeffries
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flexirest
|
@@ -55,8 +55,7 @@ dependencies:
|
|
55
55
|
description: A command-line client and API access classes for civo.com
|
56
56
|
email:
|
57
57
|
- andy@absolutedevops.io
|
58
|
-
executables:
|
59
|
-
- civo
|
58
|
+
executables: []
|
60
59
|
extensions: []
|
61
60
|
extra_rdoc_files: []
|
62
61
|
files:
|
@@ -71,20 +70,8 @@ files:
|
|
71
70
|
- app/models/civo/size.rb
|
72
71
|
- app/models/civo/ssh_key.rb
|
73
72
|
- app/models/civo/template.rb
|
74
|
-
- bin/civo
|
75
73
|
- config/routes.rb
|
76
74
|
- lib/civo.rb
|
77
|
-
- lib/civo/cli/client.rb
|
78
|
-
- lib/civo/cli/commands/accounts.rb
|
79
|
-
- lib/civo/cli/commands/instances.rb
|
80
|
-
- lib/civo/cli/commands/quota.rb
|
81
|
-
- lib/civo/cli/commands/regions.rb
|
82
|
-
- lib/civo/cli/commands/sizes.rb
|
83
|
-
- lib/civo/cli/commands/sshkeys.rb
|
84
|
-
- lib/civo/cli/commands/templates.rb
|
85
|
-
- lib/civo/cli/commands/tokens.rb
|
86
|
-
- lib/civo/cli/config.rb
|
87
|
-
- lib/civo/cli/token.rb
|
88
75
|
- lib/civo/engine.rb
|
89
76
|
- lib/civo/version.rb
|
90
77
|
- lib/tasks/civo_tasks.rake
|
data/bin/civo
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
4
|
-
ENGINE_PATH = File.expand_path('../../lib/civo/engine', __FILE__)
|
5
|
-
|
6
|
-
# Set up gems listed in the Gemfile.
|
7
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
8
|
-
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
9
|
-
require 'commander/import'
|
10
|
-
require 'toml'
|
11
|
-
require 'flexirest'
|
12
|
-
require_relative "#{ENGINE_ROOT}/lib/civo.rb"
|
13
|
-
require_relative "#{ENGINE_ROOT}/lib/civo/version.rb"
|
14
|
-
|
15
|
-
program :version, Civo::VERSION
|
16
|
-
program :description, 'Civo CLI and API client library'
|
17
|
-
|
18
|
-
require_relative "#{ENGINE_ROOT}/lib/civo/cli/commands/accounts.rb"
|
19
|
-
require_relative "#{ENGINE_ROOT}/lib/civo/cli/commands/sshkeys.rb"
|
20
|
-
require_relative "#{ENGINE_ROOT}/lib/civo/cli/commands/quota.rb"
|
21
|
-
require_relative "#{ENGINE_ROOT}/lib/civo/cli/commands/sizes.rb"
|
22
|
-
require_relative "#{ENGINE_ROOT}/lib/civo/cli/commands/regions.rb"
|
23
|
-
require_relative "#{ENGINE_ROOT}/lib/civo/cli/commands/templates.rb"
|
24
|
-
require_relative "#{ENGINE_ROOT}/lib/civo/cli/commands/instances.rb"
|
25
|
-
require_relative "#{ENGINE_ROOT}/lib/civo/cli/commands/tokens.rb"
|
data/lib/civo/cli/client.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
module Civo
|
2
|
-
class Client
|
3
|
-
def self.tabulate(hash, titles, options = {})
|
4
|
-
longest_key_length = hash.keys.max_by(&:length).try(:length) || 5
|
5
|
-
|
6
|
-
default = hash.delete("**DEFAULT**")
|
7
|
-
title = "%-#{longest_key_length}s | %s" % [titles[0], titles[1]]
|
8
|
-
puts title
|
9
|
-
puts "%s-|-%s" % [("-" * longest_key_length), ("-" * (69-longest_key_length))]
|
10
|
-
keys = hash.keys
|
11
|
-
keys.sort! if options[:sort] == true
|
12
|
-
keys.each do |key|
|
13
|
-
value = hash[key]
|
14
|
-
print "%-#{longest_key_length}s | %s" % [key, value]
|
15
|
-
if key == default
|
16
|
-
print " (DEFAULT)"
|
17
|
-
end
|
18
|
-
puts
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.tabulate_flexirest(data, mappings)
|
23
|
-
columns = mappings.dup
|
24
|
-
columns.each do |k, nice|
|
25
|
-
columns[k] = {max_width: (nice.length > 5 ? nice.length : 5), label: nice }
|
26
|
-
end
|
27
|
-
|
28
|
-
data.each do |record|
|
29
|
-
columns.each do |k, v|
|
30
|
-
if block_given?
|
31
|
-
yield record
|
32
|
-
end
|
33
|
-
length = record.send(k).to_s.length
|
34
|
-
if record.send(k).to_s.length > v[:max_width]
|
35
|
-
v[:max_width] = length
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
puts columns.keys.map {|k| "%-#{columns[k][:max_width]}s" % columns[k][:label] }.to_a.join(" | ")
|
41
|
-
puts columns.keys.map {|k| "-" * columns[k][:max_width] }.to_a.join("-+-")
|
42
|
-
|
43
|
-
data.each do |record|
|
44
|
-
row = []
|
45
|
-
columns.each do |k, v|
|
46
|
-
value = record.send(k)
|
47
|
-
if value.is_a? Array
|
48
|
-
value = value.join(", ")
|
49
|
-
end
|
50
|
-
row << "%-#{columns[k][:max_width]}s" % value
|
51
|
-
end
|
52
|
-
puts (row.join(" | "))
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
command "accounts" do |c|
|
2
|
-
c.description = "List known accounts (CIVO-INTERNAL-USE ONLY)"
|
3
|
-
c.action do |args, options|
|
4
|
-
begin
|
5
|
-
accounts = Civo::Account.all
|
6
|
-
Civo::Client.tabulate_flexirest accounts, {username: "Account", api_key: "API Key"}
|
7
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
8
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
alias_command "account", "accounts"
|
13
|
-
|
14
|
-
command "accounts:create" do |c|
|
15
|
-
c.description = "Create an account (CIVO-INTERNAL-USE ONLY)"
|
16
|
-
c.example "Creates an account called 'testuser'", 'civo accounts:create testuser'
|
17
|
-
c.action do |args, options|
|
18
|
-
begin
|
19
|
-
account = Civo::Account.create(name: args.first)
|
20
|
-
puts "Account '#{args.first}' created. The API key is '#{account.api_key}'"
|
21
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
22
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
alias_command "account:create", "accounts:create"
|
27
|
-
|
28
|
-
command "accounts:reset" do |c|
|
29
|
-
c.description = "Reset the API Key for an account (CIVO-INTERNAL-USE ONLY)"
|
30
|
-
c.example "Resets the account called 'testuser' with a new API key", 'civo accounts:reset testuser'
|
31
|
-
c.action do |args, options|
|
32
|
-
begin
|
33
|
-
account = Civo::Account.reset(name: args.first)
|
34
|
-
puts "Account '#{args.first}' reset, the new API key is '#{account.api_key}'"
|
35
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
36
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
alias_command "account:reset", "accounts:reset"
|
41
|
-
|
42
|
-
command "accounts:remove" do |c|
|
43
|
-
c.description = "Remove an account (and all instances, networks, etc) (CIVO-INTERNAL-USE ONLY)"
|
44
|
-
c.example "Removes an account called 'testuser'", 'civo accounts:remove testuser'
|
45
|
-
c.action do |args, options|
|
46
|
-
begin
|
47
|
-
account = Civo::Account.remove(name: args.first)
|
48
|
-
if account.result == "ok"
|
49
|
-
puts "Account '#{args.first}' has been removed."
|
50
|
-
else
|
51
|
-
puts "Failed to delete that account: #{account.inspect}"
|
52
|
-
end
|
53
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
54
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
55
|
-
rescue Flexirest::HTTPNotFoundClientException => e
|
56
|
-
puts "Couldn't find that account to remove, maybe it's already been removed?"
|
57
|
-
rescue Flexirest::HTTPServerException => e
|
58
|
-
puts "Unable to remove #{e.result.reason}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
alias_command "account:remove", "accounts:remove"
|
63
|
-
alias_command "accounts:delete", "accounts:remove"
|
64
|
-
alias_command "account:delete", "accounts:remove"
|
@@ -1,140 +0,0 @@
|
|
1
|
-
command "instances" do |c|
|
2
|
-
c.description = "List known instances"
|
3
|
-
c.action do |args, options|
|
4
|
-
begin
|
5
|
-
instances = Civo::Instance.all
|
6
|
-
Civo::Client.tabulate_flexirest instances, {id: "ID", hostname: "Hostname", size: "Size", nice_ip_addresses: "IP Addresses", status: "Status", initial_user: "User", initial_password: "Password"}
|
7
|
-
rescue Flexirest::HTTPServerException => e
|
8
|
-
puts "An error occurred: #{e.result.reason}"
|
9
|
-
exit 3
|
10
|
-
rescue Flexirest::ResponseParseException => e
|
11
|
-
puts "An error occurred: #{e.inspect}"
|
12
|
-
exit 4
|
13
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
14
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
alias_command "instance", "instances"
|
19
|
-
|
20
|
-
command "instances:create" do |c|
|
21
|
-
c.description = "Create an instance"
|
22
|
-
c.option "--size STRING", String, "The size from 'civo sizes'"
|
23
|
-
c.option "--region STRING", String, "The region from 'civo regions'"
|
24
|
-
c.option "--ssh-key STRING", String, "The SSH key name from 'civo sshkeys'"
|
25
|
-
c.option "--[no-]public-ip", "Should a public IP address be allocated"
|
26
|
-
c.option "--template STRING", String, "The template from 'civo templates'"
|
27
|
-
c.option "--initial-user STRING", String, "The default user to create (defaults to 'civo')"
|
28
|
-
c.example "Creates an instance called 'test1.example.com'", 'civo instances:create test1.example.com --size g1.small --region svg1 --ssh-key default'
|
29
|
-
c.action do |args, options|
|
30
|
-
begin
|
31
|
-
params = {}
|
32
|
-
params[:size] = options.size if options.size
|
33
|
-
params[:region] = options.region if options.region
|
34
|
-
params[:ssh_key] = options.ssh_key if options.ssh_key
|
35
|
-
params[:public_ip] = options.public_ip if options.public_ip
|
36
|
-
params[:template] = options.template if options.template
|
37
|
-
params[:initial_user] = options.initial_user if options.initial_user
|
38
|
-
params[:hostname] = args.first
|
39
|
-
instance = Civo::Instance.create(params)
|
40
|
-
puts "Instance '#{args.first}' created. The ID is '#{instance.id}' and its status is #{instance.status}"
|
41
|
-
rescue Flexirest::HTTPServerException => e
|
42
|
-
puts "An error occurred: #{e.result.reason}"
|
43
|
-
exit 3
|
44
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
45
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
alias_command "instance:create", "instances:create"
|
50
|
-
|
51
|
-
command "instances:remove" do |c|
|
52
|
-
c.description = "Remove an instance by hostname or id"
|
53
|
-
c.example "Removes an instance called 'test.example.com'", 'civo instances:remove test.example.com'
|
54
|
-
c.action do |args, options|
|
55
|
-
begin
|
56
|
-
if args.first[/(\w{8}(-\w{4}){3}-\w{12}?)/]
|
57
|
-
id = args.first
|
58
|
-
else
|
59
|
-
instance = Civo::Instance.all.detect {|i| i.hostname == args.first}
|
60
|
-
id = instance.id
|
61
|
-
end
|
62
|
-
instance = Civo::Instance.remove(id: id)
|
63
|
-
if instance.result == "ok"
|
64
|
-
puts "Instance '#{args.first}' has been removed."
|
65
|
-
else
|
66
|
-
puts "Failed to delete that instance: #{instance.inspect}"
|
67
|
-
end
|
68
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
69
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
70
|
-
rescue Flexirest::HTTPNotFoundClientException => e
|
71
|
-
puts "Couldn't find that account to remove, maybe it's already been removed?"
|
72
|
-
rescue Flexirest::HTTPServerException => e
|
73
|
-
puts "Unable to remove #{e.result.reason}"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
alias_command "instance:remove", "instances:remove"
|
78
|
-
alias_command "instances:delete", "instances:remove"
|
79
|
-
alias_command "instance:delete", "instances:remove"
|
80
|
-
|
81
|
-
command "instances:upgrade" do |c|
|
82
|
-
c.description = "Upgrade an instance by hostname or id"
|
83
|
-
c.option "--size STRING", String, "The size from 'civo sizes', must be larger than the current size"
|
84
|
-
c.example "Upgrades an instance called 'test.example.com' to `g1.large` size", 'civo instances:upgrade test.example.com --size g1.large'
|
85
|
-
c.action do |args, options|
|
86
|
-
begin
|
87
|
-
if args.first[/(\w{8}(-\w{4}){3}-\w{12}?)/]
|
88
|
-
id = args.first
|
89
|
-
else
|
90
|
-
instance = Civo::Instance.all.detect {|i| i.hostname == args.first}
|
91
|
-
id = instance.id
|
92
|
-
end
|
93
|
-
instance = Civo::Instance.upgrade(id: id, size: options.size)
|
94
|
-
if instance.result == "ok"
|
95
|
-
puts "Instance '#{args.first}' is being upgraded to #{options.size}."
|
96
|
-
else
|
97
|
-
puts "Failed to upgrade that instance: #{instance.inspect}"
|
98
|
-
end
|
99
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
100
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
101
|
-
rescue Flexirest::HTTPNotFoundClientException => e
|
102
|
-
puts "Couldn't find that account to remove, maybe it's already been removed?"
|
103
|
-
rescue Flexirest::HTTPServerException => e
|
104
|
-
puts "Unable to remove #{e.result.reason}"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
alias_command "instance:upgrade", "instances:upgrade"
|
109
|
-
alias_command "instances:resize", "instances:upgrade"
|
110
|
-
alias_command "instance:resize", "instances:upgrade"
|
111
|
-
|
112
|
-
command "instances:reboot" do |c|
|
113
|
-
c.description = "Reboot an instance by hostname or id"
|
114
|
-
c.example "Reboot an instance called 'test.example.com'", 'civo instances:reboot test.example.com'
|
115
|
-
c.action do |args, options|
|
116
|
-
begin
|
117
|
-
if args.first[/(\w{8}(-\w{4}){3}-\w{12}?)/]
|
118
|
-
id = args.first
|
119
|
-
else
|
120
|
-
instance = Civo::Instance.all.detect {|i| i.hostname == args.first}
|
121
|
-
id = instance.id
|
122
|
-
end
|
123
|
-
instance = Civo::Instance.reboot(id: id)
|
124
|
-
if instance.result == "ok"
|
125
|
-
puts "Instance '#{args.first}' is being rebooted."
|
126
|
-
else
|
127
|
-
puts "Failed to reboot that instance: #{instance.inspect}"
|
128
|
-
end
|
129
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
130
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
131
|
-
rescue Flexirest::HTTPNotFoundClientException => e
|
132
|
-
puts "Couldn't find that account to remove, maybe it's already been removed?"
|
133
|
-
rescue Flexirest::HTTPServerException => e
|
134
|
-
puts "Unable to remove #{e.result.reason}"
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
alias_command "instance:reboot", "instances:reboot"
|
139
|
-
alias_command "instances:restart", "instances:reboot"
|
140
|
-
alias_command "instance:restart", "instances:reboot"
|
@@ -1,82 +0,0 @@
|
|
1
|
-
command "quota" do |c|
|
2
|
-
c.option "--account STRING", String, "The account to get the quota for"
|
3
|
-
|
4
|
-
c.description = "List the quota for the current account"
|
5
|
-
c.action do |args, options|
|
6
|
-
begin
|
7
|
-
if options.account
|
8
|
-
quota = Civo::Quota.current(username: options.account)
|
9
|
-
else
|
10
|
-
quota = Civo::Quota.current
|
11
|
-
end
|
12
|
-
data = {
|
13
|
-
"Number of instances" => "#{quota.instance_count_limit} (used #{quota.instance_count_usage})",
|
14
|
-
"Total CPU cores" => "#{quota.cpu_core_limit} (used #{quota.cpu_core_usage})",
|
15
|
-
"Total RAM" => "#{quota.ram_mb_limit}MB (used #{quota.ram_mb_usage}MB)",
|
16
|
-
"Total disk space" => "#{quota.disk_gb_limit}GB (used #{quota.disk_gb_usage}GB)",
|
17
|
-
"Disk volumes" => "#{quota.disk_volume_count_limit} (used #{quota.disk_volume_count_usage})",
|
18
|
-
"Disk snapshots" => "#{quota.disk_snapshot_count_limit} (used #{quota.disk_snapshot_count_usage})",
|
19
|
-
"Public IP addresses" => "#{quota.public_ip_address_limit} (used #{quota.public_ip_address_usage})",
|
20
|
-
"Private subnets" => "#{quota.subnet_count_limit} (used #{quota.subnet_count_usage})",
|
21
|
-
"Private networks" => "#{quota.network_count_limit} (used #{quota.network_count_usage})",
|
22
|
-
"Security groups" => "#{quota.security_group_limit} (used #{quota.security_group_usage})",
|
23
|
-
"Security group rules" => "#{quota.security_group_rule_limit} (used #{quota.security_group_rule_usage})",
|
24
|
-
"Number of ports (network connections)" => "#{quota.port_count_limit} (used #{quota.port_count_usage})"
|
25
|
-
}
|
26
|
-
|
27
|
-
Civo::Client.tabulate data, ["Title", "Limit"]
|
28
|
-
|
29
|
-
if Civo::Config.admin?
|
30
|
-
puts
|
31
|
-
puts "To set these quota values use:"
|
32
|
-
puts "civo quota:set --instance-count #{quota.instance_count_limit} --cpu-core #{quota.cpu_core_limit} --ram-mb #{quota.ram_mb_limit} --disk-gb #{quota.disk_gb_limit} \\"
|
33
|
-
puts " --disk-volume-count #{quota.disk_volume_count_limit} --disk-snapshot-count #{quota.disk_snapshot_count_limit} --public-ip-address #{quota.public_ip_address_limit} \\"
|
34
|
-
puts " --subnet-count #{quota.subnet_count_limit} --network-count #{quota.network_count_limit} --security-group #{quota.security_group_limit} --security-group-rule #{quota.security_group_rule_limit} \\"
|
35
|
-
puts " --port-count #{quota.port_count_limit} #{"--account #{options.account}" if options.account}"
|
36
|
-
end
|
37
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
38
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
command "quota:set" do |c|
|
44
|
-
c.description = "Update the quotas for the current account (CIVO-INTERNAL-USE ONLY)"
|
45
|
-
c.option "--account STRING", String, "The account to update the quota for"
|
46
|
-
c.option "--instance-count INTEGER", Integer, "The limit to the number of instances available"
|
47
|
-
c.option "--cpu-core INTEGER", Integer, "The limit to the number of CPU cores available"
|
48
|
-
c.option "--ram-mb INTEGER", Integer, "The limit to the amount of RAM (in MB) available"
|
49
|
-
c.option "--disk-gb INTEGER", Integer, "The limit to the of disk space (in GB) available"
|
50
|
-
c.option "--disk-volume-count INTEGER", Integer, "The limit to the number of disk volumes available"
|
51
|
-
c.option "--disk-snapshot-count INTEGER", Integer, "The limit to the number of disk snapshots available"
|
52
|
-
c.option "--public-ip-address INTEGER", Integer, "The limit to the number of public IP addresses available"
|
53
|
-
c.option "--subnet-count INTEGER", Integer, "The limit to the number of subnets available"
|
54
|
-
c.option "--network-count INTEGER", Integer, "The limit to the number of networks available"
|
55
|
-
c.option "--security-group INTEGER", Integer, "The limit to the number of security groups available"
|
56
|
-
c.option "--security-group-rule INTEGER", Integer, "The limit to the number of security group rules available"
|
57
|
-
c.option "--port-count INTEGER", Integer, "The limit to the number of ports (network connections) available"
|
58
|
-
|
59
|
-
c.action do |args, options|
|
60
|
-
begin
|
61
|
-
params = {}
|
62
|
-
params[:name] = options.account if options.account
|
63
|
-
params[:instance_count_limit] = options.instance_count if options.instance_count
|
64
|
-
params[:cpu_core_limit] = options.cpu_core if options.cpu_core
|
65
|
-
params[:ram_mb_limit] = options.ram_mb if options.ram_mb
|
66
|
-
params[:disk_gb_limit] = options.disk_gb if options.disk_gb
|
67
|
-
params[:disk_volume_count_limit] = options.disk_volume_count if options.disk_volume_count
|
68
|
-
params[:disk_snapshot_count_limit] = options.disk_snapshot_count if options.disk_snapshot_count
|
69
|
-
params[:public_ip_address_limit] = options.public_ip_address if options.public_ip_address
|
70
|
-
params[:subnet_count_limit] = options.subnet_count if options.subnet_count
|
71
|
-
params[:network_count_limit] = options.network_count if options.network_count
|
72
|
-
params[:security_group_limit] = options.security_group if options.security_group
|
73
|
-
params[:security_group_rule_limit] = options.security_group_rule if options.security_group_rule
|
74
|
-
params[:port_count_limit] = options.port_count if options.port_count
|
75
|
-
puts params.inspect
|
76
|
-
Civo::Quota.update(params)
|
77
|
-
puts "Quota updated"
|
78
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
79
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
command "regions" do |c|
|
2
|
-
c.description = "List available regions"
|
3
|
-
c.action do |args, options|
|
4
|
-
begin
|
5
|
-
regions = Civo::Region.all
|
6
|
-
puts "Region name"
|
7
|
-
puts "-" * 72
|
8
|
-
regions.each do |region|
|
9
|
-
puts region.name
|
10
|
-
end
|
11
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
12
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
alias_command "region", "regions"
|
@@ -1,26 +0,0 @@
|
|
1
|
-
command "sizes" do |c|
|
2
|
-
c.description = "List available instance sizes"
|
3
|
-
c.action do |args, options|
|
4
|
-
begin
|
5
|
-
sizes = Civo::Size.all
|
6
|
-
Civo::Client.tabulate_flexirest sizes, {name: "Size", description: "Description"}
|
7
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
8
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
# alias_command "sizes", "size"
|
13
|
-
|
14
|
-
command "sizes:reset" do |c|
|
15
|
-
c.description = "Reset available instance sizes"
|
16
|
-
c.action do |args, options|
|
17
|
-
begin
|
18
|
-
Civo::Size.reset
|
19
|
-
puts "Standard sizes reset in Openstack"
|
20
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
21
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
alias_command "size:reset", "sizes:reset"
|
@@ -1,53 +0,0 @@
|
|
1
|
-
command "sshkeys" do |c|
|
2
|
-
c.description = "List the SSH public keys you've uploaded"
|
3
|
-
c.action do |args, options|
|
4
|
-
begin
|
5
|
-
sshkeys = Civo::SshKey.all
|
6
|
-
Civo::Client.tabulate_flexirest sshkeys, {name: "Name", label: "SSH Key Label"}
|
7
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
8
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
alias_command "sshkey", "sshkeys"
|
13
|
-
|
14
|
-
command "sshkeys:upload" do |c|
|
15
|
-
c.description = "Upload an SSH public key for installing in to new instances"
|
16
|
-
c.example "Uploads an SSH public key, calling it 'default' from file '~/.ssh/id_rsa.pub'", 'civo sshkeys:upload default ~/.ssh/id_rsa.pub'
|
17
|
-
c.action do |args, options|
|
18
|
-
pub_key = File.read(File.expand_path(args[1]))
|
19
|
-
begin
|
20
|
-
Civo::SshKey.create(name: args.first, public_key: pub_key)
|
21
|
-
puts "SSH key '#{args.first}' uploaded."
|
22
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
23
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
alias_command "sshkeys:create", "sshkeys:upload"
|
28
|
-
alias_command "sshkey:upload", "sshkeys:upload"
|
29
|
-
alias_command "sshkey:create", "sshkeys:upload"
|
30
|
-
|
31
|
-
command "sshkeys:remove" do |c|
|
32
|
-
c.description = "Remove an SSH public key from the list you've uploaded"
|
33
|
-
c.example "Removes an SSH public key called 'testuser'", 'civo sshkeys:remove testuser'
|
34
|
-
c.action do |args, options|
|
35
|
-
begin
|
36
|
-
key = Civo::SshKey.remove(name: args.first)
|
37
|
-
if key.result == "ok"
|
38
|
-
puts "SSH public key '#{args.first}' has been removed."
|
39
|
-
else
|
40
|
-
puts "Failed to delete that SSH key: #{key.inspect}"
|
41
|
-
end
|
42
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
43
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
44
|
-
rescue Flexirest::HTTPNotFoundClientException => e
|
45
|
-
puts "Couldn't find that account to remove, maybe it's already been removed?"
|
46
|
-
rescue Flexirest::HTTPServerException => e
|
47
|
-
puts "Unable to remove #{e.result.reason}"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
alias_command "sshkey:remove", "sshkeys:remove"
|
52
|
-
alias_command "sshkey:delete", "sshkeys:remove"
|
53
|
-
alias_command "sshkeys:delete", "sshkeys:remove"
|
@@ -1,78 +0,0 @@
|
|
1
|
-
command "templates" do |c|
|
2
|
-
c.description = "List available instance templates"
|
3
|
-
c.action do |args, options|
|
4
|
-
begin
|
5
|
-
templates = Civo::Template.all
|
6
|
-
Civo::Client.tabulate_flexirest templates, {id: "Template", short_description: "Description"}
|
7
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
8
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
alias_command "template", "templates"
|
13
|
-
|
14
|
-
if Civo::Config.admin?
|
15
|
-
command "templates:create" do |c|
|
16
|
-
c.description = "Create a template (the ID should be all lower-case, hyphens and full stops)"
|
17
|
-
c.option "--name STRING", String, "The name of the template"
|
18
|
-
c.option "--image-id STRING", String, "The Openstack Image ID"
|
19
|
-
c.option "--short-description STRING", String, "A short (one-line) description of this template"
|
20
|
-
c.option "--description STRING", String, "A longer (Markdown format) description of this template"
|
21
|
-
c.option "--cloud-init-file STRING", String, "The filename of a cloud init file"
|
22
|
-
c.example "Creates a template with the ID 'ubuntu-apache' with a cloud init file called 'my-cloud-config'", 'civo template:create ubuntu-apache --image-id 12345-67890-12345 --cloud-init-file=my-cloud-config'
|
23
|
-
c.action do |args, options|
|
24
|
-
params = {
|
25
|
-
id: args[0]
|
26
|
-
}
|
27
|
-
params[:name] = options.name if options.name
|
28
|
-
params[:image_id] = options.image_id if options.image_id
|
29
|
-
params[:short_description] = options.short_description if options.short_description
|
30
|
-
params[:description] = options.description if options.description
|
31
|
-
if options.cloud_init_file
|
32
|
-
cloud_init_file = File.expand_path(options.cloud_init_file)
|
33
|
-
params[:cloud_config] = File.read(cloud_init_file) if File.exist?(cloud_init_file)
|
34
|
-
end
|
35
|
-
begin
|
36
|
-
Civo::Template.create(params)
|
37
|
-
puts "Template '#{args.first}' updated."
|
38
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
39
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
alias_command "template:create", "templates:create"
|
44
|
-
alias_command "template:new", "templates:create"
|
45
|
-
alias_command "templates:new", "templates:create"
|
46
|
-
|
47
|
-
command "templates:update" do |c|
|
48
|
-
c.description = "Update a template"
|
49
|
-
c.option "--name STRING", String, "The name of the template"
|
50
|
-
c.option "--image-id STRING", String, "The Openstack Image ID"
|
51
|
-
c.option "--short-description STRING", String, "A short (one-line) description of this template"
|
52
|
-
c.option "--description STRING", String, "A longer (Markdown format) description of this template"
|
53
|
-
c.option "--cloud-init-file STRING", String, "The filename of a cloud init file"
|
54
|
-
c.example "Updates a template with the ID 'ubuntu-apache' with a cloud init file called 'my-cloud-config'", 'civo template:update ubuntu-apache --cloud-init-file=my-cloud-config'
|
55
|
-
c.action do |args, options|
|
56
|
-
params = {
|
57
|
-
id: args[0]
|
58
|
-
}
|
59
|
-
params[:name] = options.name if options.name
|
60
|
-
params[:image_id] = options.image_id if options.image_id
|
61
|
-
params[:short_description] = options.short_description if options.short_description
|
62
|
-
params[:description] = options.description if options.description
|
63
|
-
if options.cloud_init_file
|
64
|
-
cloud_init_file = File.expand_path(options.cloud_init_file)
|
65
|
-
params[:cloud_config] = File.read(cloud_init_file) if File.exist?(cloud_init_file)
|
66
|
-
end
|
67
|
-
begin
|
68
|
-
Civo::Template.save(params)
|
69
|
-
puts "Template '#{args.first}' updated."
|
70
|
-
rescue Flexirest::HTTPUnauthorisedClientException, Flexirest::HTTPForbiddenClientException
|
71
|
-
puts "Access denied to your default token, ensure it's set correctly with 'civo tokens'"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
alias_command "template:update", "templates:update"
|
76
|
-
alias_command "template:save", "templates:update"
|
77
|
-
alias_command "templates:save", "templates:update"
|
78
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
command "tokens" do |c|
|
2
|
-
c.description = "List the tokens you have saved"
|
3
|
-
c.action do |args, options|
|
4
|
-
tokens = Civo::Token.read_all
|
5
|
-
if tokens.keys.size > 0
|
6
|
-
Civo::Client.tabulate tokens, ["Name", "API Key"]
|
7
|
-
else
|
8
|
-
puts "No tokens found, please set one using tokens:save"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
alias_command "token", "tokens"
|
13
|
-
|
14
|
-
command "tokens:save" do |c|
|
15
|
-
c.description = "Save an API token supplied by Civo.com"
|
16
|
-
c.example "Saves a token called 'master' with API key 'key_goes_here'", 'civo tokens:save master key_goes_here'
|
17
|
-
c.action do |args, options|
|
18
|
-
Civo::Token.save(args[0], args[1])
|
19
|
-
end
|
20
|
-
end
|
21
|
-
alias_command "token:save", "tokens:save"
|
22
|
-
|
23
|
-
command "tokens:default" do |c|
|
24
|
-
c.description = "Set the default token from the list you have saved"
|
25
|
-
c.example "Sets the default token to 'master'", 'civo tokens:default master'
|
26
|
-
c.action do |args, options|
|
27
|
-
Civo::Token.set_default(args[0])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
alias_command "tokens:use", "tokens:default"
|
31
|
-
alias_command "token:use", "tokens:default"
|
32
|
-
alias_command "token:default", "tokens:default"
|
33
|
-
|
34
|
-
command "tokens:remove" do |c|
|
35
|
-
c.description = "Remove a token from the list you have saved"
|
36
|
-
c.example "Removes the token 'master'", 'civo tokens:remove master'
|
37
|
-
c.action do |args, options|
|
38
|
-
Civo::Token.remove(args[0])
|
39
|
-
end
|
40
|
-
end
|
41
|
-
alias_command "token:remove", "tokens:remove"
|
data/lib/civo/cli/config.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Civo
|
2
|
-
class Config
|
3
|
-
FILENAME = "#{ENV["HOME"]}/.civorc"
|
4
|
-
|
5
|
-
def self.header_line
|
6
|
-
"# This file is managed by 'civo'\n"
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.ensure_file_exists!
|
10
|
-
unless File.exists?(FILENAME)
|
11
|
-
update({meta: {version: "1", url: "https://api.civo.com"}}).save
|
12
|
-
FileUtils.chmod(0600, FILENAME)
|
13
|
-
end
|
14
|
-
|
15
|
-
unless File.exists?(FILENAME)
|
16
|
-
puts "#{FILENAME} doesn't exist and couldn't be created"
|
17
|
-
exit 1
|
18
|
-
end
|
19
|
-
|
20
|
-
unless ("%o" % File.stat(FILENAME).mode).to_s[/600$/]
|
21
|
-
puts "The permissions on #{FILENAME} aren't 0600 (#{ ("%o" % File.stat(FILENAME).mode).to_s}), they must be for security reasons"
|
22
|
-
exit 2
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.parse
|
27
|
-
ensure_file_exists!
|
28
|
-
|
29
|
-
@config = ::TOML.load_file(FILENAME)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.api_url
|
33
|
-
parse["meta"]["url"]
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.admin?
|
37
|
-
parse["meta"]["admin"] == "true"
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.update(config)
|
41
|
-
@config = config
|
42
|
-
self
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.save
|
46
|
-
File.open(FILENAME, "w") do |f|
|
47
|
-
f << header_line
|
48
|
-
f << TOML::Generator.new(@config).body
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
data/lib/civo/cli/token.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Civo
|
2
|
-
class Token
|
3
|
-
|
4
|
-
def self.read_all
|
5
|
-
config = Civo::Config.parse
|
6
|
-
config["tokens"] || {}
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.write_all(tokens)
|
10
|
-
config = Civo::Config.parse
|
11
|
-
config["tokens"] = tokens
|
12
|
-
Civo::Config.update(config).save
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.save(name, key)
|
16
|
-
tokens = read_all
|
17
|
-
tokens[name] = key
|
18
|
-
if tokens["**DEFAULT**"] == nil
|
19
|
-
tokens["**DEFAULT**"] = name
|
20
|
-
end
|
21
|
-
write_all(tokens)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.set_default(name)
|
25
|
-
puts "Setting default token to be #{name}"
|
26
|
-
tokens = read_all
|
27
|
-
tokens["**DEFAULT**"] = name
|
28
|
-
write_all(tokens)
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.remove(name)
|
32
|
-
tokens = read_all
|
33
|
-
tokens.delete(name)
|
34
|
-
if tokens["**DEFAULT**"] == name
|
35
|
-
tokens["**DEFAULT**"] = tokens.keys.first
|
36
|
-
if tokens["**DEFAULT**"] == "**DEFAULT**"
|
37
|
-
tokens.delete("**DEFAULT**")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
write_all(tokens)
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.default
|
44
|
-
tokens = read_all
|
45
|
-
token = tokens[tokens["**DEFAULT**"]]
|
46
|
-
if token.nil?
|
47
|
-
puts "No default token has been set. Use 'civo tokens:save --name NAME --token TOKEN' to set one"
|
48
|
-
exit 2
|
49
|
-
end
|
50
|
-
token
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|