Class: Knifecosmic::CosmicServerRemoveNic
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Knifecosmic::CosmicServerRemoveNic
- Defined in:
- lib/chef/knife/cosmic_server_remove_nic.rb
Instance Method Summary collapse
Methods included from Chef::Knife::KnifecosmicBaseList
included, #list_object, #list_object_fields, #output_format
Methods included from Chef::Knife::KnifecosmicBase
Instance Method Details
#run ⇒ Object
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 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 99 |
# File 'lib/chef/knife/cosmic_server_remove_nic.rb', line 36 def run @server_id, @nic_id = name_args if @server_id.nil? || @nic_id.nil? show_usage ui.fatal("You must provide both a nic id and a server id") exit(1) end object_list = [] if locate_config_value(:fields) locate_config_value(:fields).split(',').each { |n| object_list << ui.color(("#{n}").strip, :bold) } else object_list << ui.color('Server', :bold) object_list << ui.color('Network', :bold) object_list << ui.color('Type', :bold) object_list << ui.color('Default', :bold) object_list << ui.color('Address', :bold) object_list << ui.color('Gateway', :bold) object_list << ui.color('Netmask', :bold) object_list << ui.color('ID', :bold) end columns = object_list.count connection_result = connection.remove_nic_from_vm( @nic_id, @server_id ) output_format(connection_result) object_list << connection_result['name'] object_list << '' object_list << '' object_list << '' object_list << '' object_list << '' object_list << '' object_list << '' if connection_result['nic'] connection_result['nic'].each do |r| if locate_config_value(:fields) locate_config_value(:fields).downcase.split(',').each { |n| object_list << ((r[("#{n}").strip]).to_s || 'N/A') } else object_list << '' object_list << r['networkname'].to_s object_list << r['type'].to_s object_list << (r['isdefault'] ? r['isdefault'].to_s : 'false') object_list << (r['ipaddress'] || '') object_list << (r['gateway'] || '') object_list << (r['netmask'] || '') object_list << (r['networkid'] || '') end end puts ui.list(object_list, :uneven_columns_across, columns) list_object_fields(connection_result) if locate_config_value(:fieldlist) else ui.error("No nicosmic returned in response") end end |