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.
data/lib/civo_cli.rb CHANGED
@@ -1,6 +1,67 @@
1
1
  require "civo_cli/version"
2
2
 
3
- module CivoCli
3
+ require "civo"
4
+ require "json"
5
+ require "thor"
6
+ require "terminal-table"
7
+ require 'colorize'
8
+ Dir[File.join(__dir__, '*.rb')].each { |file| require file }
9
+
10
+ module CivoCLI
4
11
  class Error < StandardError; end
5
- # Your code goes here...
12
+
13
+ class Main < Thor
14
+ desc "apikey", "manage API keys stored in the client"
15
+ subcommand "apikey", CivoCLI::APIKey
16
+ map "apikeys" => "apikey"
17
+
18
+ desc "blueprint", "manage blueprints"
19
+ subcommand "blueprint", CivoCLI::Blueprint
20
+ map "blueprints" => "blueprint"
21
+
22
+ desc "domain", "manage DNS domains"
23
+ subcommand "domain", CivoCLI::Domain
24
+ map "domains" => "domain"
25
+
26
+ desc "firewall", "manage firewalls"
27
+ subcommand "firewall", CivoCLI::Firewall
28
+ map "firewalls" => "firewall"
29
+
30
+ desc "instance", "manage instances"
31
+ subcommand "instance", CivoCLI::Instance
32
+ map "instances" => "instance"
33
+
34
+ desc "network", "manage networks"
35
+ subcommand "network", CivoCLI::Network
36
+ map "networks" => "network"
37
+
38
+ desc "quota", "view the quota"
39
+ subcommand "quota", CivoCLI::Quota
40
+ map "quotas" => "quota"
41
+
42
+ desc "region", "manage regions"
43
+ subcommand "region", CivoCLI::Region
44
+ map "regions" => "region"
45
+
46
+ desc "size", "manage sizes"
47
+ subcommand "size", CivoCLI::Size
48
+ map "sizes" => "size"
49
+
50
+ desc "snapshot", "manage snapshots"
51
+ subcommand "snapshot", CivoCLI::Snapshot
52
+ map "snapshots" => "snapshot"
53
+
54
+ desc "sshkey", "manage uploaded SSH keys"
55
+ subcommand "sshkey", CivoCLI::SSHKey
56
+ map "sshkeys" => "sshkey"
57
+
58
+ desc "template", "manage templates"
59
+ subcommand "template", CivoCLI::Template
60
+ map "templates" => "template"
61
+
62
+ desc "volume", "manage volumes"
63
+ subcommand "volume", CivoCLI::Volume
64
+ map "volumes" => "volume"
65
+
66
+ end
6
67
  end
data/lib/config.rb ADDED
@@ -0,0 +1,74 @@
1
+ module CivoCLI
2
+ class Config
3
+ def self.get_apikeys
4
+ current["apikeys"]
5
+ end
6
+
7
+ def self.get_apikey(key)
8
+ current["apikeys"][key]
9
+ end
10
+
11
+ def self.get_current_apikey
12
+ current["apikeys"][get_current_apikey_name]
13
+ end
14
+
15
+ def self.get_current_apikey_name
16
+ get_meta(:current_apikey)
17
+ end
18
+
19
+ def self.set_current_apikey_name(name)
20
+ set_meta(:current_apikey, name)
21
+ end
22
+
23
+ def self.set_apikey(key, value)
24
+ current["apikeys"][key] = value
25
+ save
26
+ end
27
+
28
+ def self.delete_apikey(key)
29
+ current["apikeys"].delete(key)
30
+ if get_current_apikey_name == key
31
+ if get_apikeys.any?
32
+ set_current_apikey_name(get_apikeys.keys.first)
33
+ else
34
+ set_current_apikey_name(nil)
35
+ end
36
+ end
37
+ end
38
+
39
+ def self.get_meta(key)
40
+ current["meta"].transform_keys{ |key| key.to_sym rescue key }[key]
41
+ end
42
+
43
+ def self.set_meta(key, value)
44
+ current["meta"][key.to_s] = value
45
+ save
46
+ end
47
+
48
+ def self.current
49
+ @config ||= JSON.parse(File.read(filename))
50
+ end
51
+
52
+ def self.reset
53
+ @config = nil
54
+ end
55
+
56
+ def self.save
57
+ File.write(filename, @config.to_json)
58
+ end
59
+
60
+ def self.filename
61
+ "#{ENV['HOME']}/.civo.json"
62
+ end
63
+
64
+ def self.set_api_auth
65
+ ENV["CIVO_API_VERSION"] = "2"
66
+ ENV["CIVO_TOKEN"] = CivoCLI::Config.get_current_apikey
67
+ if ENV["CIVO_TOKEN"].nil? || ENV["CIVO_TOKEN"] == ""
68
+ puts "#{"Unable to connect:".colorize(:red)} No valid API key is set"
69
+ exit 1
70
+ end
71
+ ENV["CIVO_URL"] = CivoCLI::Config.get_meta(:url) || "https://api.civo.com"
72
+ end
73
+ end
74
+ end
data/lib/domain.rb ADDED
@@ -0,0 +1,5 @@
1
+ module CivoCLI
2
+ class Domain < Thor
3
+
4
+ end
5
+ end
data/lib/firewall.rb ADDED
@@ -0,0 +1,5 @@
1
+ module CivoCLI
2
+ class Firewall < Thor
3
+
4
+ end
5
+ end
data/lib/instance.rb ADDED
@@ -0,0 +1,115 @@
1
+ module CivoCLI
2
+ class Instance < Thor
3
+ desc "list", "list all instances"
4
+ def list
5
+ CivoCLI::Config.set_api_auth
6
+ rows = []
7
+ sizes = Civo::Size.all.items
8
+ Civo::Instance.all.items.each do |instance|
9
+ size_name = sizes.detect {|s| s.name == instance.size}&.nice_name
10
+ rows << [instance.id, instance.hostname, size_name, instance.region, instance.public_ip, instance.status]
11
+ end
12
+ puts Terminal::Table.new headings: ['ID', 'Hostname', 'Size', 'Region', 'Public IP', 'Status'], rows: rows
13
+ end
14
+
15
+ if CivoCLI::Config.get_meta("admin")
16
+ desc "", ""
17
+ def high_cpu
18
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/high_cpu"
19
+ end
20
+ end
21
+
22
+ desc "", ""
23
+ def find
24
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id", requires: [:id]
25
+ end
26
+
27
+ desc "", ""
28
+ def create
29
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances", requires: [:hostname, :size, :region],
30
+ # defaults: {public_ip: true, initial_user: "civo"}
31
+ end
32
+
33
+ desc "", ""
34
+ def tags
35
+
36
+ end
37
+
38
+ desc "", ""
39
+ def update
40
+
41
+ end
42
+
43
+ desc "", ""
44
+ def remove
45
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id", requires: [:id], send_delete_body: true
46
+ end
47
+
48
+ desc "", ""
49
+ def reboot
50
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/reboots", requires: [:id]
51
+ end
52
+
53
+ desc "", ""
54
+ def hard_reboot
55
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/hard_reboots", requires: [:id]
56
+ end
57
+
58
+ desc "", ""
59
+ def soft_reboot
60
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/soft_reboots", requires: [:id]
61
+ end
62
+
63
+ desc "", ""
64
+ def console
65
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/console", requires: [:id]
66
+ end
67
+
68
+ desc "", ""
69
+ def rebuild
70
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/rebuild", requires: [:id]
71
+ end
72
+
73
+ desc "", ""
74
+ def stop
75
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/stop", requires: [:id]
76
+ end
77
+
78
+ desc "", ""
79
+ def start
80
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/start", requires: [:id]
81
+ end
82
+
83
+ desc "", ""
84
+ def upgrade
85
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/resize", requires: [:size, :id]
86
+ end
87
+
88
+ desc "", ""
89
+ def restore
90
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/restore", requires: [:snapshot, :id]
91
+ end
92
+
93
+ desc "", ""
94
+ def move_ip
95
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/ip/:ip", requires: [:ip, :id]
96
+ end
97
+
98
+ desc "", ""
99
+ def rescue
100
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/rescue", requires: [:id]
101
+ end
102
+
103
+ desc "", ""
104
+ def unrescue
105
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/unrescue", requires: [:id]
106
+ end
107
+
108
+ desc "", ""
109
+ def firewall
110
+ # {ENV["CIVO_API_VERSION"] || "1"}/instances/:id/firewall", requires: [:firewall_id, :id]
111
+ end
112
+
113
+ default_task :list
114
+ end
115
+ end
data/lib/network.rb ADDED
@@ -0,0 +1,43 @@
1
+ module CivoCLI
2
+ class Network < Thor
3
+ desc "list", "list all networks"
4
+ def list
5
+ CivoCLI::Config.set_api_auth
6
+ rows = []
7
+ Civo::Network.all.items.each do |network|
8
+ if network.default
9
+ rows << [network.id, network.label, network.cidr, "<====="]
10
+ else
11
+ rows << [network.id, network.label, network.cidr, ""]
12
+ end
13
+ end
14
+ puts Terminal::Table.new headings: ['ID', 'Label', 'CIDR', 'Default?'], rows: rows
15
+ end
16
+
17
+ desc "create LABEL", "create a new private network called LABEL"
18
+ def create(label)
19
+ CivoCLI::Config.set_api_auth
20
+ network = Civo::Network.create(label: label)
21
+ puts "Create a private network called #{label.colorize(:green)} with ID #{network.id.colorize(:green)}"
22
+ rescue Flexirest::HTTPException => e
23
+ puts e.result.reason.colorize(:red)
24
+ exit 1
25
+ end
26
+ map "new" => "create"
27
+
28
+ desc "remove ID", "remove the network ID"
29
+ def remove(id)
30
+ CivoCLI::Config.set_api_auth
31
+ network = Civo::Network.all.items.detect {|key| key.id == id}
32
+ Civo::Network.remove(id: id)
33
+ puts "Removed the network #{network.label.colorize(:green)} with ID #{network.id.colorize(:green)}"
34
+ rescue Flexirest::HTTPException => e
35
+ puts e.result.reason.colorize(:red)
36
+ exit 1
37
+ end
38
+ map "delete" => "remove", "rm" => "remove"
39
+
40
+ default_task :list
41
+
42
+ end
43
+ end
data/lib/quota.rb ADDED
@@ -0,0 +1,69 @@
1
+ module CivoCLI
2
+ class Quota < Thor
3
+ desc "show", "show the current quota and usage"
4
+ def show
5
+ CivoCLI::Config.set_api_auth
6
+ rows = []
7
+ quota = Civo::Quota.current
8
+ if quota.instance_count_usage >= (quota.instance_count_limit * 0.8)
9
+ rows << ["Instances", quota.instance_count_usage.to_s.colorize(:red), quota.instance_count_limit]
10
+ else
11
+ rows << ["Instances", quota.instance_count_usage, quota.instance_count_limit]
12
+ end
13
+ if quota.cpu_core_usage >= (quota.cpu_core_limit * 0.8)
14
+ rows << ["CPU cores", quota.cpu_core_usage.to_s.colorize(:red), quota.cpu_core_limit]
15
+ else
16
+ rows << ["CPU cores", quota.cpu_core_usage, quota.cpu_core_limit]
17
+ end
18
+ if quota.ram_mb_usage >= (quota.ram_mb_limit * 0.8)
19
+ rows << ["RAM MB", quota.ram_mb_usage.to_s.colorize(:red), quota.ram_mb_limit]
20
+ else
21
+ rows << ["RAM MB", quota.ram_mb_usage, quota.ram_mb_limit]
22
+ end
23
+ if quota.disk_gb_usage >= (quota.disk_gb_limit * 0.8)
24
+ rows << ["Disk GB", quota.disk_gb_usage.to_s.colorize(:red), quota.disk_gb_limit]
25
+ else
26
+ rows << ["Disk GB", quota.disk_gb_usage, quota.disk_gb_limit]
27
+ end
28
+ if quota.disk_volume_count_usage >= (quota.disk_volume_count_limit * 0.8)
29
+ rows << ["Volumes", quota.disk_volume_count_usage.to_s.colorize(:red), quota.disk_volume_count_limit]
30
+ else
31
+ rows << ["Volumes", quota.disk_volume_count_usage, quota.disk_volume_count_limit]
32
+ end
33
+ if quota.disk_snapshot_count_usage >= (quota.disk_snapshot_count_limit * 0.8)
34
+ rows << ["Snapshots", quota.disk_snapshot_count_usage.to_s.colorize(:red), quota.disk_snapshot_count_limit]
35
+ else
36
+ rows << ["Snapshots", quota.disk_snapshot_count_usage, quota.disk_snapshot_count_limit]
37
+ end
38
+ if quota.public_ip_address_usage >= (quota.public_ip_address_limit * 0.8)
39
+ rows << ["Public IPs", quota.public_ip_address_usage.to_s.colorize(:red), quota.public_ip_address_limit]
40
+ else
41
+ rows << ["Public IPs", quota.public_ip_address_usage, quota.public_ip_address_limit]
42
+ end
43
+ if quota.subnet_count_usage >= (quota.subnet_count_limit * 0.8)
44
+ rows << ["Subnets", quota.subnet_count_usage.to_s.colorize(:red), quota.subnet_count_limit]
45
+ else
46
+ rows << ["Subnets", quota.subnet_count_usage, quota.subnet_count_limit]
47
+ end
48
+ if quota.network_count_usage >= (quota.network_count_limit * 0.8)
49
+ rows << ["Private networks", quota.network_count_usage.to_s.colorize(:red), quota.network_count_limit]
50
+ else
51
+ rows << ["Private networks", quota.network_count_usage, quota.network_count_limit]
52
+ end
53
+ if quota.security_group_usage >= (quota.security_group_limit * 0.8)
54
+ rows << ["Firewalls", quota.security_group_usage.to_s.colorize(:red), quota.security_group_limit]
55
+ else
56
+ rows << ["Firewalls", quota.security_group_usage, quota.security_group_limit]
57
+ end
58
+ if quota.security_group_rule_usage >= (quota.security_group_rule_limit * 0.8)
59
+ rows << ["Firewall rules", quota.security_group_rule_usage.to_s.colorize(:red), quota.security_group_rule_limit]
60
+ else
61
+ rows << ["Firewall rules", quota.security_group_rule_usage, quota.security_group_rule_limit]
62
+ end
63
+ puts Terminal::Table.new headings: ["Item", "Usage", "Limit"], rows: rows
64
+ puts "Any items in #{"red".to_s.colorize(:red)} are at least 80% of your limit"
65
+ end
66
+
67
+ default_task :show
68
+ end
69
+ end
data/lib/region.rb ADDED
@@ -0,0 +1,15 @@
1
+ module CivoCLI
2
+ class Region < Thor
3
+ desc "list", "List all regions available for selection"
4
+ def list
5
+ CivoCLI::Config.set_api_auth
6
+ rows = []
7
+ Civo::Region.all.items.each do |region|
8
+ rows << [region.code]
9
+ end
10
+ puts Terminal::Table.new headings: ['Code'], rows: rows
11
+ end
12
+
13
+ default_task :list
14
+ end
15
+ end
data/lib/size.rb ADDED
@@ -0,0 +1,16 @@
1
+ module CivoCLI
2
+ class Size < Thor
3
+ desc "list", "List all sizes available for selection"
4
+ def list
5
+ CivoCLI::Config.set_api_auth
6
+ rows = []
7
+ Civo::Size.all.items.select{|s| s.selectable }.each do |size|
8
+ rows << [size.name, size.description, size.cpu_cores, size.ram_mb, size.disk_gb]
9
+ end
10
+ puts Terminal::Table.new headings: ['Name', 'Description', 'CPU', 'RAM (MB)', 'Disk (GB)'], rows: rows
11
+ end
12
+
13
+ default_task :list
14
+
15
+ end
16
+ end
data/lib/snapshot.rb ADDED
@@ -0,0 +1,43 @@
1
+ module CivoCLI
2
+ class Snapshot < Thor
3
+ desc "list", "list all snapshots"
4
+ def list
5
+ CivoCLI::Config.set_api_auth
6
+ rows = []
7
+ Civo::Snapshot.all.items.each do |snapshot|
8
+ rows << [snapshot.id, snapshot.name, snapshot.state, snapshot.size_gb, (snapshot.cron_timing || "One-off")]
9
+ end
10
+ puts Terminal::Table.new headings: ['ID', 'Name', 'State', "Size (GB)", "Cron"], rows: rows
11
+ end
12
+
13
+ option "cron", type: :string, desc: "The timing of when to take/repeat in cron format", aliases: ["-c"], banner: "CRON_TIMING"
14
+ desc "create NAME INSTANCE_ID [-c '0 * * * *']", "create a snapshot called NAME from instance INSTANCE_ID"
15
+ def create(name, instance_id)
16
+ CivoCLI::Config.set_api_auth
17
+ puts options.inspect
18
+ params = {name: name, instance_id: instance_id}
19
+ params[:cron_timing] = options["cron"] unless options["cron"].nil?
20
+ snapshot = Civo::Snapshot.create(params)
21
+ puts "Created snapshot #{name.colorize(:green)} with ID #{snapshot.id.colorize(:green)} #{"with cron timing #{options["cron"].colorize(:green)}" unless options["cron"].nil?}"
22
+ rescue Flexirest::HTTPException => e
23
+ puts e.result.reason.colorize(:red)
24
+ exit 1
25
+ end
26
+ map "new" => "create"
27
+
28
+ desc "remove ID", "remove the snapshot ID"
29
+ def remove(id)
30
+ CivoCLI::Config.set_api_auth
31
+ snapshot = Civo::Snapshot.all.items.detect {|key| key.id == id}
32
+ Civo::Snapshot.remove(id: id)
33
+ puts "Removed snapshot #{snapshot.name.colorize(:green)} with ID #{snapshot.id.colorize(:green)}"
34
+ rescue Flexirest::HTTPException => e
35
+ puts e.result.reason.colorize(:red)
36
+ exit 1
37
+ end
38
+ map "delete" => "remove", "rm" => "remove"
39
+
40
+ default_task :list
41
+
42
+ end
43
+ end
data/lib/sshkey.rb ADDED
@@ -0,0 +1,38 @@
1
+ module CivoCLI
2
+ class SSHKey < Thor
3
+ desc "list", "list all SSH keys"
4
+ def list
5
+ CivoCLI::Config.set_api_auth
6
+ rows = []
7
+ Civo::SshKey.all.items.each do |key|
8
+ rows << [key.id, key.name, key.fingerprint]
9
+ end
10
+ puts Terminal::Table.new headings: ['ID', 'Name', 'Fingerprint'], rows: rows
11
+ end
12
+
13
+ desc "upload NAME FILENAME", "upload the SSH public key in FILENAME to a new key called NAME"
14
+ def upload(name, filename)
15
+ CivoCLI::Config.set_api_auth
16
+ ssh_key = Civo::SshKey.create(name: name, public_key: File.read(filename))
17
+ puts "Uploaded SSH key #{name.colorize(:green)} with ID #{ssh_key.id.colorize(:green)}"
18
+ rescue Flexirest::HTTPException => e
19
+ puts e.result.reason.colorize(:red)
20
+ exit 1
21
+ end
22
+ map "create" => "upload", "new" => "upload"
23
+
24
+ desc "remove ID", "remove the SSH public key with ID"
25
+ def remove(id)
26
+ CivoCLI::Config.set_api_auth
27
+ ssh_key = Civo::SshKey.all.items.detect {|key| key.id == id}
28
+ Civo::SshKey.remove(id: id)
29
+ puts "Removed SSH key #{ssh_key.name.colorize(:green)} with ID #{ssh_key.id.colorize(:green)}"
30
+ rescue Flexirest::HTTPException => e
31
+ puts e.result.reason.colorize(:red)
32
+ exit 1
33
+ end
34
+ map "delete" => "remove", "rm" => "remove"
35
+
36
+ default_task :list
37
+ end
38
+ end
data/lib/template.rb ADDED
@@ -0,0 +1,96 @@
1
+ module CivoCLI
2
+ class Template < Thor
3
+ desc "list", "list all templates"
4
+ def list
5
+ CivoCLI::Config.set_api_auth
6
+ rows = []
7
+ Civo::Template.all.items.each do |template|
8
+ rows << [template.id, template.name, template.image_id, template.volume_id, template.default_username]
9
+ end
10
+ puts Terminal::Table.new headings: ['ID', 'Name', 'Image ID', 'Volume ID', "Default Username"], 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 template"
17
+ def show(id)
18
+ CivoCLI::Config.set_api_auth
19
+ template = Civo::Template.details(id)
20
+ puts " ID: #{template.id}"
21
+ puts " Code: #{template.code}"
22
+ puts " Name: #{template.name}"
23
+ puts " Image ID: #{template.image_id}"
24
+ puts " Volume ID: #{template.volume_id}"
25
+ puts "Short Description: #{template.short_description}"
26
+ puts " Description: #{template.description}"
27
+ puts " Default Username: #{template.default_username}"
28
+ puts ""
29
+ puts "-" * 29 + "CLOUD CONFIG" + "-" * 29
30
+ puts template.cloud_config
31
+ rescue Flexirest::HTTPException => e
32
+ puts e.result.reason.colorize(:red)
33
+ exit 1
34
+ end
35
+
36
+ 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"
37
+ option :description, type: :string, desc: "A full/long multiline description", aliases: ["-d"], banner: "DESCRIPTION"
38
+ option "image-id", type: :string, desc: "The glance ID of the base filesystem image", aliases: ["-i"], banner: "IMAGE_ID"
39
+ option "volume-id", type: :string, desc: "The volume ID of the base filesystem volume", aliases: ["-v"], banner: "VOLUME_ID"
40
+ option :name, type: :string, desc: "A nice name to be used for the template", aliases: ["-n"], banner: "NICE_NAME"
41
+ option "short-description", type: :string, desc: "A one line short summary of the template", aliases: ["-s"], banner: "SUMMARY"
42
+ desc "update ID", "update the template with ID"
43
+ def update(id)
44
+ CivoCLI::Config.set_api_auth
45
+ params = {id: id}
46
+ params[:cloud_config] = File.read(options["cloud-init-file"]) unless options["cloud-init-file"].nil?
47
+ params[:image_id] = options["image-id"] unless options["image-id"].nil?
48
+ params[:volume_id] = options["volume-id"] unless options["volume-id"].nil?
49
+ params[:description] = options["description"] unless options["description"].nil?
50
+ params[:name] = options["name"] unless options["name"].nil?
51
+ params[:short_description] = options["short-description"] unless options["short-description"].nil?
52
+ Civo::Template.save(params)
53
+ template = Civo::Template.details(id)
54
+ puts "Updated template #{template.name.colorize(:green)}"
55
+ rescue Flexirest::HTTPException => e
56
+ puts e.result.reason.colorize(:red)
57
+ exit 1
58
+ end
59
+
60
+ 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"
61
+ option :description, type: :string, desc: "A full/long multiline description", aliases: ["-d"], banner: "DESCRIPTION"
62
+ option "image-id", type: :string, desc: "The glance ID of the base filesystem image", aliases: ["-i"], banner: "IMAGE_ID"
63
+ option "volume-id", type: :string, desc: "The volume ID of the base filesystem volume", aliases: ["-v"], banner: "VOLUME_ID"
64
+ option :name, type: :string, desc: "A nice name to be used for the template", aliases: ["-n"], banner: "NICE_NAME"
65
+ option "short-description", type: :string, desc: "A one line short summary of the template", aliases: ["-s"], banner: "SUMMARY"
66
+ desc "create", "create a new template"
67
+ def create
68
+ CivoCLI::Config.set_api_auth
69
+ params = {}
70
+ params[:cloud_config] = File.read(options["cloud-init-file"]) unless options["cloud-init-file"].nil?
71
+ params[:image_id] = options["image-id"] unless options["image-id"].nil?
72
+ params[:volume_id] = options["volume-id"] unless options["volume-id"].nil?
73
+ params[:description] = options["description"] unless options["description"].nil?
74
+ params[:name] = options["name"] unless options["name"].nil?
75
+ params[:short_description] = options["short-description"] unless options["short-description"].nil?
76
+ template = Civo::Template.create(params)
77
+ puts "Created template #{template.name.colorize(:green)} with ID #{template.id.colorize(:green)}"
78
+ rescue Flexirest::HTTPException => e
79
+ puts e.result.reason.colorize(:red)
80
+ exit 1
81
+ end
82
+ map "new" => "create"
83
+
84
+ desc "remove ID", "remove the template with ID"
85
+ def remove(id)
86
+ CivoCLI::Config.set_api_auth
87
+ Civo::Template.remove(id)
88
+ rescue Flexirest::HTTPException => e
89
+ puts e.result.reason.colorize(:red)
90
+ exit 1
91
+ end
92
+ map "delete" => "remove", "rm" => "remove"
93
+
94
+ default_task :list
95
+ end
96
+ end