civo_cli 0.1.0 → 0.1.1

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: 927ddbd3f24ce34b813e67e1b2272aa26246901174c381a2d50c1ecaba04ef2f
4
- data.tar.gz: f3fca2349b9447087fe43fcbf560469ebab6c891586cfd1627605233b90a9eab
3
+ metadata.gz: d11ea9765c6587f9b9fe117fb9c3ff15b50cae5fddd6110191f71c819e235b9e
4
+ data.tar.gz: cb754f79de7af4b2072c0ecbe51285887d7688f0c569d9057fb466112a3da331
5
5
  SHA512:
6
- metadata.gz: 32fa783327ab26f639c58cfff0bf6e199b8a955d8b5ba0f6330671ab0ee9bca1739252d1dab609091205695391e068132220a31c8780a273bf5ee217caf5d5e6
7
- data.tar.gz: 7118dc6fc3c150b1e5329ca122f1cd4cf2939f73798c7346385c2822e6c2152e65e9d3d3fe8699a302693de76acced627e3b3795ff130f521275c3c1de89bfbc
6
+ metadata.gz: efcabbc75b6bf60c6750a1b7b0dcc8359211ef6ad69139691f925bcd99fe340150cf05206cb695416a187515855fe94e59b6f904d556aea9e8461524bfab47bf
7
+ data.tar.gz: cabfc6bfdcf8dd8cbfd7606f42c23cb4881c3960ff7cee8198102e23484acabb7d40d7103940a4fa8a5cbde01c19fbec0008e80ca9e44e4e799cb219daeffe82
data/CHANGELOG.md CHANGED
@@ -1,2 +1,10 @@
1
- # Civo CLI Changlog
1
+ # Changelog
2
+ All notable changes to the Civo CLI will be documented in this file.
2
3
 
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
+
6
+ ## [0.12.0] - 2017-06-20
7
+ ### Rewrote
8
+ - Written new version in Ruby for ease of maintenance that replaces the old [Go-based CLI](https://github.com/absolutedevops/civo)
9
+
10
+ [1.0.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.3.0...v1.0.0
data/Gemfile.lock ADDED
@@ -0,0 +1,128 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ civo_cli (0.1.1)
5
+ civo (>= 1.1.14)
6
+ colorize
7
+ json
8
+ terminal-table
9
+ thor
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (5.2.3)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ addressable (2.6.0)
20
+ public_suffix (>= 2.0.2, < 4.0)
21
+ civo (1.1.14)
22
+ commander
23
+ flexirest (>= 1.4.6)
24
+ toml
25
+ coderay (1.1.2)
26
+ colorize (0.8.1)
27
+ commander (4.4.7)
28
+ highline (~> 2.0.0)
29
+ concurrent-ruby (1.1.5)
30
+ crack (0.4.3)
31
+ safe_yaml (~> 1.0.0)
32
+ diff-lcs (1.3)
33
+ faraday (0.15.4)
34
+ multipart-post (>= 1.2, < 3)
35
+ ffi (1.10.0)
36
+ flexirest (1.7.6)
37
+ activesupport
38
+ crack
39
+ faraday
40
+ multi_json
41
+ formatador (0.2.5)
42
+ guard (2.15.0)
43
+ formatador (>= 0.2.4)
44
+ listen (>= 2.7, < 4.0)
45
+ lumberjack (>= 1.0.12, < 2.0)
46
+ nenv (~> 0.1)
47
+ notiffany (~> 0.0)
48
+ pry (>= 0.9.12)
49
+ shellany (~> 0.0)
50
+ thor (>= 0.18.1)
51
+ guard-compat (1.2.1)
52
+ guard-rspec (4.7.3)
53
+ guard (~> 2.1)
54
+ guard-compat (~> 1.1)
55
+ rspec (>= 2.99.0, < 4.0)
56
+ hashdiff (0.3.8)
57
+ highline (2.0.1)
58
+ i18n (1.6.0)
59
+ concurrent-ruby (~> 1.0)
60
+ json (2.2.0)
61
+ listen (3.1.5)
62
+ rb-fsevent (~> 0.9, >= 0.9.4)
63
+ rb-inotify (~> 0.9, >= 0.9.7)
64
+ ruby_dep (~> 1.2)
65
+ lumberjack (1.0.13)
66
+ method_source (0.9.2)
67
+ minitest (5.11.3)
68
+ multi_json (1.13.1)
69
+ multipart-post (2.0.0)
70
+ nenv (0.3.0)
71
+ notiffany (0.1.1)
72
+ nenv (~> 0.1)
73
+ shellany (~> 0.0)
74
+ parslet (1.8.2)
75
+ pry (0.12.2)
76
+ coderay (~> 1.1.0)
77
+ method_source (~> 0.9.0)
78
+ public_suffix (3.0.3)
79
+ rake (10.5.0)
80
+ rb-fsevent (0.10.3)
81
+ rb-inotify (0.10.0)
82
+ ffi (~> 1.0)
83
+ rspec (3.8.0)
84
+ rspec-core (~> 3.8.0)
85
+ rspec-expectations (~> 3.8.0)
86
+ rspec-mocks (~> 3.8.0)
87
+ rspec-core (3.8.0)
88
+ rspec-support (~> 3.8.0)
89
+ rspec-expectations (3.8.2)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.8.0)
92
+ rspec-mocks (3.8.0)
93
+ diff-lcs (>= 1.2.0, < 2.0)
94
+ rspec-support (~> 3.8.0)
95
+ rspec-support (3.8.0)
96
+ ruby_dep (1.5.0)
97
+ safe_yaml (1.0.5)
98
+ shellany (0.0.1)
99
+ terminal-notifier-guard (1.7.0)
100
+ terminal-table (1.8.0)
101
+ unicode-display_width (~> 1.1, >= 1.1.1)
102
+ thor (0.20.3)
103
+ thread_safe (0.3.6)
104
+ toml (0.2.0)
105
+ parslet (~> 1.8.0)
106
+ tzinfo (1.2.5)
107
+ thread_safe (~> 0.1)
108
+ unicode-display_width (1.4.1)
109
+ webmock (3.5.1)
110
+ addressable (>= 2.3.6)
111
+ crack (>= 0.3.2)
112
+ hashdiff
113
+
114
+ PLATFORMS
115
+ ruby
116
+
117
+ DEPENDENCIES
118
+ bundler (~> 1.17)
119
+ civo_cli!
120
+ guard
121
+ guard-rspec
122
+ rake (~> 10.0)
123
+ rspec (~> 3.0)
124
+ terminal-notifier-guard
125
+ webmock
126
+
127
+ BUNDLED WITH
128
+ 1.17.2
data/Guardfile ADDED
@@ -0,0 +1,43 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "RUBYOPT=W0 bundle exec rspec", all_on_start: true, title: "Ruby Civo CLI Specs" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ end
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Andy Jeffries
3
+ Copyright (c) 2019 Aboslute Devops Ltd
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,28 +1,201 @@
1
- # CivoCli
1
+ # Civo Command-Line Client
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/civo_cli`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This utility is for interacting with the Civo Cloud API provided on Civo.com. In order to use the API you need an API key, which is available when you're logged in to Civo.com at https://www.civo.com/api.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Installation/overview
6
6
 
7
- ## Installation
7
+ The first step should be to download the client. This is simply done using:
8
8
 
9
- Add this line to your application's Gemfile:
9
+ ```
10
+ gem install civo_cli
11
+ ```
12
+
13
+ You'll then need to run a command in a Terminal to register your API key with the client. Let's take the example that your company is called "Acme Widgets" and your API key is "123456789012345678901234567890". You need to give the API key a short reference when saving it, such as `acme` (because you can register multiple API keys for different accounts in the same client):
14
+
15
+ ```
16
+ civo apikeys save -n acme -k 123456789012345678901234567890
17
+ ```
18
+
19
+ You will then need to set this as your default apikey to be used in all future requests with:
20
+
21
+ ```
22
+ civo apikeys default -n acme
23
+ ```
24
+
25
+ Now you are free to use the remaining commands in the system. We'll work through the most common ones below, the rest are normally used by Civo administrators (and the permission levels associated with your apikey in CIvo won't allow you to make them).
26
+
27
+ In order to discover the available commands you can use `civo -h` to list the available commands, then use `civo [command] -h` to list sub commands and so on further down the line. For example:
28
+
29
+ ```
30
+ civo -h
31
+ civo instances -h
32
+ civo instances create -h
33
+ ```
34
+
35
+ In this way all the possible things you can do with the client are discoverable.
36
+
37
+
38
+ ## SSH keys
39
+
40
+ One of the first things you'll likely want to do is upload your SSH public key, so that you can SSH in to new instances - you can't create a new instance without this step.
41
+
42
+ Assuming your public key is in `~/.ssh/id_rsa.pub` (if it isn't, you'll probably know why and where it is) you can upload this with:
43
+
44
+ ```
45
+ civo sshkey upload --name default --public-key ~/.ssh/id_rsa.pub
46
+ ```
47
+
48
+ If you want to remove a public key (say you are replacing it with a new one), you can do this with:
49
+
50
+ ```
51
+ civo sshkey delete --name default
52
+ ```
53
+
54
+ **Note:** This won't remove it from your currently running instances, it will only affect new instances created.
55
+
56
+
57
+ ## Choosing the specification of an instance
58
+ When creating an instance, you'll need to specify items such as the size of instance, which region to create it in (if your provider supports multiple regions) and the template to use (from the available operating systems, versions and layered applications).
59
+
60
+ The information on all of these are available by running `civo size`, `civo region` and `civo template`. The output of the command will give you the key to use when creating the instance. For example (and these are subject to change):
61
+
62
+ ```
63
+ $ civo size
64
+ +-----------+----------------------------------------------------+
65
+ | Name | Specification |
66
+ +-----------+----------------------------------------------------+
67
+ | g1.xsmall | Extra Small - 512MB RAM, 1 CPU Core, 20GB SSD Disk |
68
+ | g1.small | Small - 1GB RAM, 2 CPU Cores, 50GB SSD Disk |
69
+ | g1.medium | Medium - 2GB RAM, 4 CPU Cores, 100GB SSD Disk |
70
+ | g1.large | Large - 4GB RAM, 6 CPU Cores, 150GB SSD Disk |
71
+ | g1.xlarge | Extra Large - 8GB RAM, 8 CPU Cores, 200GB SSD Disk |
72
+ +-----------+----------------------------------------------------+
73
+
74
+ $ civo template
75
+ +--------------------+------------------------------------------------------------------------+
76
+ | ID | Description |
77
+ +--------------------+------------------------------------------------------------------------+
78
+ | centos-7 | CentOS version 7 (RHEL open source clone) |
79
+ | ubuntu-14.04-vesta | Canonical's Ubuntu 14.04 with the Vesta Control Panel |
80
+ | ubuntu-14.04 | Canonical's Ubuntu 14.04 installed in a minimal configuration |
81
+ +--------------------+------------------------------------------------------------------------+
82
+ ```
83
+
84
+
85
+ ## Managing instances
86
+
87
+ To view the list of your currently running instances you can simply run:
88
+
89
+ ```
90
+ civo instance
91
+ ```
92
+
93
+ This will output a table listing the instances currently in your account:
94
+
95
+ ```
96
+ +----------+-------------------+----------+-------------------------------+--------+------+--------------+
97
+ | ID | Name | Size | IP Addresses | Status | User | Password |
98
+ +----------+-------------------+----------+-------------------------------+--------+------+--------------+
99
+ | 8043d0e7 | test1.example.com | g1.small | 10.0.0.2=>31.28.88.103 | ACTIVE | civo | jioAQfSDffFS |
100
+ +----------+-------------------+----------+-------------------------------+--------+------+--------------+
101
+ ```
10
102
 
11
- ```ruby
12
- gem 'civo_cli'
103
+ Creating an instance is a simple command away (remember, if you can't remember the parameters `civo instance create -h` is there to help you) using something like:
104
+
105
+ ```
106
+ civo instance create --name test2.example.com --size g1.small \
107
+ --region svg1 --ssh-key-id default --template ubuntu-14.04 --public-ip
108
+ ```
109
+
110
+ If you don't specify a name, a random one will be created for you.
111
+
112
+ **Note:** Specifying the name will set the hostname on the machine but won't affect DNS resolution, currently that's up to you to provide separately.
113
+
114
+ If you decide you don't need an instance any more you can remove it by simply calling `civo instance destroy` passing in either the ID or the name, using the details above as an example:
115
+
116
+ ```
117
+ civo instance destroy -i8043d0e7
118
+ civo instance destroy --id=test1.example.com
119
+ ```
120
+
121
+ **Note:** The machine will be forever destroyed at this point, you can't get the data back from the hard drive afterwards.
122
+
123
+ If your machine gets stuck you can restart it with (again using either the ID or the name):
124
+
125
+ ```
126
+ civo instance reboot --id=8043d0e7
127
+ ```
128
+
129
+ If it's *really* stuck (i.e. hard kernel lock) then you can do the cloud equivalent of unplugging it and plugging it back in with the addition of the hard switch:
130
+
131
+ ```
132
+ civo instance reboot --hard --id=8043d0e7
133
+ ```
134
+
135
+ ## Snapshots (backups)
136
+
137
+ If you want to take a snapshot of an instance, you can do this using a single command line like this:
138
+
139
+ ```
140
+ civo snapshot create --name my-backup --instance 8043d0e7 --safe
13
141
  ```
14
142
 
15
- And then execute:
143
+ The name can be anything you choose, it won't conflict if you create two snapshots with the same name (but it will make it harder for you to remember which is which). The instance has to be part of the ID or a unique part of the hostname. The `--safe` is optional - without this switch it will snapshot your instance while it runs, with the flag it will shut the instance down first, take a snapshot then start it back up. The reason it's referred to as `safe` is that if you snapshot a running instance, any database server may be the middle of rewriting files for example, leaving them in a half-rewritten and hence corrupted state. If you know your machine is in a good state (say it's an application server), then you can snapshot while it's running.
16
144
 
17
- $ bundle
145
+ ## Firewalls
18
146
 
19
- Or install it yourself as:
147
+ By default all ports and protocols are open on your instance. We would recommend either using something like [iptables](http://netfilter.org/projects/iptables/) or [Ucomplicated Fire Wall](https://help.ubuntu.com/community/UFW) on the instance, or using the Civo firewall functionality which sits outside your instance (and hence can't be turned off if the machine is compromised).
20
148
 
21
- $ gem install civo_cli
149
+ The first step is to create a new firewall with:
22
150
 
23
- ## Usage
151
+ ```
152
+ civo firewall create --name my-firewall
153
+ ```
154
+
155
+ For confirmation that this has worked you can run `civo firewall` to list the firewalls. Then you can add rules to it with commands like (to allow incoming SSH and pings):
156
+
157
+ ```
158
+ civo firewall rules create my-firewall -p tcp -s 22
159
+ civo firewall rules create my-firewall -p icmp
160
+ ```
161
+
162
+ You can check that it's configured correctly by running `civo firewall rules my-firewall`. Now that you're sure your firewall is configured, you can assign it to one or more instances with:
163
+
164
+ ```
165
+ civo instances firewall --id=8043d0e7 --firewall my-firewall
166
+ ```
167
+
168
+ If you make a mistake at any point, you can revert to the default firewall by simply running the same command without `--firewall ...`, for example:
24
169
 
25
- TODO: Write usage instructions here
170
+ ```
171
+ civo instances firewall --id=8043d0e7
172
+ ```
173
+
174
+ ## Quota
175
+
176
+ All Civo users have a limited quota applied to their account (to stop errant scripts from filling up the cloud with a million instances). You can view your current quota using a command like this:
177
+
178
+ ```
179
+ $ civo quota
180
+ +---------------------------------------+------+-------+
181
+ | Title | Used | Limit |
182
+ +---------------------------------------+------+-------+
183
+ | Number of instances | 0 | 10 |
184
+ | Total CPU cores | 0 | 20 |
185
+ | Total RAM (MB) | 0 | 5120 |
186
+ | Total disk space (GB) | 0 | 250 |
187
+ | Disk volumes | 0 | 10 |
188
+ | Disk snapshots | 0 | 30 |
189
+ | Public IP addresses | 0 | 10 |
190
+ | Private subnets | 0 | 1 |
191
+ | Private networks | 0 | 1 |
192
+ | Security groups | 0 | 10 |
193
+ | Security group rules | 0 | 100 |
194
+ | Number of ports (network connections) | 0 | 20 |
195
+ +---------------------------------------+------+-------+
196
+ ```
197
+
198
+ If you want to increase them, contact us via Civo.com.
26
199
 
27
200
  ## Development
28
201
 
@@ -30,10 +203,18 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
30
203
 
31
204
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
205
 
206
+ For more information on some commonly used Gems in this project see:
207
+
208
+ * [Civo API](https://github.com/absolutedevops/civo-ruby)
209
+ * [Thor](http://whatisthor.com/)
210
+ * [Terminal Table](https://github.com/tj/terminal-table)
211
+ * [Colorize](https://github.com/fazibear/colorize)
212
+
33
213
  ## Contributing
34
214
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/andyjeffries/civo_cli.
215
+ Bug reports and pull requests are welcome on GitHub at https://github.com/civo/cli.
36
216
 
37
217
  ## License
38
218
 
39
219
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
220
+
data/civo_cli.gemspec CHANGED
@@ -5,9 +5,9 @@ require "civo_cli/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "civo_cli"
8
- spec.version = CivoCli::VERSION
9
- spec.authors = ["Andy Jeffries"]
10
- spec.email = ["andy@absolutedevops.io"]
8
+ spec.version = CivoCLI::VERSION
9
+ spec.authors = ["Andy Jeffries", "Absolute Devops Ltd"]
10
+ spec.email = ["andy@absolutedevops.io", "hello@civo.com"]
11
11
 
12
12
  spec.summary = %q{CLI for interacting with Civo.com}
13
13
  spec.description = %q{The official command line client for interacting with Civo's API}
@@ -36,7 +36,19 @@ Gem::Specification.new do |spec|
36
36
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
37
  spec.require_paths = ["lib"]
38
38
 
39
+ spec.required_ruby_version = '~> 2.0'
40
+
39
41
  spec.add_development_dependency "bundler", "~> 1.17"
40
42
  spec.add_development_dependency "rake", "~> 10.0"
41
43
  spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_development_dependency "guard"
45
+ spec.add_development_dependency "guard-rspec"
46
+ spec.add_development_dependency 'terminal-notifier-guard'
47
+ spec.add_development_dependency 'webmock'
48
+
49
+ spec.add_runtime_dependency 'terminal-table'
50
+ spec.add_runtime_dependency 'thor'
51
+ spec.add_runtime_dependency 'colorize'
52
+ spec.add_runtime_dependency 'civo', ">= 1.1.14"
53
+ spec.add_runtime_dependency 'json'
42
54
  end
data/exe/civo CHANGED
@@ -3,3 +3,4 @@
3
3
  require "bundler/setup"
4
4
  require "civo_cli"
5
5
 
6
+ CivoCLI::Main.start(ARGV) if __FILE__ == $0
data/lib/apikey.rb ADDED
@@ -0,0 +1,50 @@
1
+ module CivoCLI
2
+ class APIKey < Thor
3
+ desc "list", "List all stored API keys"
4
+ def list
5
+ keys = CivoCLI::Config.get_apikeys
6
+ default = CivoCLI::Config.get_meta(:current_apikey)
7
+
8
+ rows = []
9
+ keys.each do |label, key|
10
+ if label == default
11
+ rows << [label, key, "<====="]
12
+ else
13
+ rows << [label, key, ""]
14
+ end
15
+ end
16
+ puts Terminal::Table.new headings: ['Name', 'Key', 'Default?'], rows: rows
17
+ end
18
+
19
+ desc "add NAME KEY", "Add the API Key 'KEY' using a label of 'NAME'"
20
+ def add(name, key)
21
+ CivoCLI::Config.set_apikey(name, key)
22
+ puts "Saved the API Key #{key.colorize(:green)} as #{name.colorize(:green)}"
23
+ end
24
+
25
+ desc "remove NAME", "Remove the API Key with a label of 'NAME'"
26
+ def remove(name)
27
+ CivoCLI::Config.delete_apikey(name)
28
+ puts "Removed the API Key #{name.colorize(:green)}"
29
+ end
30
+ map "delete" => "remove", "rm" => "remove"
31
+
32
+ desc "current [NAME]", "Either return the name of the current API key or set the current key to be the one with a label of 'NAME'"
33
+ def current(name=nil)
34
+ if name.nil?
35
+ puts "The current API Key is #{CivoCLI::Config.get_current_apikey_name.colorize(:green)}"
36
+ else
37
+ keys = CivoCLI::Config.get_apikeys
38
+ if keys.keys.include?(name)
39
+ CivoCLI::Config.set_meta(:current_apikey, name)
40
+ puts "The current API Key is now #{CivoCLI::Config.get_current_apikey_name.colorize(:green)}"
41
+ else
42
+ puts "The API Key #{name.colorize(:red)} couldn't be found, so it could not be set as default"
43
+ exit 1
44
+ end
45
+ end
46
+ end
47
+
48
+ default_task :list
49
+ end
50
+ end
data/lib/blueprint.rb ADDED
@@ -0,0 +1,83 @@
1
+ module CivoCLI
2
+ class Blueprint < Thor
3
+ desc "list", "list all blueprints"
4
+ def list
5
+ CivoCLI::Config.set_api_auth
6
+ rows = []
7
+ Civo::Blueprint.all.items.each do |blueprint|
8
+ rows << [blueprint.id, blueprint.name, blueprint.template_id, blueprint.version, blueprint.last_build_ended_at]
9
+ end
10
+ puts Terminal::Table.new headings: ['ID', 'Name', 'Template ID', 'Version', "Last built"], rows: rows
11
+ rescue Flexirest::HTTPException => e
12
+ puts e.result.reason.colorize(:red)
13
+ exit 1
14
+ end
15
+
16
+ desc "show ID", "show the details for a single blueprint"
17
+ def show(id)
18
+ CivoCLI::Config.set_api_auth
19
+ blueprint = Civo::Blueprint.all.detect {|b| b.id == id }
20
+ puts " ID : #{blueprint.id}"
21
+ puts " Name : #{blueprint.name}"
22
+ puts " Template ID : #{blueprint.template_id}"
23
+ puts " Version : #{blueprint.version}"
24
+ puts "Last Build Started : #{blueprint.last_build_started_at&.strftime("%-d %B %Y, %H:%M:%S")}"
25
+ puts " Last Build Ended : #{blueprint.last_build_ended_at&.strftime("%-d %B %Y, %H:%M:%S")}"
26
+ puts ""
27
+ puts "-" * 29 + " CONTENT " + "-" * 29
28
+ puts ""
29
+ puts blueprint.dsl_content
30
+ rescue Flexirest::HTTPException => e
31
+ puts e.result.reason.colorize(:red)
32
+ exit 1
33
+ end
34
+
35
+ option "content-file", type: :string, desc: "The filename of a file to be used as the Blueprintfile content", aliases: ["-c"], banner: "CONTENT_FILE"
36
+ option "template-id", type: :string, desc: "The ID of the template to update", aliases: ["-t"], banner: "TEMPLATE_ID"
37
+ option :name, type: :string, desc: "A nice name to be used for the blueprint", aliases: ["-n"], banner: "NICE_NAME"
38
+ desc "update ID", "update the blueprint with ID"
39
+ def update(id)
40
+ CivoCLI::Config.set_api_auth
41
+ params = {id: id}
42
+ params[:dsl_content] = File.read(options["content-file"]) unless options["content-file"].nil?
43
+ params[:template_id] = options["template-id"] unless options["template-id"].nil?
44
+ params[:name] = options["name"] unless options["name"].nil?
45
+ Civo::Blueprint.save(params)
46
+ blueprint = Civo::Blueprint.all.detect {|b| b.id == id }
47
+ puts "Updated blueprint #{blueprint.name.colorize(:green)}"
48
+ rescue Flexirest::HTTPException => e
49
+ puts e.result.reason.colorize(:red)
50
+ exit 1
51
+ end
52
+
53
+ option "content-file", type: :string, desc: "The filename of a file to be used as the Blueprintfile content", aliases: ["-c"], banner: "CONTENT_FILE"
54
+ option "template-id", type: :string, desc: "The ID of the template to update", aliases: ["-t"], banner: "TEMPLATE_ID"
55
+ option :name, type: :string, desc: "A nice name to be used for the blueprint", aliases: ["-n"], banner: "NICE_NAME"
56
+ desc "create", "create a new blueprint"
57
+ def create
58
+ CivoCLI::Config.set_api_auth
59
+ params = {}
60
+ params[:dsl_content] = File.read(options["content-file"]) unless options["content-file"].nil?
61
+ params[:template_id] = options["template-id"] unless options["template-id"].nil?
62
+ params[:name] = options["name"] unless options["name"].nil?
63
+ blueprint = Civo::Blueprint.create(params)
64
+ puts "Created blueprint #{blueprint.name.colorize(:green)} with ID #{blueprint.id.colorize(:green)}"
65
+ rescue Flexirest::HTTPException => e
66
+ puts e.result.reason.colorize(:red)
67
+ exit 1
68
+ end
69
+ map "new" => "create"
70
+
71
+ desc "remove ID", "remove the blueprint with ID"
72
+ def remove(id)
73
+ CivoCLI::Config.set_api_auth
74
+ Civo::Blueprint.remove(id)
75
+ rescue Flexirest::HTTPException => e
76
+ puts e.result.reason.colorize(:red)
77
+ exit 1
78
+ end
79
+ map "delete" => "remove", "rm" => "remove"
80
+
81
+ default_task :list
82
+ end
83
+ end
@@ -1,3 +1,3 @@
1
- module CivoCli
2
- VERSION = "0.1.0"
1
+ module CivoCLI
2
+ VERSION = "0.1.1"
3
3
  end