Module: Collins::Api::Management
- Included in:
- Collins::Api
- Defined in:
- lib/collins/api/management.rb
Instance Method Summary collapse
- #ipmi_create(asset_or_tag, username, password, address, gateway, netmask) ⇒ Object
- #ipmi_update(asset_or_tag, options = {}) ⇒ Object
- #power!(asset_or_tag, action) ⇒ Object
- #power_status(asset_or_tag) ⇒ Object
- #provision(asset_or_tag, profile, contact, options = {}) ⇒ Object
- #provisioning_profiles ⇒ Object
Instance Method Details
#ipmi_create(asset_or_tag, username, password, address, gateway, netmask) ⇒ Object
60 61 62 63 |
# File 'lib/collins/api/management.rb', line 60 def ipmi_create asset_or_tag, username, password, address, gateway, netmask ipmi_update asset_or_tag, :username => username, :password => password, :address => address, :gateway => gateway, :netmask => netmask end |
#ipmi_update(asset_or_tag, options = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/collins/api/management.rb', line 65 def ipmi_update asset_or_tag, = {} asset = get_asset_or_tag asset_or_tag parameters = { :username => get_option(:username, , nil), :password => get_option(:password, , nil), :address => get_option(:address, , nil), :gateway => get_option(:gateway, , nil), :netmask => get_option(:netmask, , nil) } parameters = select_non_empty_parameters parameters return true if parameters.empty? logger.debug("Updating asset #{asset.tag} IPMI info with parameters #{parameters.inspect}") http_post("/api/asset/#{asset.tag}/ipmi", parameters, asset.location) do |response| parse_response response, :expects => [200,201], :as => :status end end |
#power!(asset_or_tag, action) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/collins/api/management.rb', line 45 def power! asset_or_tag, action asset = get_asset_or_tag asset_or_tag if action.to_s.downcase == "status" then return power_status asset_or_tag end action = Collins::Power.normalize_action action parameters = { :action => action } logger.debug("Calling power action on #{asset.tag}, action #{action}") http_post("/api/asset/#{asset.tag}/power", parameters, asset.location) do |response| parse_response response, :expects => 200, :as => :status end end |
#power_status(asset_or_tag) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/collins/api/management.rb', line 37 def power_status asset_or_tag asset = get_asset_or_tag asset_or_tag logger.debug("Checking power status of #{asset.tag}") http_get("/api/asset/#{asset.tag}/power", {}, asset.location) do |response| parse_response response, :expects => 200, :as => :message, :raise => strict?, :default => "Unknown" end end |
#provision(asset_or_tag, profile, contact, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/collins/api/management.rb', line 17 def provision asset_or_tag, profile, contact, = {} asset = get_asset_or_tag asset_or_tag parameters = { :profile => profile, :contact => contact, :suffix => [:suffix], :primary_role => [:primary_role], :secondary_role => [:secondary_role], :pool => [:pool], :activate => [:activate] } parameters = select_non_empty_parameters parameters if parameters.empty? then raise CollinsError.new("provision requires at least a profile") end http_post("/api/provision/#{asset.tag}", parameters, asset.location) do |response| parse_response response, :expects => 200, :as => :status end end |
#provisioning_profiles ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/collins/api/management.rb', line 8 def provisioning_profiles logger.debug("Getting provisioning profiles from collins") http_get("/api/provision/profiles") do |response| parse_response response, :expects => 200, :as => :data do |json| json["PROFILES"].map { |o| Collins::Profile.new(o) } end end end |