Class: Chef::Knife::ProfitbricksFailoverRemove

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

Instance Method Summary collapse

Methods included from ProfitbricksBase

#connection, #error_and_exit, #get_image, included, #msg_pair, #validate_required_params

Instance Method Details

#runObject



30
31
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
# File 'lib/chef/knife/profitbricks_ipfailover_remove.rb', line 30

def run
  $stdout.sync = true
  validate_required_params(%i[datacenter_id lan_id ip nic_id], Chef::Config[:knife])

  connection

  lan = ProfitBricks::LAN.get(Chef::Config[:knife][:datacenter_id], Chef::Config[:knife][:lan_id])

  ipfailover = lan.properties['ipFailover']

  ipfailover.each_with_index do |value, index|
    if value['nicUuid'] == Chef::Config[:knife][:nic_id] && value['ip'] == Chef::Config[:knife][:ip]
      ipfailover.delete_at(index)
    end
  end

  lan.update(ipFailover: ipfailover)
  lan.wait_for { ready? }
  lan.reload

  puts "\n"
  puts "#{ui.color('ID', :cyan)}: #{lan.id}"
  puts "#{ui.color('Name', :cyan)}: #{lan.properties['name']}"
  puts "#{ui.color('Public', :cyan)}: #{lan.properties['public']}"
  puts "#{ui.color('IP Failover', :cyan)}: #{lan.properties['ipFailover']}"

  puts 'done'
end