class Chef::Knife::IonoscloudSnapshotCreate

Attributes

description[R]
required_options[R]

Public Class Methods

new(args = []) click to toggle source
Calls superclass method
# File lib/chef/knife/ionoscloud_snapshot_create.rb, line 40
def initialize(args = [])
  super(args)
  @description =
  'Creates a snapshot of a volume within the virtual data center. '\
  'You can use a snapshot to create a new storage volume or to restore a storage volume.'
  @required_options = [:datacenter_id, :volume_id, :ionoscloud_username, :ionoscloud_password]
end

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/ionoscloud_snapshot_create.rb, line 48
def run
  $stdout.sync = true
  handle_extra_config
  validate_required_params(@required_options, config)

  print "#{ui.color('Creating Snapshot...', :magenta)}"

  volume_api = Ionoscloud::VolumeApi.new(api_client)

  snapshot, _, headers  = volume_api.datacenters_volumes_create_snapshot_post_with_http_info(
    config[:datacenter_id],
    config[:volume_id],
    {
      name: config[:name],
      description: config[:description],
      sec_auth_protection: config[:sec_auth_protection],
      licence_type: config[:licence_type],
    }.compact,
  )

  dot = ui.color('.', :magenta)
  api_client.wait_for { print dot; is_done? get_request_id headers }

  snapshot = Ionoscloud::SnapshotApi.new(api_client).snapshots_find_by_id(snapshot.id)

  puts "\n"
  puts "#{ui.color('ID', :cyan)}: #{snapshot.id}"
  puts "#{ui.color('Name', :cyan)}: #{snapshot.properties.name}"
  puts "#{ui.color('Description', :cyan)}: #{snapshot.properties.description}"
  puts "#{ui.color('Location', :cyan)}: #{snapshot.properties.location}"
  puts "#{ui.color('Size', :cyan)}: #{snapshot.properties.size.to_s}"
  puts 'done'
end