Class: UCS
- Inherits:
-
Object
- Object
- UCS
- Defined in:
- lib/ucslib/service/ucs/ucs.rb
Constant Summary
Constants included from Stats
Instance Method Summary collapse
-
#initialize(authjson) ⇒ UCS
constructor
A new instance of UCS.
-
#rest_get(api_url) ⇒ Hash
Generic API get call.
- #rest_post(payload, api_url) ⇒ Object
- #to_boolean(str) ⇒ Object
Methods included from Destroy
Methods included from Inventory
#discover, #list_blades, #list_cpus, #list_memory, #list_running_firmware, #list_service_profiles, #list_vlans, #list_vsans
Methods included from Manage
#associate_service_profile_template_to_server_pool, #discover_state
Methods included from Provision
#set_chassis_discovery_policy, #set_fc_uplink_port, #set_host_firmware_package, #set_local_boot_policy, #set_local_disk_policy, #set_mac_pool, #set_management_ip_pool, #set_mgmt_firmware_package, #set_network_uplink_port, #set_ntp_server, #set_org, #set_port_channel, #set_power_policy, #set_pxe_boot_policy, #set_san_boot_policy, #set_server_pool, #set_server_port, #set_service_profile_template, #set_service_profiles, #set_service_profiles_from_template, #set_syslog_server, #set_time_zone, #set_uuid_pool, #set_vhba_template, #set_vlan, #set_vnic_template, #set_vsan, #set_wwnn_pool, #set_wwpn_pool
Methods included from Stats
#fetch, #get_hash, #show_all, #show_sample
Methods included from Update
#update_boot_policy_on_service_profile_template, #update_host_firmware_package
Methods included from Session
Constructor Details
#initialize(authjson) ⇒ UCS
Returns a new instance of UCS.
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 |
# File 'lib/ucslib/service/ucs/ucs.rb', line 38 def initialize (authjson) username = "#{JSON.parse(authjson)['username']}" password = "#{JSON.parse(authjson)['password']}" ip = "#{JSON.parse(authjson)['ip']}" #Required to default to true if verify_ssl is left out, more secure and backwards compatible @verify_ssl = JSON.parse(authjson)['verify_ssl'].nil? ? true : to_boolean(JSON.parse(authjson)['verify_ssl']) @url = "https://#{ip}/nuova" xml_builder = Nokogiri::XML::Builder.new do |xml| xml.aaaLogin('inName' => username, 'inPassword' => password) end aaa_login_xml = xml_builder.to_xml.to_s ucs_response = rest_post(aaa_login_xml,@url) ucs_login_doc = Nokogiri::XML(ucs_response) ucs_login_root = ucs_login_doc.root = ucs_login_root.attributes['outCookie'] # Archive code to be removed later. #TODO # begin # return session = { :cookie => "#{cookie}", # :username => "#{username}", # :password => "#{password}", # :ip => "#{ip}" }.to_json # rescue Exception => e # 'An Error Occured. Please check authentication credentials' # else # Process.exit # end end |
Instance Method Details
#rest_get(api_url) ⇒ Hash
Generic API get call
86 87 88 89 90 |
# File 'lib/ucslib/service/ucs/ucs.rb', line 86 def rest_get(api_url) RestClient::Request.execute(method: :get, url: api_url, verify_ssl: @verify_ssl).body end |
#rest_post(payload, api_url) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/ucslib/service/ucs/ucs.rb', line 72 def rest_post(payload, api_url) RestClient::Request.execute(method: :post, url: api_url, verify_ssl: @verify_ssl, payload: payload, headers: { content_type: 'text/xml', }).body end |
#to_boolean(str) ⇒ Object
92 93 94 |
# File 'lib/ucslib/service/ucs/ucs.rb', line 92 def to_boolean(str) str.to_s.downcase == "true" end |