Module: Chef::Knife::Cloud::VcairHelpers
- Included in:
- VcairImageList, VcairIpList, VcairNetworkList, VcairServerCreate, VcairServerShow, VcairVmDelete, VcairVmList
- Defined in:
- lib/chef/knife/vcair_helpers.rb
Instance Method Summary collapse
- #config_value(key) ⇒ Object
- #create_service_instance ⇒ Object
- #get_id(value) ⇒ Object
- #msg_pair(label, value, color = :cyan) ⇒ Object
- #net ⇒ Object
- #network_config ⇒ Object
- #org ⇒ Object
- #template ⇒ Object
- #validate!(keys = [:vcair_username, :vcair_password, :vcair_api_host, :vcair_org, :vcair_api_version]) ⇒ Object
- #vapp ⇒ Object
- #vdc ⇒ Object
- #vm ⇒ Object
Instance Method Details
#config_value(key) ⇒ Object
62 63 64 65 |
# File 'lib/chef/knife/vcair_helpers.rb', line 62 def config_value(key) key = key.to_sym Chef::Config[:knife][key] || config[key] end |
#create_service_instance ⇒ Object
13 14 15 |
# File 'lib/chef/knife/vcair_helpers.rb', line 13 def create_service_instance VcairService.new end |
#get_id(value) ⇒ Object
67 68 69 |
# File 'lib/chef/knife/vcair_helpers.rb', line 67 def get_id(value) value['id'] end |
#msg_pair(label, value, color = :cyan) ⇒ Object
71 72 73 74 75 |
# File 'lib/chef/knife/vcair_helpers.rb', line 71 def msg_pair(label, value, color=:cyan) if value && !value.to_s.empty? puts "#{ui.color(label, color)}: #{value}" end end |
#net ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/chef/knife/vcair_helpers.rb', line 30 def net if config_value(:vcair_net) @net ||= org.networks.get_by_name(config_value(:vcair_net)) else # Grab first non-isolated (bridged, natRouted) network @net ||= org.networks.find { |n| n if !n.fence_mode.match("isolated") } end end |
#network_config ⇒ Object
55 56 57 58 59 |
# File 'lib/chef/knife/vcair_helpers.rb', line 55 def network_config @network_config ||= vapp.network_config.find do |n| n if n[:networkName].match(net.name) end end |
#org ⇒ Object
17 18 19 20 |
# File 'lib/chef/knife/vcair_helpers.rb', line 17 def org @org ||= @service.connection.organizations.get_by_name( config_value(:vcair_org)) end |
#template ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/chef/knife/vcair_helpers.rb', line 39 def template # TODO: find by catalog item ID and/or NAME # TODO: add option to search just public and/or private catalogs @template ||= org.catalogs.map do |cat| cat.catalog_items.get_by_name(config_value(:image)) end.compact.first end |
#validate!(keys = [:vcair_username, :vcair_password, :vcair_api_host, :vcair_org, :vcair_api_version]) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/chef/knife/vcair_helpers.rb', line 77 def validate!(keys=[:vcair_username, :vcair_password, :vcair_api_host, :vcair_org, :vcair_api_version]) errors = [] keys.each do |k| pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)/i) ? w.upcase : w.capitalize } if config_value(k).nil? errors << "You did not provide a valid '#{pretty_key}' value. Please set knife[:#{k}] in your knife.rb or pass as an option." end end if errors.each{|e| ui.error(e)}.any? exit 1 end end |
#vapp ⇒ Object
47 48 49 |
# File 'lib/chef/knife/vcair_helpers.rb', line 47 def vapp @vapp ||= vdc.vapps.get_by_name(config_value(:chef_node_name)) end |
#vdc ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/chef/knife/vcair_helpers.rb', line 22 def vdc if config_value(:vcair_vdc) @vdc ||= org.vdcs.get_by_name(config_value(:vcair_vdc)) else @vdc ||= org.vdcs.first end end |
#vm ⇒ Object
51 52 53 |
# File 'lib/chef/knife/vcair_helpers.rb', line 51 def vm @vm ||= vapp.vms.find {|v| v.vapp_name == config_value(:chef_node_name)} end |