class Chef::Knife::IonoscloudServerCreate

Attributes

description[R]
required_options[R]

Public Class Methods

new(args = []) click to toggle source
Calls superclass method
# File lib/chef/knife/ionoscloud_server_create.rb, line 52
def initialize(args = [])
  super(args)
  @description =
  "One of the unique features of the Ionoscloud platform when compared "\
  "with the other providers is that they allow you to define your own settings "\
  "for cores, memory, and disk size without being tied to a particular size or flavor.\n\n"\
  "Note: _The memory parameter value must be a multiple of 256, e.g. 256, 512, 768, 1024, and so forth._"
  @required_options = [:datacenter_id, :cores, :ram, :ionoscloud_username, :ionoscloud_password]
end

Public Instance Methods

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

  print "#{ui.color('Creating server...', :magenta)}"
  params = {
    name: config[:name],
    cores: config[:cores],
    cpuFamily: config[:cpu_family],
    ram: config[:ram],
    availabilityZone: config[:availability_zone]
  }

  params[:bootCdrom] = { id: config[:boot_cdrom] } unless config[:boot_cdrom].nil?
  params[:bootVolume] = { id: config[:boot_volume] } unless config[:boot_volume].nil?

  server_api = Ionoscloud::ServerApi.new(api_client)

  server, _, headers = server_api.datacenters_servers_post_with_http_info(
    config[:datacenter_id],
    { properties: params.compact },
  )

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

  server = server_api.datacenters_servers_find_by_id(config[:datacenter_id], server.id)

  puts "\n"
  puts "#{ui.color('ID', :cyan)}: #{server.id}"
  puts "#{ui.color('Name', :cyan)}: #{server.properties.name}"
  puts "#{ui.color('Cores', :cyan)}: #{server.properties.cores}"
  puts "#{ui.color('CPU Family', :cyan)}: #{server.properties.cpu_family}"
  puts "#{ui.color('Ram', :cyan)}: #{server.properties.ram}"
  puts "#{ui.color('Availability Zone', :cyan)}: #{server.properties.availability_zone}"
  puts "#{ui.color('Boot Volume', :cyan)}: #{server.properties.boot_volume ? server.properties.boot_volume.id : ''}"
  puts "#{ui.color('Boot CDROM', :cyan)}: #{server.properties.boot_cdrom ? server.properties.boot_cdrom.id : ''}"

  puts 'done'
end