Module: Supermicro::Network
- Included in:
- Client
- Defined in:
- lib/supermicro/network.rb
Instance Method Summary collapse
- #get_bmc_network ⇒ Object
- #set_bmc_dhcp ⇒ Object
- #set_bmc_network(ipv4: nil, mask: nil, gateway: nil, dns_primary: nil, dns_secondary: nil, hostname: nil, dhcp: false, wait: true) ⇒ Object
Instance Method Details
#get_bmc_network ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/supermicro/network.rb', line 7 def get_bmc_network # Get the manager's ethernet interface response = authenticated_request(:get, "/redfish/v1/Managers/1/EthernetInterfaces/1") if response.status == 200 data = JSON.parse(response.body) { "ipv4" => data.dig("IPv4Addresses", 0, "Address"), "mask" => data.dig("IPv4Addresses", 0, "SubnetMask"), "gateway" => data.dig("IPv4Addresses", 0, "Gateway"), "mode" => data.dig("IPv4Addresses", 0, "AddressOrigin"), # DHCP or Static "mac" => data["MACAddress"], "hostname" => data["HostName"], "fqdn" => data["FQDN"], "dns_servers" => data["NameServers"] || [], "name" => data["Id"] || "BMC", "speed_mbps" => data["SpeedMbps"] || 1000, "status" => data.dig("Status", "Health") || "OK", "kind" => "ethernet" } else raise Error, "Failed to get BMC network config. Status: #{response.status}" end end |
#set_bmc_dhcp ⇒ Object
126 127 128 129 |
# File 'lib/supermicro/network.rb', line 126 def set_bmc_dhcp # Convenience method set_bmc_network(dhcp: true) end |
#set_bmc_network(ipv4: nil, mask: nil, gateway: nil, dns_primary: nil, dns_secondary: nil, hostname: nil, dhcp: false, wait: true) ⇒ Object
32 33 34 35 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/supermicro/network.rb', line 32 def set_bmc_network(ipv4: nil, mask: nil, gateway: nil, dns_primary: nil, dns_secondary: nil, hostname: nil, dhcp: false, wait: true) if dhcp puts "Setting BMC to DHCP mode...".yellow body = { "DHCPv4" => { "DHCPEnabled" => true } } else puts "Configuring BMC network settings...".yellow body = {} # Configure static IP if provided if ipv4 && mask # Must explicitly disable DHCP when setting static IP body["DHCPv4"] = { "DHCPEnabled" => false } body["IPv4StaticAddresses"] = [{ "Address" => ipv4, "SubnetMask" => mask, "Gateway" => gateway }] puts " IP: #{ipv4}/#{mask}".cyan puts " Gateway: #{gateway}".cyan if gateway end # Configure DNS if provided if dns_primary || dns_secondary dns_servers = [] dns_servers << dns_primary if dns_primary dns_servers << dns_secondary if dns_secondary body["StaticNameServers"] = dns_servers puts " DNS: #{dns_servers.join(', ')}".cyan end # Configure hostname if provided if hostname body["HostName"] = hostname puts " Hostname: #{hostname}".cyan end end response = authenticated_request( :patch, "/redfish/v1/Managers/1/EthernetInterfaces/1", body: body.to_json, headers: { 'Content-Type' => 'application/json' } ) if response.status.between?(200, 299) puts "BMC network configuration submitted.".green # If we're changing IP and wait is enabled, handle the transition if ip_address && wait puts "Waiting for BMC to apply network changes...".yellow # Check if response contains a task/job ID if response.status == 202 && response.headers['Location'] # Job was created, monitor it job_uri = response.headers['Location'] puts "Monitoring job: #{job_uri}".cyan # Wait for current job to complete (on old IP) wait_for_network_job(job_uri) else # No job, just wait a bit for the change to apply sleep 5 end # Now verify the BMC is reachable on the new IP puts "Verifying BMC is reachable on new IP: #{ip_address}...".yellow if verify_bmc_on_new_ip(ip_address, @username, @password) puts "BMC successfully configured and reachable on #{ip_address}".green # Update our client's host to the new IP @host = ip_address true else puts "WARNING: BMC configuration may have succeeded but cannot reach BMC on #{ip_address}".yellow puts "The BMC may still be applying changes or may require manual verification.".yellow false end else puts "BMC network configured successfully.".green puts "WARNING: BMC may restart network services. Connection may be lost.".yellow if ip_address && !wait true end else raise Error, "Failed to configure BMC network: #{response.status} - #{response.body}" end end |