civo_cli 0.3.9 → 0.3.10

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
  SHA256:
3
- metadata.gz: d62448379809416dbb023c5af87507ea6d678b099919e82a4ea0b5c3edf5f23f
4
- data.tar.gz: dadd6536e7152e2b8d40495aa4b0cccc9e57afae69dac56505d2dfd8227073c0
3
+ metadata.gz: 024560b523d64e630b4171c5246c0e346a4b43ce0255f88891a2e38a6f6638d9
4
+ data.tar.gz: 13c84db2adba712473576272c6110703ab980105aa7a9d42c0aedcdc0f41d1b2
5
5
  SHA512:
6
- metadata.gz: fa11fc73c7c3cecafc93757f7b4273a9a544998b3dee4c9a33feadc93138bb998f7b64ab43dee1a4e3eb56a1e90f8c2c0c9f6272ca0b36aab52163123a6e97dc
7
- data.tar.gz: c047daf2274eeb5c9eddc595f80c8d52764f317a3bb90b8bfad4a70e507f8245529699eb3b4a9c17f59fcc0d1c13fe840d81eddebb4a4b9c9f1fdfdc007ea77c
6
+ metadata.gz: 2461ec652f57b9543781216fb8f65998673fa3a69b2ededcd2d655f232681bc320446ca5f975b0206b043472d964df6a7dd51f80d5dc1d356107ffa79add87a3
7
+ data.tar.gz: 1d0071b595864730781b8e0646b89382d47d95318dc424704587331b34c043e03c2827b17fbf68bba3d14215d4c3688dabf2346a8d7957ca518d53ab28ae2e57
data/CHANGELOG.md CHANGED
@@ -3,7 +3,14 @@ All notable changes to the Civo CLI will be documented in this file.
3
3
 
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
- ## [0.3.8] - 2019-08-12
6
+ ## [0.3.10] - 2019-08-19
7
+ ### Added
8
+ - Alias for `instance public_ip` method as `instance ip`
9
+
10
+ ### Fixed
11
+ - File require issues on Debian Jessie preventing gem from running
12
+
13
+ ## [0.3.9] - 2019-08-12
7
14
  ### Added
8
15
  - Time taken for a `create` command appended with `--wait`.
9
16
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- civo_cli (0.3.9)
4
+ civo_cli (0.3.10)
5
5
  bundler (~> 1.17)
6
6
  civo (>= 1.2.5)
7
7
  colorize
data/README.md CHANGED
@@ -14,6 +14,7 @@ Civo CLI is a tool to manage your [Civo.com](https://www.civo.com) account from
14
14
  - [Domains and Domain Records](#domains-and-domain-records)
15
15
  - [Firewalls](#firewalls)
16
16
  - [Networks](#networks)
17
+ - [Load Balancers](#load-balancers)
17
18
  - [Quota](#quota)
18
19
  - [Sizes](#sizes)
19
20
  - [Snapshots](#snapshots)
@@ -480,6 +481,47 @@ $ civo network remove 74b69006-ea59-46a0-96c4-63f5bfa290e1
480
481
  Removed the network cli-demo with ID 74b69006-ea59-46a0-96c4-63f5bfa290e1
481
482
  ```
482
483
 
484
+ ## Load Balancers
485
+ #### Introduction
486
+ Civo supports load balancing for your instances, allowing you to spread web traffic between them to maximise availability. You can view details about load balancers you may have running, create new oness, update information and even remove them from the command line.
487
+
488
+ #### Viewing Load Balancers
489
+ You can list currently-active load balancers by calling `civo loadbalancer list`. This will draw a table detailing the unique ID, hostname, protocol, port, TLS certificate information, backend check path and connection information.
490
+
491
+ #### Creating Load Balancers
492
+ Create a new load balancer by calling `civo loadbalancer create` as well as any options you provide. The options are:
493
+ * `hostname` - A valid hostname for your load balancer. Defaults to `loadbalancer-[uuid].civo.com`.
494
+ * `protocol` - Either `http` or `https`. If you specify `https` then you must also provide the next two fields.
495
+ * `tls_certificate` - TLS certificate in Base64-encoded PEM. Required if `--protocol` is `https`.
496
+ * `tls_key` - TLS key in Base64-encoded PEM. Required if `--protocol` is `https`.
497
+ * `max_request_size` - Maximum request content size, in MB. Defaults to 20.
498
+ * `port` - Listening port. Defaults to 80 to match default `http` protocol.
499
+ * `policy` - Traffic management policy. One of: `least_conn` (sends new requests to the least busy server), `random` (sends new requests to a random backend), `round_robin` (sends new requests to the next backend in order), `ip_hash` (sends requests from a given IP address to the same backend), default is "random".
500
+ * `health_check_path` - URL to check for a valid (2xx/3xx) HTTP status on the backends. Defaults to `/`.
501
+ * `fail_timeout` - Timeout in seconds to consider a backend to have failed. Defaults to `30`.
502
+ * `max_conns` - Maximum concurrent connections to each backend. Defaults to `10`.
503
+ * `ignore_invalid_backend_tls` - Should self-signed/invalid certificates be ignored from backend servers? Defaults to `true`.
504
+ * `backend` - Specify a backend instance to associate with the load balancer. Takes `instance_id`, `protocol` and `port` in the format `--backend=instance_id: instance-id protocol: http port: 80`.
505
+ ```
506
+ $ civo loadbalancer create
507
+ Created a new Load Balancer with hostname loadbalancer-01da06bc-40ef-4d4c-bb68-d0765d288b54.civo.com
508
+ ```
509
+
510
+ #### Updating Load Balancers
511
+ Updating an existing load balancer takes the same options as creation, with the syntax being `civo loadbalancer update ID [options]`. For example, we can update the hostname of the load balancer created above using `--hostname`:
512
+ ```
513
+ $ civo loadbalancer update 01da06bc-40ef-4d4c-bb68-d0765d288b54 --hostname="civo-demo-loadbalancer.civo.com"
514
+ Updated Load Balancer
515
+ ```
516
+
517
+ #### Removing Load Balancers
518
+ Removing a load balancer is simple - simply call `civo loadbalancer remove loadbalancer_id`. Please note that this change is immediate:
519
+
520
+ ```
521
+ $ civo loadbalancer remove 01da06bc-40ef-4d4c-bb68-d0765d288b54
522
+ Removed the load balancer civo-demo-loadbalancer.civo.com with ID 01da06bc-40ef-4d4c-bb68-d0765d288b54
523
+ ```
524
+
483
525
  ## Quota
484
526
  All customers joining Civo will have a default quota applied to their account. The quota has nothing to do with charges or payments, but with the limits on the amount of simultaneous resources you can use. You can view the state of your quota at any time by running `civo quota`. Here is my current quota usage at the time of writing:
485
527
  ```
data/lib/civo_cli.rb CHANGED
@@ -5,6 +5,7 @@ require "thor"
5
5
  require "terminal-table"
6
6
  require 'colorize'
7
7
  require 'config'
8
+ require 'namegenerator'
8
9
  Dir[File.join(__dir__, '*.rb')].each { |file| require file }
9
10
 
10
11
  module CivoCLI
@@ -39,6 +40,10 @@ module CivoCLI
39
40
  subcommand "kubernetes", CivoCLI::Kubernetes
40
41
  map "k8s" => "kubernetes"
41
42
 
43
+ desc "loadbalancer", "manage load balancers"
44
+ subcommand "loadbalancer", CivoCLI::LoadBalancer
45
+ map "loadbalancers" => "loadbalancer"
46
+
42
47
  desc "network", "manage networks"
43
48
  subcommand "network", CivoCLI::Network
44
49
  map "networks" => "network"
@@ -1,3 +1,3 @@
1
1
  module CivoCLI
2
- VERSION = "0.3.9"
2
+ VERSION = "0.3.10"
3
3
  end
data/lib/instance.rb CHANGED
@@ -140,7 +140,8 @@ module CivoCLI
140
140
 
141
141
  if options[:wait]
142
142
  print "Building new instance #{hostname}: "
143
-
143
+ timer = CivoCLI::Timer.new
144
+ timer.start_timer
144
145
  spinner = CivoCLI::Spinner.spin(instance: @instance) do |s|
145
146
  Civo::Instance.all.items.each do |instance|
146
147
  if instance.id == @instance.id && instance.status == 'ACTIVE'
@@ -149,8 +150,8 @@ module CivoCLI
149
150
  end
150
151
  s[:final_instance]
151
152
  end
152
-
153
- puts "\b Done\nCreated instance #{spinner[:final_instance].hostname.colorize(:green)} - #{spinner[:final_instance].initial_user}@#{spinner[:final_instance].public_ip}"
153
+ timer.end_timer
154
+ puts "\b Done\nCreated instance #{spinner[:final_instance].hostname.colorize(:green)} - #{spinner[:final_instance].initial_user}@#{spinner[:final_instance].public_ip} in #{Time.at(timer.time_elapsed).utc.strftime("%M min %S sec")}"
154
155
  else
155
156
  puts "Created instance #{hostname.colorize(:green)}"
156
157
  end
@@ -325,6 +326,8 @@ module CivoCLI
325
326
  puts e.result.reason.colorize(:red)
326
327
  exit 1
327
328
  end
329
+ map "ip" => "public_ip"
330
+
328
331
 
329
332
  desc "password ID/HOSTNAME", "Show the default user password for instance with ID/HOSTNAME"
330
333
  option :quiet, type: :boolean, aliases: '-q'
data/lib/kubernetes.rb CHANGED
@@ -90,6 +90,8 @@ module CivoCLI
90
90
  @cluster = Civo::Kubernetes.create(name: name, target_nodes_size: options[:size], num_target_nodes: options[:nodes])
91
91
 
92
92
  if options[:wait]
93
+ timer = CivoCLI::Timer.new
94
+ timer.start_timer
93
95
  print "Building new Kubernetes cluster #{name.colorize(:green)}: "
94
96
 
95
97
  spinner = CivoCLI::Spinner.spin(instance: @instance) do |s|
@@ -101,7 +103,8 @@ module CivoCLI
101
103
  s[:final_cluster]
102
104
  end
103
105
 
104
- puts "\b Done\nCreated Kubernetes cluster #{spinner[:final_cluster].name.colorize(:green)}"
106
+ timer.end_timer
107
+ puts "\b Done\nCreated Kubernetes cluster #{name.colorize(:green)} in #{Time.at(timer.time_elapsed).utc.strftime("%M min %S sec")}"
105
108
  elsif !options[:wait] && options[:save]
106
109
  puts "Creating Kubernetes cluster #{name.colorize(:green)}. Can only save configuration once cluster is created."
107
110
  else
@@ -0,0 +1,145 @@
1
+ module CivoCLI
2
+ class LoadBalancer < Thor
3
+ desc "list", "list all load balancers"
4
+ def list
5
+ CivoCLI::Config.set_api_auth
6
+ rows = []
7
+ Civo::LoadBalancer.all.items.each do |loadbalancer|
8
+ rows << [loadbalancer.id, loadbalancer.hostname, loadbalancer.protocol, loadbalancer.port, loadbalancer.tls_certificate, loadbalancer.tls_key, loadbalancer.policy, loadbalancer.health_check_path, loadbalancer.fail_timeout, loadbalancer.max_conns, loadbalancer.ignore_invalid_backend_tls, loadbalancer.backends.items.map(&:instance_id).join(", ")]
9
+ end
10
+
11
+ puts Terminal::Table.new headings: ['ID', 'Hostname', 'Protocol', 'Port', "TLS\nCert", 'TLS key', 'Policy', "Health Check\nPath", "Fail\nTimeout", "Max.\nConnections", "Ignore Invalid\nBackend TLS?", 'Backends'], rows: rows
12
+ end
13
+ map "ls" => "list", "all" => "list"
14
+
15
+
16
+ desc "create [OPTIONS]", "create a new load balancer with options"
17
+ option :hostname, banner: 'hostname', aliases: '--name'
18
+ option :protocol, default: 'http', banner: 'http | https'
19
+ option :tls_certificate, banner: 'base64 PEM'
20
+ option :tls_key, banner: 'base64 PEM'
21
+ option :port, default: 80, type: :numeric, banner: 'listen port'
22
+ option :max_request_size, default: 20, type: :numeric, banner: 'MegaBytes'
23
+ option :policy, default: 'random', banner: 'least_conn | random | round_robin | ip_hash'
24
+ option :health_check_path, default: '/', banner: 'URL', alias: 'healthpath'
25
+ option :fail_timeout, default: 30, type: :numeric, banner: 'seconds'
26
+ option :max_conns, default: 10, type: :numeric, banner: 'connections'
27
+ option :ignore_invalid_backend_tls, default: true, type: :boolean
28
+ option :backend, default: {}, type: :hash
29
+ long_desc <<-LONGDESC
30
+ Create a new load balancer with hostname (randomly assigned if blank), and supplied options:
31
+ \x5--hostname=<hostname> - If not supplied, will be in format loadbalancer-uuid.civo.com
32
+ \x5--protocol=<http | https> - Either http or https. If you specify https then you must also provide the next two fields
33
+ \x5--tls_certificate=<base64 PEM> - TLS certificate in Base64-encoded PEM. Required if --protocol is https
34
+ \x5--tls_key=<base64 PEM> - TLS key in Base64-encoded PEM. Required if --protocol is https
35
+ \x5--port=<n> - Port to listen on. Defaults to 80 to match default protocol
36
+ \x5--max_request_size=<nn> - Maximum request content size, in MB
37
+ \x5--policy=<least_conn | random | round_robin | ip_hash> - Balancing policy to choose backends
38
+ \x5--health_check_path=<URL> - Which URL to use to determine if backend status is OK (2xx/3xx status)
39
+ \x5--fail_timeout=<seconds> - Backend timeout in seconds
40
+ \x5--max_conns=<connections> - Maximum concurrent connections to each backend
41
+ \x5--ignore_invalid_backend_tls=<true | false> - Should self-signed/invalid certificates be ignored from the backend servers?
42
+ \x5--backend=<instance_id:instance_id protocol:http | https port:number> - A backend instance, with the instance ID, desired protocol and port number specified.
43
+ LONGDESC
44
+ def create(*args)
45
+ CivoCLI::Config.set_api_auth
46
+ backends = {}
47
+ options[:backend].each do | key, value |
48
+ backends[key] = value
49
+ end
50
+ backendarray = []
51
+ backendarray << backends
52
+ loadbalancer = Civo::LoadBalancer.create(hostname: options[:hostname] ||= nil,
53
+ protocol: options[:protocol],
54
+ tls_certificate: options[:tls_certificate],
55
+ tls_key: options[:tls_key],
56
+ port: options[:port],
57
+ max_request_size: options[:max_request_size],
58
+ policy: options[:policy],
59
+ health_check_path: options[:health_check_path],
60
+ fail_timeout: options[:fail_timeout],
61
+ max_conns: options[:max_conns],
62
+ ignore_invalid_backend_tls: options[:ignore_invalid_backend_tls],
63
+ backends: backendarray)
64
+
65
+ puts "Created a new Load Balancer with hostname #{loadbalancer.hostname.colorize(:green)}"
66
+
67
+ rescue Flexirest::HTTPException => e
68
+ puts e.result.reason.colorize(:red)
69
+ exit 1
70
+ end
71
+ map "new" => "create"
72
+
73
+ desc "update ID [OPTIONS]", "update the load balancer ID with options provided"
74
+ option :hostname, banner: 'hostname', aliases: '--name'
75
+ option :protocol, default: 'http', banner: 'http | https'
76
+ option :tls_certificate, banner: 'base64 PEM'
77
+ option :tls_key, banner: 'base64 PEM'
78
+ option :port, lazy_default: 80, type: :numeric, banner: 'listen port'
79
+ option :max_request_size, lazy_default: 20, type: :numeric, banner: 'MegaBytes'
80
+ option :policy, lazy_default: 'random', banner: 'least_conn | random | round_robin | ip_hash'
81
+ option :health_check_path, lazy_default: '/', banner: 'URL', alias: 'healthpath'
82
+ option :fail_timeout, lazy_default: 30, type: :numeric, banner: 'seconds'
83
+ option :max_conns, lazy_default: 10, type: :numeric, banner: 'connections'
84
+ option :ignore_invalid_backend_tls, lazy_default: true, type: :boolean
85
+ option :backend, default: {}, type: :hash
86
+ long_desc <<-LONGDESC
87
+ Update a load balancer with ID provided, and any of the following options:
88
+ \x5--hostname=<hostname> - New hostname
89
+ \x5--protocol=<http | https> - Either http or https. If you specify https then you must also provide the next two fields
90
+ \x5--tls_certificate=<base64 PEM> - TLS certificate in Base64-encoded PEM. Required if --protocol is https
91
+ \x5--tls_key=<base64 PEM> - TLS key in Base64-encoded PEM. Required if --protocol is https
92
+ \x5--port=<n> - Port to listen on. Defaults to 80 to match default protocol
93
+ \x5--max_request_size=<nn> - Maximum request content size, in MB
94
+ \x5--policy=<least_conn | random | round_robin | ip_hash> - Balancing policy to choose backends
95
+ \x5--health_check_path=<URL> - Which URL to use to determine if backend status is OK (2xx/3xx status)
96
+ \x5--fail_timeout=<seconds> - Backend timeout in seconds
97
+ \x5--max_conns=<connections> - Maximum concurrent connections to each backend
98
+ \x5--ignore_invalid_backend_tls=<true | false> - Should self-signed/invalid certificates be ignored from the backend servers?
99
+ \x5--backend=<instance_id:instance_id protocol:http | https port:number> - A backend instance, with the instance ID, desired protocol and port number specified.
100
+ LONGDESC
101
+ def update(id, hostname = nil, protocol = nil, tls_certificate = nil, tls_key = nil, port = nil, max_request_size = nil, policy = nil, health_check_path = nil, fail_timeout = nil, max_conns = nil, ignore_invalid_backend_tls = nil, backend = nil)
102
+ CivoCLI::Config.set_api_auth
103
+ loadbalancer = Civo::LoadBalancer.all.items.detect {|key| key.id == id}
104
+ if options[:backend]
105
+ backends = {}
106
+ options[:backend].each do | key, value |
107
+ backends[key] = value
108
+ end
109
+ backendarray = []
110
+ backendarray << backends
111
+ end
112
+ Civo::LoadBalancer.update(id: loadbalancer.id,
113
+ hostname: options[:hostname] || loadbalancer.hostname,
114
+ protocol: options[:protocol] || loadbalancer.protocol,
115
+ tls_certificate: options[:tls_certificate] || loadbalancer.tls_certificate,
116
+ tls_key: options[:tls_key] || loadbalancer.tls_key,
117
+ port: options[:port] || loadbalancer.port,
118
+ max_request_size: options[:max_request_size] || loadbalancer.max_request_size,
119
+ policy: options[:policy] || loadbalancer.policy,
120
+ health_check_path: options[:health_check_path] || loadbalancer.health_check_path,
121
+ fail_timeout: options[:fail_timeout] || loadbalancer.fail_timeout,
122
+ max_conns: options[:max_conns] || loadbalancer.max_conns,
123
+ ignore_invalid_backend_tls: options[:ignore_invalid_backend_tls] || loadbalancer.ignore_invalid_backend_tls,
124
+ backends: backendarray || loadbalancer.backends
125
+ )
126
+ puts "Updated Load Balancer #{loadbalancer.hostname.colorize(:green)}"
127
+ end
128
+ map "change" => "update"
129
+
130
+ desc "remove ID", "remove the load balancer with ID"
131
+ def remove(id)
132
+ CivoCLI::Config.set_api_auth
133
+ loadbalancer = Civo::LoadBalancer.all.items.detect {|key| key.id == id}
134
+ Civo::LoadBalancer.remove(id: id)
135
+ puts "Removed the load balancer #{loadbalancer.hostname.colorize(:green)} with ID #{loadbalancer.id.colorize(:green)}"
136
+ rescue Flexirest::HTTPException => e
137
+ puts e.result.reason.colorize(:red)
138
+ exit 1
139
+ end
140
+ map "delete" => "remove", "rm" => "remove"
141
+
142
+ default_task :help
143
+
144
+ end
145
+ end
data/lib/snapshot.rb CHANGED
@@ -16,7 +16,6 @@ module CivoCLI
16
16
  desc "create NAME INSTANCE_ID [-c '0 * * * *']", "create a snapshot called NAME from instance INSTANCE_ID"
17
17
  def create(name, instance_id)
18
18
  CivoCLI::Config.set_api_auth
19
- puts options.inspect
20
19
  params = {name: name, instance_id: instance_id}
21
20
  params[:cron_timing] = options["cron"] unless options["cron"].nil?
22
21
  snapshot = Civo::Snapshot.create(params)
data/lib/timer.rb ADDED
@@ -0,0 +1,16 @@
1
+ module CivoCLI
2
+ class Timer
3
+
4
+ attr_accessor :time_elapsed
5
+
6
+ def start_timer
7
+ @start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
8
+ end
9
+
10
+ def end_timer
11
+ end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
12
+
13
+ @time_elapsed = (end_time - @start_time).round(2)
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: civo_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2019-08-12 00:00:00.000000000 Z
13
+ date: 2019-08-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -214,6 +214,7 @@ files:
214
214
  - lib/firewall.rb
215
215
  - lib/instance.rb
216
216
  - lib/kubernetes.rb
217
+ - lib/loadbalancer.rb
217
218
  - lib/namegenerator.rb
218
219
  - lib/network.rb
219
220
  - lib/quota.rb
@@ -224,6 +225,7 @@ files:
224
225
  - lib/sshkey.rb
225
226
  - lib/sub_command_base.rb
226
227
  - lib/template.rb
228
+ - lib/timer.rb
227
229
  - lib/volume.rb
228
230
  homepage: https://www.civo.com/api
229
231
  licenses: