Class: Chef::Knife::BaremetalcloudListConfigurations
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::BaremetalcloudListConfigurations
- Defined in:
- lib/chef/knife/baremetalcloud_list_configurations.rb
Instance Method Summary collapse
-
#errorHandling(response) ⇒ Object
Method to handle baremetalcloud errors.
-
#run ⇒ Object
Plugin method called by Knife.
-
#verifyArguments ⇒ Object
Method to verify mandatory arguments.
Instance Method Details
#errorHandling(response) ⇒ Object
Method to handle baremetalcloud errors
20 21 22 23 24 25 26 27 |
# File 'lib/chef/knife/baremetalcloud_list_configurations.rb', line 20 def errorHandling(response) # Error handling unless response[:error].nil? puts "#{ui.color("ERROR:", :bold)} #{response[:error][:name]}" puts "Description: #{response[:error][:description]}" exit 1 end end |
#run ⇒ Object
Plugin method called by Knife
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/chef/knife/baremetalcloud_list_configurations.rb', line 45 def run # Verify mandatory arguments verifyArguments # Configure the API abstraction @bmc @bmc = Fog::Compute.new({ :bare_metal_cloud_username => config[:baremetalcloud_username], :bare_metal_cloud_password => config[:baremetalcloud_password], :provider => 'BareMetalCloud' }) # Get the API response response = @bmc.list_configurations.body # Error handling errorHandling(response) response[:"available-server"].each do |resp| puts "#{resp[:quantity]}\t#{resp[:configuration]}" end end |
#verifyArguments ⇒ Object
Method to verify mandatory arguments
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/chef/knife/baremetalcloud_list_configurations.rb', line 30 def verifyArguments # Parameters :baremetalcloud_username and :baremetalcloud_password are mandatory unless config[:baremetalcloud_username] ui.error("--username is a mandatory parameter") exit 1 end unless config[:baremetalcloud_password] ui.error("--password is a mandatory parameter") exit 1 end end |