civo_cli 0.3.5 → 0.3.6

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: 978698444b706bd68c75dbee0d66e847ae5deec7094e617667964c30971d9f23
4
- data.tar.gz: 042c137693dc532f64f27873e36f3f182e7fd7d4a567d481b84b272118c54a7f
3
+ metadata.gz: 9a44df2a086732861b0ddfb002a821e58ee1f1a727ba1b788b952171df3da150
4
+ data.tar.gz: 4fe9581ac67a967491600a9e0ec971ffaecdbff3e1650480a2ed6682627bba9d
5
5
  SHA512:
6
- metadata.gz: 0ee196d1e1587e05fd0b09099151334a6264a65edec7446182d076d2a49119388d838e78bf37cfe4c48b2e1fb5e5a90bb7ec8c391796296e5d1de97f8a94ce6c
7
- data.tar.gz: de0018540d48efd6b9c0b37d27fcc83a394b5fb3be095511e449a9fb2a694c3c10478390f486f92fa8742dfe3240071a28e79953b5fa575ad1615b3dfb9aacff
6
+ metadata.gz: 8ca1c4c564db1f18c5930767636b90164c213cf9e754ab86e877d4dc95166d26f2147c674b51ea8f3e50b572de0dbd7e234a4cc50e0df2621dafc2bf5299acd2
7
+ data.tar.gz: a3730a64a3bfba67cea1b28ebda090b0dbd7b70a168b938adc26f56a52ea679472af1e214bf615b1e31869ee8ecf6c79218644666c74fe44d6ebe55bad457d43
data/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@ 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.6] - 2019-07-25
7
+ ### Added
8
+ - `kubernetes config --save` option to save a named cluster's configuration file to `~/.kube/config` (requires `kubectl` to be installed)
9
+ - `kubernetes create --wait --save` option to save a new cluster's configuration to `~/.kube/config` (requires `kubectl` to be installed)
10
+ - Aliases for `show` and `list` in methods where they are available.
11
+
12
+ ### Changed
13
+ - Make `help` the default method when base / subcommand is called with no options/arguments.
14
+
6
15
  ## [0.3.5] - 2019-07-11
7
16
  ### Removed
8
17
  - Removed password from output of `instance show`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- civo_cli (0.3.5)
4
+ civo_cli (0.3.6)
5
5
  bundler (~> 1.17)
6
6
  civo (>= 1.2.1)
7
7
  colorize
data/README.md CHANGED
@@ -278,6 +278,7 @@ You can create an instance by running `civo kubernetes create` with a cluster na
278
278
  * `size` - The size of nodes to create, from the current list of sizes available at [`civo sizes`](#sizes). Defaults to `g2.medium`.
279
279
  * `nodes` - The number of nodes to create (the master also acts as a node).
280
280
  * `wait` - a simple flag (e.g. `--wait`) that will cause the CLI to spin and wait for the cluster to be `ACTIVE`.
281
+ * `save` - a flag used in conjunction with `--wait` (i.e. `--wait --save`) to save the configuration to your local `~/.kube/config` file.
281
282
 
282
283
  ```
283
284
  $ civo kubernetes create my-first-cluster
@@ -292,6 +293,15 @@ civo kubernetes scale my-first-cluster --nodes=4
292
293
  Kubernetes cluster my-first-cluster will now have 4 nodes
293
294
  ```
294
295
 
296
+ #### Viewing or Saving the cluster configuration
297
+ To output a cluster's configuration information, you can invoke `civo kubernetes config cluster-name`. This will output the `kubeconfig` file to the screen.
298
+
299
+ You can save a cluster's configuration to your local `~/.kube/config` file. This requires `kubectl` to be installed. Usage:
300
+ ```
301
+ civo kubernetes save my-first-cluster
302
+ Saved config to ~/.kube/config
303
+ ```
304
+
295
305
  #### Renaming the cluster
296
306
  Although the name isn't used anywhere except for in the list of clusters (e.g. it's not in any way written in to the cluster), if you wish to rename a cluster you can do so with:
297
307
 
data/lib/apikey.rb CHANGED
@@ -15,6 +15,7 @@ module CivoCLI
15
15
  end
16
16
  puts Terminal::Table.new headings: ['Name', 'Key', 'Default?'], rows: rows
17
17
  end
18
+ map "ls" => "list", "all" => "list"
18
19
 
19
20
  desc "add NAME KEY", "Add the API Key 'KEY' using a label of 'NAME'"
20
21
  def add(name, key)
@@ -52,6 +53,6 @@ module CivoCLI
52
53
  end
53
54
  map "use" => "current"
54
55
 
55
- default_task :list
56
+ default_task :help
56
57
  end
57
58
  end
data/lib/blueprint.rb CHANGED
@@ -15,6 +15,7 @@ module CivoCLI
15
15
  puts e.result.reason.colorize(:red)
16
16
  exit 1
17
17
  end
18
+ map "ls" => "list", "all" => "list"
18
19
 
19
20
  desc "show ID", "show the details for a single blueprint"
20
21
  option :verbose, type: :boolean, desc: "Show the converted bash script and last run output", aliases: ["-v"]
@@ -49,6 +50,7 @@ module CivoCLI
49
50
  puts e.result.reason.colorize(:red)
50
51
  exit 1
51
52
  end
53
+ map "get" => "show", "inspect" => "show"
52
54
 
53
55
  option "content-file", type: :string, desc: "The filename of a file to be used as the Blueprintfile content", aliases: ["-c"], banner: "CONTENT_FILE"
54
56
  option "template-id", type: :string, desc: "The ID of the template to update", aliases: ["-t"], banner: "TEMPLATE_ID"
@@ -129,5 +131,6 @@ module CivoCLI
129
131
  result[0]
130
132
  end
131
133
  end
134
+ default_task :help
132
135
  end
133
136
  end
@@ -1,3 +1,3 @@
1
1
  module CivoCLI
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/lib/domain.rb CHANGED
@@ -9,6 +9,8 @@ module CivoCLI
9
9
  end
10
10
  puts Terminal::Table.new headings: ['ID', 'Name'], rows: rows
11
11
  end
12
+ map "ls" => "list", "all" => "list"
13
+
12
14
 
13
15
  desc "create DOMAIN", "create a new domain name called DOMAIN"
14
16
  def create(name)
@@ -33,7 +35,7 @@ module CivoCLI
33
35
  end
34
36
  map "delete" => "remove", "rm" => "remove"
35
37
 
36
- default_task :list
38
+ default_task :help
37
39
 
38
40
  end
39
41
  end
data/lib/domain_record.rb CHANGED
@@ -13,6 +13,8 @@ module CivoCLI
13
13
  end
14
14
  puts Terminal::Table.new headings: ['ID', 'Type', 'Name', 'Value', 'TTL', 'Priority'], rows: rows
15
15
  end
16
+ map "ls" => "list", "all" => "list"
17
+
16
18
 
17
19
  desc "show RECORD_ID", "show full information for record RECORD_ID (or full DNS name)"
18
20
  def show(record_id)
@@ -34,6 +36,7 @@ module CivoCLI
34
36
  puts e.result.reason.colorize(:red)
35
37
  exit 1
36
38
  end
39
+ map "get" => "show", "inspect" => "show"
37
40
 
38
41
  option :priority, type: :string, desc: "The priority for MX records", aliases: ["-p"], banner: "PRIORITY"
39
42
  option :ttl, type: :string, desc: "The Time-To-Live for this record", aliases: ["-t"], banner: "TTL"
@@ -95,7 +98,7 @@ module CivoCLI
95
98
  end
96
99
  map "delete" => "remove", "rm" => "remove"
97
100
 
98
- default_task :list
101
+ default_task :help
99
102
 
100
103
  private
101
104
 
data/lib/firewall.rb CHANGED
@@ -23,6 +23,7 @@ module CivoCLI
23
23
  puts e.result.reason.colorize(:red)
24
24
  exit 1
25
25
  end
26
+ map "ls" => "list", "all" => "list"
26
27
 
27
28
  desc "remove firewall_ID", "Removes a firewall with Firewall ID provided"
28
29
  def remove(firewall_ID)
@@ -81,5 +82,6 @@ module CivoCLI
81
82
  puts e.result.reason.colorize(:red)
82
83
  exit 1
83
84
  end
85
+ default_task :help
84
86
  end
85
87
  end
data/lib/instance.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  module CivoCLI
2
2
  class Instance < Thor
3
+ DEFAULT_SIZE = 'g2.small'
4
+ DEFAULT_REGION = 'lon1'
5
+ DEFAULT_INITIAL_USER = 'civo'
6
+ DEFAULT_PUBLIC_IP = 'true'
7
+ DEFAULT_TEMPLATE = '811a8dfb-8202-49ad-b1ef-1e6320b20497'
8
+
3
9
  desc "list", "list all instances"
4
10
  def list
5
11
  CivoCLI::Config.set_api_auth
@@ -11,6 +17,8 @@ module CivoCLI
11
17
  end
12
18
  puts Terminal::Table.new headings: ['ID', 'Hostname', 'Size', 'Region', 'Public IP', 'Status'], rows: rows
13
19
  end
20
+ map "ls" => "list", "all" => "list"
21
+
14
22
 
15
23
  if CivoCLI::Config.get_meta("admin")
16
24
  desc "high-cpu", "list high CPU using instances"
@@ -76,12 +84,14 @@ module CivoCLI
76
84
  puts e.result.reason.colorize(:red)
77
85
  exit 1
78
86
  end
87
+ map "get" => "show", "inspect" => "show"
79
88
 
80
89
  desc "create [HOSTNAME] [...]", "create a new instance with specified hostname and provided options"
81
- option :size, default: 'g2.small', banner: 'instance_size_code'
82
- option :region, default: 'lon1', banner: 'civo_region'
83
- option :public_ip, default: 'true', banner: 'true | false | from [instance_id]'
84
- option :initial_user, default: 'civo', banner: 'username', aliases: '--user'
90
+ option :name, aliases: '--hostname', banner: 'hostname'
91
+ option :size, default: DEFAULT_SIZE, banner: 'instance_size_code'
92
+ option :region, default: DEFAULT_REGION, banner: 'civo_region'
93
+ option :public_ip, default: DEFAULT_PUBLIC_IP, banner: 'true | false | from [instance_id]'
94
+ option :initial_user, default: DEFAULT_INITIAL_USER, banner: 'username', aliases: '--user'
85
95
  option :template, banner: 'template_id'
86
96
  option :snapshot, banner: 'snapshot_id'
87
97
  option :ssh_key, banner: 'ssh_key_id', aliases: '--ssh'
@@ -101,15 +111,23 @@ module CivoCLI
101
111
  \x5 --tags=<'tag1 tag2 tag3...'> - space-separated tag(s)
102
112
  \x5 --wait - wait for build to complete and show status. Off by default.
103
113
  LONGDESC
104
- def create(hostname = CivoCLI::NameGenerator.create, *args)
114
+ def create(*args)
105
115
  CivoCLI::Config.set_api_auth
116
+
117
+ if !options[:name] && !args
118
+ hostname = CivoCLI::NameGenerator.create
119
+ elsif options[:name]
120
+ hostname = options[:name]
121
+ elsif !options[:name] && args
122
+ hostname = args.join('-')
123
+ end
106
124
  if options[:template] && options[:snapshot]
107
125
  puts "Please provide either template OR snapshot ID".colorize(:red)
108
126
  exit 1
109
127
  end
110
128
 
111
129
  if !options[:template] && !options[:snapshot]
112
- options[:template] = '811a8dfb-8202-49ad-b1ef-1e6320b20497'
130
+ options[:template] = DEFAULT_TEMPLATE
113
131
  end
114
132
 
115
133
 
@@ -322,7 +340,7 @@ module CivoCLI
322
340
  exit 1
323
341
  end
324
342
 
325
- default_task :list
343
+ default_task :help
326
344
 
327
345
  private
328
346
 
data/lib/kubernetes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'tempfile'
2
+
1
3
  module CivoCLI
2
4
  class Kubernetes < Thor
3
5
  desc "list", "list all kubernetes clusters"
@@ -11,6 +13,8 @@ module CivoCLI
11
13
  rescue Flexirest::HTTPForbiddenClientException
12
14
  reject_user_access
13
15
  end
16
+ map "ls" => "list", "all" => "list"
17
+
14
18
 
15
19
  desc "show ID/NAME", "show a Kubernetes cluster by ID or name"
16
20
  def show(id)
@@ -43,13 +47,26 @@ module CivoCLI
43
47
  puts e.result.reason.colorize(:red)
44
48
  exit 1
45
49
  end
50
+ map "get" => "show", "inspect" => "show"
46
51
 
47
- desc "config ID/NAME", "get the ~/.kube/config for a Kubernetes cluster by ID or name"
52
+
53
+ desc "config ID/NAME [--save]", "get or save the ~/.kube/config for a Kubernetes cluster by ID or name"
54
+ option :save, type: :boolean, aliases: ['--export', '-s']
55
+ long_desc <<-LONGDESC
56
+ Gets the configuration information for a Kubernetes cluster by ID or name.
57
+ \x5Use optional parameter --save [-s or --export] to merge the fetched configuration
58
+ \x5into your Kubernetes configuration file at ~/.kube/config.
59
+ \x5Please note that this option requires you to have `kubectl` installed.
60
+ LONGDESC
48
61
  def config(id)
49
62
  CivoCLI::Config.set_api_auth
50
- rows = []
51
63
  cluster = detect_cluster(id)
52
- puts cluster.kubeconfig
64
+
65
+ if options[:save]
66
+ save_config(cluster)
67
+ else
68
+ puts cluster.kubeconfig
69
+ end
53
70
  rescue Flexirest::HTTPException => e
54
71
  puts e.result.reason.colorize(:red)
55
72
  exit 1
@@ -59,12 +76,14 @@ module CivoCLI
59
76
  option :size, default: 'g2.medium', banner: 'size'
60
77
  option :nodes, default: '3', banner: 'node_count'
61
78
  option :wait, type: :boolean
79
+ option :save, type: :boolean
62
80
  long_desc <<-LONGDESC
63
81
  Create a new Kubernetes cluster with name (randomly assigned if blank), instance size (default: g2.medium),
64
82
  \x5\x5Optional parameters are as follows:
65
83
  \x5 --size=<instance_size> - 'g2.medium' if blank. List of sizes and codes to use can be found through `civo sizes`
66
84
  \x5 --nodes=<count> - '3' if blank
67
85
  \x5 --wait - wait for build to complete and show status. Off by default.
86
+ \x5 --save - save resulting configuration to ~/.kube/config (requires kubectl and the --wait option)
68
87
  LONGDESC
69
88
  def create(name = CivoCLI::NameGenerator.create, *args)
70
89
  CivoCLI::Config.set_api_auth
@@ -83,8 +102,14 @@ module CivoCLI
83
102
  end
84
103
 
85
104
  puts "\b Done\nCreated Kubernetes cluster #{spinner[:final_cluster].name.colorize(:green)}"
105
+ elsif !options[:wait] && options[:save]
106
+ puts "Creating Kubernetes cluster #{name.colorize(:green)}. Can only save configuration once cluster is created."
86
107
  else
87
- puts "Created Kubernetes cluster #{name.colorize(:green)}"
108
+ puts "Created Kubernetes cluster #{name.colorize(:green)}."
109
+ end
110
+
111
+ if options[:save] && options[:wait]
112
+ save_config(spinner.final_cluster)
88
113
  end
89
114
  rescue Flexirest::HTTPException => e
90
115
  puts e.result.reason.colorize(:red)
@@ -139,9 +164,9 @@ module CivoCLI
139
164
  puts e.result.reason.colorize(:red)
140
165
  exit 1
141
166
  end
142
- map "delete" => "remove", "destroy" => "remove"
167
+ map "delete" => "remove", "destroy" => "remove", "rm" => "remove"
143
168
 
144
- default_task :list
169
+ default_task :help
145
170
 
146
171
  private
147
172
 
@@ -163,6 +188,26 @@ module CivoCLI
163
188
  end
164
189
  end
165
190
 
191
+ def save_config(cluster)
192
+ config_file_exists = File.exist?("#{ENV["HOME"]}/.kube/config")
193
+ tempfile = Tempfile.new('import_kubeconfig')
194
+ begin
195
+ tempfile.write(cluster.kubeconfig)
196
+ tempfile.size
197
+ result = `KUBECONFIG=#{tempfile.path}:~/.kube/config kubectl config view --flatten`
198
+ Dir.mkdir("#{ENV['HOME']}/.kube/") unless Dir.exist?("#{ENV["HOME"]}/.kube/")
199
+ File.write("#{ENV['HOME']}/.kube/config", result)
200
+ if config_file_exists
201
+ puts "Merged".colorize(:green) + " config into ~/.kube/config"
202
+ else
203
+ puts "Saved".colorize(:green) + " config to ~/.kube/config"
204
+ end
205
+ ensure
206
+ tempfile.close
207
+ tempfile.unlink
208
+ end
209
+ end
210
+
166
211
  def reject_user_access
167
212
  puts "Sorry, this functionality is currently in closed beta and not available to the public yet"
168
213
  exit(1)
data/lib/network.rb CHANGED
@@ -13,6 +13,8 @@ module CivoCLI
13
13
  end
14
14
  puts Terminal::Table.new headings: ['ID', 'Label', 'CIDR', 'Default?'], rows: rows
15
15
  end
16
+ map "ls" => "list", "all" => "list"
17
+
16
18
 
17
19
  desc "create LABEL", "create a new private network called LABEL"
18
20
  def create(label)
@@ -37,7 +39,7 @@ module CivoCLI
37
39
  end
38
40
  map "delete" => "remove", "rm" => "remove"
39
41
 
40
- default_task :list
42
+ default_task :help
41
43
 
42
44
  end
43
45
  end
data/lib/region.rb CHANGED
@@ -9,6 +9,8 @@ module CivoCLI
9
9
  end
10
10
  puts Terminal::Table.new headings: ['Code'], rows: rows
11
11
  end
12
+ map "ls" => "list", "all" => "list"
13
+
12
14
 
13
15
  default_task :list
14
16
  end
data/lib/snapshot.rb CHANGED
@@ -9,6 +9,8 @@ module CivoCLI
9
9
  end
10
10
  puts Terminal::Table.new headings: ['ID', 'Name', 'State', "Size (GB)", "Cron"], rows: rows
11
11
  end
12
+ map "ls" => "list", "all" => "list"
13
+
12
14
 
13
15
  option "cron", type: :string, desc: "The timing of when to take/repeat in cron format", aliases: ["-c"], banner: "CRON_TIMING"
14
16
  desc "create NAME INSTANCE_ID [-c '0 * * * *']", "create a snapshot called NAME from instance INSTANCE_ID"
@@ -37,7 +39,7 @@ module CivoCLI
37
39
  end
38
40
  map "delete" => "remove", "rm" => "remove"
39
41
 
40
- default_task :list
42
+ default_task :help
41
43
 
42
44
  end
43
45
  end
data/lib/sshkey.rb CHANGED
@@ -9,6 +9,8 @@ module CivoCLI
9
9
  end
10
10
  puts Terminal::Table.new headings: ['ID', 'Name', 'Fingerprint'], rows: rows
11
11
  end
12
+ map "ls" => "list", "all" => "list"
13
+
12
14
 
13
15
  desc "upload NAME FILENAME", "upload the SSH public key in FILENAME to a new key called NAME"
14
16
  def upload(name, filename)
@@ -33,6 +35,6 @@ module CivoCLI
33
35
  end
34
36
  map "delete" => "remove", "rm" => "remove"
35
37
 
36
- default_task :list
38
+ default_task :help
37
39
  end
38
40
  end
data/lib/template.rb CHANGED
@@ -17,7 +17,6 @@ module CivoCLI
17
17
  rows << [template.id, template.name]
18
18
  end
19
19
  puts Terminal::Table.new headings: ['ID', 'Name'], rows: rows
20
-
21
20
  end
22
21
 
23
22
 
@@ -25,8 +24,7 @@ module CivoCLI
25
24
  puts e.result.reason.colorize(:red)
26
25
  exit 1
27
26
  end
28
- map "ls" => "list"
29
-
27
+ map "ls" => "list", "all" => "list"
30
28
 
31
29
  desc "show ID", "show the details for a single template"
32
30
  def show(id)
@@ -47,6 +45,8 @@ module CivoCLI
47
45
  puts e.result.reason.colorize(:red)
48
46
  exit 1
49
47
  end
48
+ map "get" => "show", "inspect" => "show"
49
+
50
50
 
51
51
  option "cloud-init-file", type: :string, desc: "The filename of a file to be used as user-data/cloud-init", aliases: ["-c"], banner: "CLOUD_INIT_FILENAME"
52
52
  option :description, type: :string, desc: "A full/long multiline description", aliases: ["-d"], banner: "DESCRIPTION"
@@ -106,6 +106,6 @@ module CivoCLI
106
106
  end
107
107
  map "delete" => "remove", "rm" => "remove"
108
108
 
109
- default_task :list
109
+ default_task :help
110
110
  end
111
111
  end
data/lib/volume.rb CHANGED
@@ -10,6 +10,7 @@ module CivoCLI
10
10
  end
11
11
  puts Terminal::Table.new headings: ['ID', 'Name', 'Mounted', 'Size (GB)'], rows: rows
12
12
  end
13
+ map "ls" => "list", "all" => "list"
13
14
 
14
15
  desc "create NAME SIZE", "create a volume of SIZE (GB) called NAME"
15
16
  def create(name, size)
@@ -83,6 +84,6 @@ module CivoCLI
83
84
  exit 1
84
85
  end
85
86
 
86
- default_task :list
87
+ default_task :help
87
88
  end
88
89
  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.5
4
+ version: 0.3.6
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-07-11 00:00:00.000000000 Z
13
+ date: 2019-07-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake