Class: Chef::Knife::VcVappNetworkExternal

Inherits:
Chef::Knife
  • Object
show all
Includes:
VcCommon, VcNetworkCommon, VcVappCommon
Defined in:
lib/chef/knife/vapp/vc_vapp_network_external.rb

Instance Method Summary collapse

Methods included from VcNetworkCommon

#get_network

Methods included from VcVappCommon

#get_vapp, included

Methods included from VcCommon

#connection, #deprecation_msg, #generate_key, #get_password, included, #locate_config_value, #locate_org_option, #notice_msg, #out_msg, #pretty_symbol, #sort_by_key, #store_config, #store_password, #wait_task

Instance Method Details

#runObject



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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/chef/knife/vapp/vc_vapp_network_external.rb', line 41

def run
  $stdout.sync = true

  command_arg = @name_args.shift
  vapp_arg = @name_args.shift
  network_arg = @name_args.shift

  unless command_arg =~ /add|delete|edit/
    raise ArgumentError, "Invalid command #{command_arg} supplied. Only add, delete and edit are allowed."
  end

  command = command_arg.to_sym

  config = {
    :fence_mode => 'bridged',
    :retain_network => locate_config_value(:retain_network)
  }

  connection.

  vapp = get_vapp(vapp_arg)
  network = get_network network_arg

  unless network
    raise new ArgumentError, "Network #{network_arg} not found in vDC, please use `vapp network internal` if you want an internal network."
  end

  unless command == :delete
    parent_network_arg = locate_config_value(:parent_network)
    if parent_network_arg
      ui.msg "Retrieving parent network details"
      parent_network = get_network parent_network_arg
      config[:parent_network] =  { :id => parent_network[:id],
                                   :name => parent_network[:name] }
    else
      ui.msg "Forcing parent network to itself"
      config[:parent_network] = { :id => network[:id],
                                  :name => network[:name] }
    end
  end

  case command
    when :add
      ui.msg "Adding #{network[:name]} to vApp..."
      task_id, response = connection.add_org_network_to_vapp vapp[:id], network, config
      wait_task(connection, task_id)
    when :delete
      ui.msg "Removing #{network[:name]} from vApp..."
      task_id, response = connection.delete_vapp_network vapp[:id], network
      wait_task(connection, task_id)
    when :edit
      ui.msg "vApp network configuration for #{network[:name]}..."
      task_id, response = connection.set_vapp_network_config vapp[:id], network, config
      wait_task(connection, task_id)
  end

  connection.logout
end