Class: CivoCLI::Blueprint

Inherits:
Thor
  • Object
show all
Defined in:
lib/blueprint.rb

Instance Method Summary collapse

Instance Method Details

#createObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/blueprint.rb', line 82

def create
  CivoCLI::Config.set_api_auth
  params = {}
  params[:dsl_content] = File.read(options["content-file"]) unless options["content-file"].nil?
  params[:template_id] = options["template-id"] unless options["template-id"].nil?
  params[:name] = options["name"] unless options["name"].nil?
  result = Civo::Blueprint.create(params)
  blueprint = Civo::Blueprint.all.detect {|b| b.id == result.id }
  puts "Created blueprint #{blueprint.name.colorize(:green)} with ID #{blueprint.id.colorize(:green)}"
rescue Flexirest::HTTPForbiddenClientException => e
  puts "Sorry, you don't have access to this feature".colorize(:red)
  exit 1
rescue Flexirest::HTTPException => e
  puts e.result.reason.colorize(:red)
  exit 1
end

#listObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/blueprint.rb', line 4

def list
  CivoCLI::Config.set_api_auth
  rows = []
  Civo::Blueprint.all.items.each do |blueprint|
    rows << [blueprint.id, blueprint.name, blueprint.template_id, blueprint.version, blueprint.last_build_ended_at]
  end
  puts Terminal::Table.new headings: ['ID', 'Name', 'Template ID', 'Version', "Last built"], rows: rows
rescue Flexirest::HTTPForbiddenClientException => e
  puts "Sorry, you don't have access to this feature".colorize(:red)
  exit 1
rescue Flexirest::HTTPException => e
  puts e.result.reason.colorize(:red)
  exit 1
end

#remove(id) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'lib/blueprint.rb', line 101

def remove(id)
  CivoCLI::Config.set_api_auth
  Civo::Blueprint.remove(detect_blueprint(id))
rescue Flexirest::HTTPForbiddenClientException => e
  puts "Sorry, you don't have access to this feature".colorize(:red)
  exit 1
rescue Flexirest::HTTPException => e
  puts e.result.reason.colorize(:red)
  exit 1
end

#show(id) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/blueprint.rb', line 22

def show(id)
  CivoCLI::Config.set_api_auth
  blueprint = detect_blueprint(id)
  puts "                ID : #{blueprint.id}"
  puts "              Name : #{blueprint.name}"
  puts "       Template ID : #{blueprint.template_id}"
  puts "           Version : #{blueprint.version}"
  puts "Last Build Started : #{blueprint.last_build_started_at&.strftime("%-d %B %Y, %H:%M:%S")}"
  puts "  Last Build Ended : #{blueprint.last_build_ended_at&.strftime("%-d %B %Y, %H:%M:%S")}"
  puts ""
  puts "-" * 29 + " CONTENT " + "-" * 29
  puts ""
  puts blueprint.dsl_content

  unless options["verbose"].nil?
    puts ""
    puts "-" * 29 + " SCRIPT " + "-" * 29
    puts ""
    puts blueprint.script_content
    puts ""
    puts "-" * 29 + " LAST RAN " + "-" * 29
    puts ""
    puts blueprint.last_build_script_output
  end
rescue Flexirest::HTTPForbiddenClientException => e
  puts "Sorry, you don't have access to this feature".colorize(:red)
  exit 1
rescue Flexirest::HTTPException => e
  puts e.result.reason.colorize(:red)
  exit 1
end

#update(id) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/blueprint.rb', line 60

def update(id)
  CivoCLI::Config.set_api_auth
  params = {id: detect_blueprint(id).id}
  params[:dsl_content] = File.read(options["content-file"]) unless options["content-file"].nil?
  params[:template_id] = options["template-id"] unless options["template-id"].nil?
  params[:name] = options["name"] unless options["name"].nil?
  params[:force_rebuild] = 1 unless options["force"].nil?
  Civo::Blueprint.update(params)
  blueprint = detect_blueprint(id)
  puts "Updated blueprint #{blueprint.name.colorize(:green)}"
rescue Flexirest::HTTPForbiddenClientException => e
  puts "Sorry, you don't have access to this feature".colorize(:red)
  exit 1
rescue Flexirest::HTTPException => e
  puts e.result.reason.colorize(:red)
  exit 1
end