Class: CivoCLI::Template
- Inherits:
-
Thor
- Object
- Thor
- CivoCLI::Template
- Defined in:
- lib/template.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/template.rb', line 82 def create CivoCLI::Config.set_api_auth params = {} params[:cloud_config] = File.read(["cloud-init-file"]) unless ["cloud-init-file"].nil? params[:image_id] = ["image-id"] unless ["image-id"].nil? params[:volume_id] = ["volume-id"] unless ["volume-id"].nil? params[:description] = ["description"] unless ["description"].nil? params[:name] = ["name"] unless ["name"].nil? params[:short_description] = ["short-description"] unless ["short-description"].nil? template = Civo::Template.create(params) puts "Created template #{template.name.colorize(:green)} with ID #{template.id.colorize(:green)}" rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |
#list ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/template.rb', line 5 def list CivoCLI::Config.set_api_auth rows = [] if [:verbose] Civo::Template.all.items.each do |template| rows << [template.id, template.name, template.image_id, template.volume_id, template.default_username] end puts Terminal::Table.new headings: ['ID', 'Name', 'Image ID', 'Volume ID', "Default Username"], rows: rows else Civo::Template.all.items.each do |template| rows << [template.id, template.name] end puts Terminal::Table.new headings: ['ID', 'Name'], rows: rows end rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |
#remove(id) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/template.rb', line 100 def remove(id) CivoCLI::Config.set_api_auth Civo::Template.remove(id) rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |
#show(id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/template.rb', line 30 def show(id) CivoCLI::Config.set_api_auth template = Civo::Template.details(id) puts " ID: #{template.id}" puts " Code: #{template.code}" puts " Name: #{template.name}" puts " Image ID: #{template.image_id}" puts " Volume ID: #{template.volume_id}" puts "Short Description: #{template.short_description}" puts " Description: #{template.description}" puts " Default Username: #{template.default_username}" puts "" puts "-" * 29 + "CLOUD CONFIG" + "-" * 29 puts template.cloud_config rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |
#update(id) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/template.rb', line 58 def update(id) CivoCLI::Config.set_api_auth params = {id: id} params[:cloud_config] = File.read(["cloud-init-file"]) unless ["cloud-init-file"].nil? params[:image_id] = ["image-id"] unless ["image-id"].nil? params[:volume_id] = ["volume-id"] unless ["volume-id"].nil? params[:description] = ["description"] unless ["description"].nil? params[:name] = ["name"] unless ["name"].nil? params[:short_description] = ["short-description"] unless ["short-description"].nil? Civo::Template.save(params) template = Civo::Template.details(id) puts "Updated template #{template.name.colorize(:green)}" rescue Flexirest::HTTPException => e puts e.result.reason.colorize(:red) exit 1 end |