Class: Tools::Slice

Inherits:
Default show all
Defined in:
lib/slicehost-tools/tools/slice.rb

Instance Method Summary collapse

Methods inherited from Default

#apikey

Instance Method Details

#add(slice_name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/slicehost-tools/tools/slice.rb', line 10

def add(slice_name)
  images  = ::Image.find(:all)
  flavors = ::Flavor.find(:all)
        
  puts "Available Images: "
  image_id = select_image_from(images)
  
  puts "Available Flavors: "
  flavor_id = select_flavor_from(flavors)
  
  @add = false
  # confirm  you want to do this, it does cost money
  unless options[:force]     
    print "Are you sure you want do this? [y/N]: "
    case STDIN.gets.chomp
    when /y/i
      @add = true
    end
  end

  if @add
    slice = ::Slice.new(:name => slice_name, :flavor_id => flavor_id, :image_id => image_id)
    slice.save
  end
  
end

#delete(slice_name = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/slicehost-tools/tools/slice.rb', line 38

def delete(slice_name = nil)                            
  slice_name = select_slice.name if slice_name.nil?
    
  @abort = true
  slice = ::Slice.find_by_name(slice_name)
  puts "Please type 'I understand this is not undoable' to proceed: "
  case STDIN.gets.chomp
  when "I understand this is not undoable"
    @abort = false
  end
  
  unless @abort
    puts "You have 5 seconds to change your mind (CTRL+C)"
    sleep 5
    puts "Say goodnight gracie."
    slice.destroy
    sleep 3
    puts "Goodnight gracie."   
  else
    puts "Your slice has not been nuked. (I hope)"
  end
  
end

#hard_reboot(slice_name = nil) ⇒ Object



81
82
83
84
85
86
# File 'lib/slicehost-tools/tools/slice.rb', line 81

def hard_reboot(slice_name = nil)
  slice_name = select_slice.name if slice_name.nil?
  
  puts "(hard) rebooting #{slice_name}"                      
  reboot(:hard_reboot, slice_name)
end

#listObject



63
64
65
66
67
# File 'lib/slicehost-tools/tools/slice.rb', line 63

def list                            
  ::Slice.find(:all).each do |slice|
    puts "+ #{slice.name} (#{slice.addresses})"
  end
end

#soft_reboot(slice_name = nil) ⇒ Object



89
90
91
92
93
94
# File 'lib/slicehost-tools/tools/slice.rb', line 89

def soft_reboot(slice_name = nil)                       
  slice_name = select_slice.name if slice_name.nil?
  
  puts "(soft) rebooting #{slice_name}"
  reboot(:reboot, slice_name)
end

#status(slice_name = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/slicehost-tools/tools/slice.rb', line 70

def status(slice_name = nil)
  slice_name = select_slice.name if slice_name.nil?
  
  slice = ::Slice.find_by_name(slice_name)
  puts "Name:               #{slice.name} (#{slice.addresses})"
  puts "Flavor:             #{slice.flavor} (#{slice.image})"
  puts "Status:             #{slice.status}"
  puts "Bandwidth (in/out): #{slice.bw_in}/#{slice.bw_out}"
end