class Chef::Knife::IonoscloudServerDelete
Attributes
description[R]
required_options[R]
Public Class Methods
new(args = [])
click to toggle source
Calls superclass method
# File lib/chef/knife/ionoscloud_server_delete.rb, line 17 def initialize(args = []) super(args) @description = "This will remove a server from a VDC.\n\n"\ "**NOTE**: This will not automatically remove the storage volume\\(s\\) "\ "attached to a server. A separate API call is required to perform that action." @required_options = [:datacenter_id, :ionoscloud_username, :ionoscloud_password] end
Public Instance Methods
run()
click to toggle source
# File lib/chef/knife/ionoscloud_server_delete.rb, line 26 def run $stdout.sync = true handle_extra_config validate_required_params(@required_options, config) server_api = Ionoscloud::ServerApi.new(api_client) @name_args.each do |server_id| begin server = server_api.datacenters_servers_find_by_id(config[:datacenter_id], server_id) rescue Ionoscloud::ApiError => err raise err unless err.code == 404 ui.error("Server ID #{server_id} not found. Skipping.") next end msg_pair('ID', server.id) msg_pair('Name', server.properties.name) msg_pair('Cores', server.properties.cores) msg_pair('CPU Family', server.properties.cpu_family) msg_pair('Ram', server.properties.ram) msg_pair('Availability Zone', server.properties.availability_zone) msg_pair('Boot Volume', (server.properties.boot_volume.nil? ? '' : server.properties.boot_volume.id)) msg_pair('Boot CDROM', (server.properties.boot_cdrom.nil? ? '' : server.properties.boot_cdrom.id)) begin confirm('Do you really want to delete this server') rescue SystemExit => exc next end _, _, headers = server_api.datacenters_servers_delete_with_http_info(config[:datacenter_id], server_id) ui.warn("Deleted Server #{server.id}. Request ID: #{get_request_id headers}") end end