Class: Knifecosmic::CosmicStackDelete

Inherits:
Chef::Knife show all
Includes:
Chef::Knife::KnifecosmicBase
Defined in:
lib/chef/knife/cosmic_stack_delete.rb

Instance Method Summary collapse

Methods included from Chef::Knife::KnifecosmicBase

included

Instance Method Details

#delete_server(server_name) ⇒ Object



70
71
72
73
74
75
# File 'lib/chef/knife/cosmic_stack_delete.rb', line 70

def delete_server(server_name)
  cmd = Knifecosmic::CosmicServerDelete.new([server_name])
  cmd.config[:yes] = true
  cmd.config[:expunge] = true
  cmd.run_with_pretty_exceptions
end

#delete_stack(stack) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chef/knife/cosmic_stack_delete.rb', line 54

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chef/knife/cosmic_stack_delete.rb', line 37

def run
  if @name_args.first.nil?
    ui.error "Please specify json file eg: knife cosmic stack delete JSON_FILE"
    exit 1
  end
  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