Class: SSC::Handler::Appliance

Inherits:
Base
  • Object
show all
Defined in:
lib/handlers/appliance.rb

Constant Summary

Constants inherited from Base

Base::API_URL

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Helper

included

Constructor Details

This class inherits a constructor from SSC::Handler::Base

Instance Method Details

#create(appliance_name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/handlers/appliance.rb', line 9

def create(appliance_name)
  appliance_dir= File.join('.', appliance_name) 
  params= {:name => appliance_name}
  params.merge!(:arch => options.arch) if options.arch
  appliance= StudioApi::Appliance.clone(options.source_id, params)
  appliance_params= {
    :username => options.username,
    :password => options.password,
    :appliance_id => appliance.id }
  appliance_dir= ApplianceDirectory.new(appliance_name, appliance_params)
  appliance_dir.create
  say_array(["Created: ", appliance_dir.path] + appliance_dir.files.values)
  say "" # make sure terminal output starts on a new line
end

#destroyObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/handlers/appliance.rb', line 42

def destroy
  require_appliance do |appliance|
    if appliance.destroy.code_type == Net::HTTPOK
      say 'Appliance Successfully Destroyed', :red
    else
      say_array ['There was a problem with destroying the appliance.',
                 'Make sure that you\'re in the appliance directory OR',
                 'Have provided the --appliance_id option']
    end
  end
end

#infoObject



33
34
35
36
37
38
# File 'lib/handlers/appliance.rb', line 33

def info
  appliance= StudioApi::Appliance.find(options.appliance_id)
  say_array ["#{appliance.id}: #{appliance.name}",
   "Parent: ( #{appliance.parent.id} ) #{appliance.parent.name}",
   "Download Url: #{download_url(appliance)}"]
end

#listObject



26
27
28
29
# File 'lib/handlers/appliance.rb', line 26

def list
  appliances= StudioApi::Appliance.find(:all)
  print_table([["id", "name"]]+appliances.collect{|i| [i.id, i.name]})
end

#statusObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/handlers/appliance.rb', line 56

def status
  require_appliance do |appliance|
    response= appliance.status
    case response.state
    when 'error'
      say "Error: #{response.issues.issue.text}"
    when 'ok'
      say "Appliance Ok"
    end
  end
end