Class: KnifeCloudstack::CsStackDelete

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/cs_stack_delete.rb

Instance Method Summary collapse

Instance Method Details

#delete_server(server_name) ⇒ Object



80
81
82
83
84
# File 'lib/chef/knife/cs_stack_delete.rb', line 80

def delete_server(server_name)
  cmd = KnifeCloudstack::CsServerDelete.new([server_name])
  cmd.config[:yes] = true
  cmd.run_with_pretty_exceptions
end

#delete_stack(stack) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/chef/knife/cs_stack_delete.rb', line 64

def delete_stack(stack)
  current_stack = Mash.new(stack)
  current_stack[:servers].each do |server|
    if server[:name]

      # delete server(s)
      names = server[:name].split(/[\s,]+/)
      names.each do |name|
        delete_server(name)
      end

    end

  end
end

#runObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/chef/knife/cs_stack_delete.rb', line 51

def run
  file_path = File.expand_path(@name_args.first)
  unless File.exist?(file_path) then
    ui.error "Stack file '#{file_path}' not found. Please check the path."
    exit 1
  end

  data = File.read file_path
  stack = Chef::JSONCompat.from_json data
  delete_stack stack

end