class Chef::Knife::OpennebulaServerDelete

Public Instance Methods

destroy_item(klass, name, type_name) click to toggle source
# File lib/chef/knife/opennebula_server_delete.rb, line 49
def destroy_item(klass, name, type_name)
  begin
    object = klass.load(name)
    object.destroy
    ui.warn("Deleted #{type_name} #{name}")
  rescue Net::HTTPServerException
    ui.warn("Could not find a #{type_name} named #{name} to delete!")
  end
end
h() click to toggle source
# File lib/chef/knife/opennebula_server_delete.rb, line 59
def h
  @highline ||= HighLine.new
end
run() click to toggle source
# File lib/chef/knife/opennebula_server_delete.rb, line 64
def run

  validate!

  @name_args.each do |instance_id|
    begin

  #Fetch instance_id by name of the server =====> MEGAM SYSTEMS CODE START
  connection.servers.all.each do |ser|
          if ser.name.to_s == "#{instance_id}"
                  instance_id = ser.id
          end
  end
  #=====> MEGAM SYSTEMS CODE END

      server = connection.servers.get(instance_id)

      msg_pair("VM ID", server.id)
      msg_pair("VM Name", server.name)
      msg_pair("IP Address", server.ip)

      puts "\n"
      confirm("Do you really want to delete this server")

      server.destroy

      ui.warn("Deleted server #{server.id}")

      if config[:purge]
        thing_to_delete = config[:chef_node_name] || instance_id
        destroy_item(Chef::Node, thing_to_delete, "node")
        destroy_item(Chef::ApiClient, thing_to_delete, "client")
      else
        ui.warn("Corresponding node and client for the #{instance_id} server were not deleted and remain registered with the Chef Server")
      end

    rescue NoMethodError
      ui.error("Could not locate server '#{instance_id}'.")
    end
  end
end