Sha256: 55215c75ec4d2e6673168887755ba8da078acf99c5e48b6fcb87bb0a7c03ee21

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

require_relative 'ionoscloud_base'

class Chef
  class Knife
    class IonoscloudServerResume < Knife
      include Knife::IonoscloudBase

      banner 'knife ionoscloud server resume SERVER_ID [SERVER_ID] (options)'

      option :datacenter_id,
              short: '-D DATACENTER_ID',
              long: '--datacenter-id DATACENTER_ID',
              description: 'ID of the data center'

      attr_reader :description, :required_options

      def initialize(args = [])
        super(args)
        @description =
        'This will resume a suspended server. The operation can only be applied to suspended Cube servers. No billing event will be generated.'
        @required_options = [:datacenter_id, :ionoscloud_username, :ionoscloud_password]
      end

      def run
        $stdout.sync = true
        handle_extra_config
        validate_required_params(@required_options, config)

        server_api = Ionoscloud::ServersApi.new(api_client)

        @name_args.each do |server_id|
          begin
            _, _, headers = server_api.datacenters_servers_resume_post_with_http_info(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
          ui.info("Server #{server_id} is resuming. Request ID: #{get_request_id headers}")
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
knife-ionoscloud-6.0.0 lib/chef/knife/ionoscloud_server_resume.rb
knife-ionoscloud-6.0.0.beta.2 lib/chef/knife/ionoscloud_server_resume.rb
knife-ionoscloud-6.0.0.beta.1 lib/chef/knife/ionoscloud_server_resume.rb