Class: Chef::Knife::OneandoneServerModify

Inherits:
Chef::Knife
  • Object
show all
Includes:
OneandoneBase
Defined in:
lib/chef/knife/oneandone_server_modify.rb

Instance Method Summary collapse

Methods included from OneandoneBase

#formated_output, included, #init_client

Instance Method Details

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/chef/knife/oneandone_server_modify.rb', line 35

def run
  $stdout.sync = true

  init_client

  name_args.each do |server_id|
    server = OneAndOne::Server.new

    begin
      server.get(server_id: server_id)
    rescue StandardError => e
      if e.message.include? 'NOT_FOUND'
        ui.error("Server ID #{server_id} not found. Skipping.")
      else
        ui.error(e.message)
      end
      next
    end

    server.modify_hardware(
      fixed_instance_id: config[:fixed_size_id],
      vcore: config[:cpu],
      cores_per_processor: config[:cores],
      ram: config[:ram]
    )

    if config[:wait]
      puts ui.color('Reconfiguring, wait for the operation to complete...', :cyan).to_s
      server.wait_for

      puts "\t#{ui.color('ID', :cyan)}: #{server.id}"
      puts "\t#{ui.color('Name', :cyan)}: #{server.specs['name']}"
      puts "\t#{ui.color('Fixed Size ID', :cyan)}: #{server.specs['hardware']['fixed_instance_size_id']}"
      puts "\t#{ui.color('Processors', :cyan)}: #{server.specs['hardware']['vcore']}"
      puts "\t#{ui.color('Cores per Processor', :cyan)}: #{server.specs['hardware']['cores_per_processor']}"
      puts "\t#{ui.color('RAM (GB)', :cyan)}: #{server.specs['hardware']['ram']}\n"

      puts "Server's hardware is #{ui.color('modified', :bold)}"
    else
      puts "Server's hardware is #{ui.color('being modified', :bold)}"
    end
  end
end