Class: Chef::Knife::DigitalOceanDomainCreate

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

Instance Method Summary collapse

Methods included from DigitalOceanBase

#client, included, load_deps, #locate_config_value, #validate!, #wait_for_status

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/chef/knife/digital_ocean_domain_create.rb', line 33

def run
  $stdout.sync = true

  validate!

  unless locate_config_value(:name)
    ui.error('Name cannot be empty. => -N <domain-name>')
    exit 1
  end

  unless locate_config_value(:ip_address)
    ui.error('IP Address cannot be empty. => -I <ip-address>')
    exit 1
  end

  domain = DropletKit::Domain.new ip_address: locate_config_value(:ip_address), name: locate_config_value(:name)
  result = client.domains.create domain
  ui.info 'OK' if result.class == DropletKit::Domain || ui.error(JSON.parse(result)['message'])
end