Class: Chef::Knife::ClcServerCreate

Inherits:
Chef::Knife show all
Includes:
Knife::Clc::Async, Knife::Clc::Base, Knife::Clc::Bootstrap, Knife::Clc::CloudExtensions, Knife::Clc::IpAssignment, Knife::Clc::ServerLaunch
Defined in:
lib/chef/knife/clc_server_create.rb

Instance Method Summary collapse

Methods included from Knife::Clc::Bootstrap

#bootstrapper, included

Methods included from Knife::Clc::IpAssignment

included, #ip_assigner

Methods included from Knife::Clc::ServerLaunch

included, #server_launcher

Methods included from Knife::Clc::CloudExtensions

#cloud_adapter

Methods included from Knife::Clc::Async

included

Methods included from Knife::Clc::Base

#connection, #context, #errors, included, #run, #show_errors

Instance Method Details

#async_create_serverObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/chef/knife/clc_server_create.rb', line 66

def async_create_server
  if config[:clc_bootstrap]
    bootstrapper.async_bootstrap(server_launcher.launch_parameters)
    ui.info 'Bootstrap has been scheduled'
  end

  ui.info 'Requesting server launch...'
  links = server_launcher.execute
  ui.info 'Launch request has been sent'
  ui.info "You can check launch operation status with 'knife clc operation show #{links['operation']['id']}'"

  if config[:clc_allowed_protocols]
    ui.info 'Requesting public IP...'
    server = connection.follow(links['resource'])
    ip_links = ip_assigner.execute(server['id'])
    ui.info 'Public IP request has been sent'
    ui.info "You can check assignment operation status with 'knife clc operation show #{ip_links['operation']['id']}'"
  end

  argv = [links['resource']['id'], '--uuid', '--creds']
  argv << '--ports' if config[:clc_allowed_protocols]

  ui.info "You can check server status later with 'knife clc server show #{argv.join(' ')}'"
end

#executeObject



28
29
30
# File 'lib/chef/knife/clc_server_create.rb', line 28

def execute
  config[:clc_wait] ? sync_create_server : async_create_server
end

#parse_and_validate_parametersObject



22
23
24
25
26
# File 'lib/chef/knife/clc_server_create.rb', line 22

def parse_and_validate_parameters
  server_launcher.prepare
  ip_assigner.prepare
  bootstrapper.prepare
end

#sync_create_serverObject



32
33
34
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
# File 'lib/chef/knife/clc_server_create.rb', line 32

def sync_create_server
  ui.info 'Requesting server launch...'
  links = server_launcher.execute
  connection.wait_for(links['operation']['id']) { putc '.' }
  ui.info "\n"
  ui.info "Server has been launched"

  server = connection.follow(links['resource'])

  if config[:clc_allowed_protocols]
    ui.info 'Requesting public IP...'
    ip_links = ip_assigner.execute(server['id'])
    connection.wait_for(ip_links['operation']['id']) { putc '.' }
    ui.info "\n"
    ui.info 'Public IP has been assigned'
    server = connection.follow(links['resource'])
  end

  if config[:clc_bootstrap]
    bootstrapper.sync_bootstrap(server)
  end

  argv = [links['resource']['id'], '--uuid', '--creds']
  if config[:clc_allowed_protocols]
    argv << '--ports'
  end

  if (username = config[:clc_username]) && (password = config[:clc_password])
    argv.concat(['--username', username, '--password', password])
  end

  Chef::Knife::ClcServerShow.new(argv).run
end