class Chef::Knife::CloudstackNetworkCreate
Public Instance Methods
run()
click to toggle source
# File lib/chef/knife/cloudstack_network_create.rb, line 75 def run $stdout.sync = true validate! netoptions = {} mandatoryoptions = {} if (locate_config_value(:name).nil? || locate_config_value(:networkoffering).nil? || locate_config_value(:zone).nil?) puts "Name (-n), Service Offering ID (-o), and Zone ID (-z) are required." else mandatoryoptions['name'] = locate_config_value(:name) mandatoryoptions['networkofferingid'] = locate_config_value(:networkoffering) mandatoryoptions['zoneid'] = locate_config_value(:zone) if locate_config_value(:startip) != nil netoptions['startip'] = locate_config_value(:startip) end if locate_config_value(:endip) != nil netoptions['endip'] = locate_config_value(:endip) end if locate_config_value(:netmask) != nil netoptions['netmask'] = locate_config_value(:netmask) end if locate_config_value(:gateway) != nil netoptions['gateway'] = locate_config_value(:gateway) end if locate_config_value(:vlan) != nil netoptions['vlan'] = locate_config_value(:vlan) end if locate_config_value(:displaytext) != nil mandatoryoptions['displaytext'] = locate_config_value(:displaytext) else mandatoryoptions['displaytext'] = locate_config_value(:name) end Chef::Log.debug("Options: #{netoptions}") response = connection.create_network(mandatoryoptions['displaytext'], mandatoryoptions['name'], mandatoryoptions['networkofferingid'], mandatoryoptions['zoneid'], netoptions) Chef::Log.debug("API Response: #{response}") network_list = [ ui.color('ID', :bold), ui.color('Name', :bold), ui.color('Display Text', :bold), ui.color('Zone ID', :bold), ui.color('VLAN', :bold), ui.color('State', :bold) ] newnetwork = response['createnetworkresponse']['network'] network_list << newnetwork['id'].to_s network_list << newnetwork['name'].to_s network_list << newnetwork['displaytext'].to_s network_list << newnetwork['zoneid'].to_s network_list << newnetwork['vlan'].to_s network_list << newnetwork['state'].to_s puts ui.list(network_list, :columns_across, 6) end end