-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from vranystepan/net_settings
Manager/EthernetInterface settings
- Loading branch information
Showing
6 changed files
with
278 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
|
||
module ILO_SDK | ||
# Contains helper methods for EthernetInterface IPv4 actions | ||
module EthernetInterfaceHelper | ||
# Get all the Ethernet Interface settings | ||
# @param manager_id [Integer, String] ID of the Manager | ||
# @param ethernet_interface [Integer, String] ID of the EthernetInterface | ||
# @raise [RuntimeError] if the request failed | ||
# @return [Hash] EthernetInterface settings | ||
def get_ilo_ethernet_interface(manager_id: 1, ethernet_interface: 1) | ||
response_handler(rest_get("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/")) | ||
end | ||
|
||
# Set EthernetInterface to obtain IPv4 settings from DHCP | ||
# @param manager_id [Integer, String] ID of the Manager | ||
# @param ethernet_interface [Integer, String] ID of the EthernetInterface | ||
# @raise [RuntimeError] if the request failed | ||
# @return true | ||
def set_ilo_ipv4_dhcp(manager_id: 1, ethernet_interface: 1) | ||
new_action = { | ||
'Oem' => { | ||
'Hp' => { | ||
'DHCPv4' => { | ||
'Enabled' => true, | ||
'UseDNSServers' => true, | ||
'UseDomainName' => true, | ||
'UseGateway' => true, | ||
'UseNTPServers' => true, | ||
'UseStaticRoutes' => true, | ||
'UseWINSServers' => true | ||
} | ||
} | ||
} | ||
} | ||
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action) | ||
response_handler(response) | ||
true | ||
end | ||
|
||
# Set EthernetInterface to static IPv4 address | ||
# @param ip [String] IPv4 address | ||
# @param netmask [String] IPv4 subnet mask | ||
# @param gateway [String] IPv4 default gateway | ||
# @param manager_id [Integer, String] ID of the Manager | ||
# @param ethernet_interface [Integer, String] ID of the EthernetInterface | ||
# @raise [RuntimeError] if the request failed | ||
# @return true | ||
def set_ilo_ipv4_static(ip:, netmask:, gateway: '0.0.0.0', manager_id: 1, ethernet_interface: 1) | ||
new_action = { | ||
'Oem' => { 'Hp' => { 'DHCPv4' => { 'Enabled' => false } } }, | ||
'IPv4Addresses' => [ | ||
'Address' => ip, 'SubnetMask' => netmask, 'Gateway' => gateway | ||
] | ||
} | ||
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action) | ||
response_handler(response) | ||
true | ||
end | ||
|
||
# Set EthernetInterface DNS servers | ||
# @param dns_servers [Array] list of DNS servers | ||
# @param manager_id [Integer, String] ID of the Manager | ||
# @param ethernet_interface [Integer, String] ID of the EthernetInterface | ||
# @raise [RuntimeError] if the request failed | ||
# @return true | ||
def set_ilo_ipv4_dns_servers(dns_servers:, manager_id: 1, ethernet_interface: 1) | ||
new_action = { | ||
'Oem' => { | ||
'Hp' => { | ||
'DHCPv4' => { 'UseDNSServers' => false }, | ||
'IPv4' => { 'DNSServers' => dns_servers } | ||
} | ||
} | ||
} | ||
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action) | ||
response_handler(response) | ||
true | ||
end | ||
|
||
# Set iLO hostname and domain name | ||
# @param hostname [String] iLO hostname | ||
# @param domain_name [String] iLO domain name | ||
# @param manager_id [Integer, String] ID of the Manager | ||
# @param ethernet_interface [Integer, String] ID of the EthernetInterface | ||
# @raise [RuntimeError] if the request failed | ||
# @return true | ||
def set_ilo_hostname(hostname:, domain_name: nil, manager_id: 1, ethernet_interface: 1) | ||
new_action = { 'Oem' => { 'Hp' => { 'HostName' => hostname } } } | ||
new_action['Oem']['Hp'].merge!('DHCPv4' => {}, 'DHCPv6' => {}) if domain_name | ||
new_action['Oem']['Hp']['DHCPv4']['UseDomainName'] = false if domain_name | ||
new_action['Oem']['Hp']['DHCPv6']['UseDomainName'] = false if domain_name | ||
new_action['Oem']['Hp']['DomainName'] = domain_name if domain_name | ||
response = rest_patch("/redfish/v1/Managers/#{manager_id}/EthernetInterfaces/#{ethernet_interface}/", body: new_action) | ||
response_handler(response) | ||
true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,5 @@ | |
|
||
# Gem version defined here | ||
module ILO_SDK | ||
VERSION = '1.2.2'.freeze | ||
VERSION = '1.3.0'.freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
require_relative './../../spec_helper' | ||
|
||
RSpec.describe ILO_SDK::Client do | ||
include_context 'shared context' | ||
|
||
describe '#get_ilo_ethernet_interface' do | ||
before(:all) do | ||
@settings = { 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3' } | ||
end | ||
|
||
it 'makes a GET rest call' do | ||
fake_response = FakeResponse.new(@settings) | ||
expect(@client).to receive(:rest_get).with('/redfish/v1/Managers/1/EthernetInterfaces/1/').and_return(fake_response) | ||
expect(@client.get_ilo_ethernet_interface).to eq(@settings) | ||
end | ||
|
||
it 'allows the system_id to be set' do | ||
fake_response = FakeResponse.new(@settings) | ||
expect(@client).to receive(:rest_get).with('/redfish/v1/Managers/2/EthernetInterfaces/1/').and_return(fake_response) | ||
expect(@client.get_ilo_ethernet_interface(manager_id: 2)).to eq(@settings) | ||
end | ||
|
||
it 'allows system_id and ethernet_interface to be set' do | ||
fake_response = FakeResponse.new(@settings) | ||
expect(@client).to receive(:rest_get).with('/redfish/v1/Managers/2/EthernetInterfaces/2/').and_return(fake_response) | ||
expect(@client.get_ilo_ethernet_interface(manager_id: 2, ethernet_interface: 2)).to eq(@settings) | ||
end | ||
|
||
end | ||
|
||
describe '#set_ilo_dhcp' do | ||
before(:all) do | ||
@enable_dhcp_body = { | ||
'Oem' => { | ||
'Hp' => { | ||
'DHCPv4' => { | ||
'Enabled' => true, | ||
'UseDNSServers' => true, | ||
'UseDomainName' => true, | ||
'UseGateway' => true, | ||
'UseNTPServers' => true, | ||
'UseStaticRoutes' => true, | ||
'UseWINSServers' => true | ||
} | ||
} | ||
} | ||
} | ||
end | ||
|
||
it 'makes a PATCH rest call' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/1/EthernetInterfaces/1/', body: @enable_dhcp_body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_ipv4_dhcp).to eq(true) | ||
end | ||
|
||
it 'allows the system_id to be set' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/2/EthernetInterfaces/1/', body: @enable_dhcp_body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_ipv4_dhcp(manager_id: 2)).to eq(true) | ||
end | ||
|
||
it 'allows system_id and ethernet_interface to be set' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/2/EthernetInterfaces/2/', body: @enable_dhcp_body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_ipv4_dhcp(manager_id: 2, ethernet_interface: 2)).to eq(true) | ||
end | ||
end | ||
|
||
describe '#set_ilo_ipv4_static' do | ||
before(:all) do | ||
@body = { | ||
'Oem' => { 'Hp' => { 'DHCPv4' => { 'Enabled' => false } } }, | ||
'IPv4Addresses' => ['Address' => '192.168.1.1', 'SubnetMask' => '255.255.255.0', 'Gateway' => '0.0.0.0'] | ||
} | ||
end | ||
|
||
it 'makes a PATCH rest call' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/1/EthernetInterfaces/1/', body: @body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_ipv4_static(ip: '192.168.1.1', netmask: '255.255.255.0')).to eq(true) | ||
end | ||
|
||
it 'allows the gateway to be set' do | ||
body = Marshal.load(Marshal.dump(@body)) | ||
body['IPv4Addresses'][0]['Gateway'] = '192.168.1.254' | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/1/EthernetInterfaces/1/', body: body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_ipv4_static(ip: '192.168.1.1', netmask: '255.255.255.0', gateway: '192.168.1.254')).to eq(true) | ||
end | ||
|
||
it 'allows the system_id to be set' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/2/EthernetInterfaces/1/', body: @body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_ipv4_static(ip: '192.168.1.1', netmask: '255.255.255.0', manager_id: 2)).to eq(true) | ||
end | ||
|
||
it 'allows system_id and ethernet_interface to be set' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/2/EthernetInterfaces/2/', body: @body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_ipv4_static(ip: '192.168.1.1', netmask: '255.255.255.0', manager_id: 2, ethernet_interface: 2)).to eq(true) | ||
end | ||
end | ||
|
||
describe '#set_ilo_ipv4_dns_servers' do | ||
before(:all) do | ||
@dns_servers = ['2.2.2.2', '4.4.4.4', '8.8.8.8'] | ||
@body = { 'Oem' => { 'Hp' => { 'DHCPv4' => { 'UseDNSServers' => false }, 'IPv4' => { 'DNSServers' => @dns_servers } } } } | ||
end | ||
|
||
it 'makes a PATCH rest call' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/1/EthernetInterfaces/1/', body: @body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_ipv4_dns_servers(dns_servers: @dns_servers)).to eq(true) | ||
end | ||
|
||
it 'allows the system_id to be set' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/2/EthernetInterfaces/1/', body: @body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_ipv4_dns_servers(dns_servers: @dns_servers, manager_id: 2)).to eq(true) | ||
end | ||
|
||
it 'allows system_id and ethernet_interface to be set' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/2/EthernetInterfaces/2/', body: @body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_ipv4_dns_servers(dns_servers: @dns_servers, manager_id: 2, ethernet_interface: 2)).to eq(true) | ||
end | ||
end | ||
|
||
describe '#set_ilo_hostname' do | ||
before(:all) do | ||
@body = { 'Oem' => { 'Hp' => { 'HostName' => 'server-ilo' } } } | ||
end | ||
|
||
it 'makes a PATCH rest call' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/1/EthernetInterfaces/1/', body: @body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_hostname(hostname: 'server-ilo')).to eq(true) | ||
end | ||
|
||
it 'allows domain_name to be set' do | ||
body = Marshal.load(Marshal.dump(@body)) | ||
body['Oem']['Hp'].merge!('DHCPv4' => { 'UseDomainName' => false }, 'DHCPv6' => { 'UseDomainName' => false }) | ||
body['Oem']['Hp']['DomainName'] = 'domain.local' | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/1/EthernetInterfaces/1/', body: body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_hostname(hostname: 'server-ilo', domain_name: 'domain.local')).to eq(true) | ||
end | ||
|
||
it 'allows the system_id to be set' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/2/EthernetInterfaces/1/', body: @body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_hostname(hostname: 'server-ilo', manager_id: 2)).to eq(true) | ||
end | ||
|
||
it 'allows system_id and ethernet_interface to be set' do | ||
expect(@client).to receive(:rest_patch).with('/redfish/v1/Managers/2/EthernetInterfaces/2/', body: @body).and_return(FakeResponse.new) | ||
expect(@client.set_ilo_hostname(hostname: 'server-ilo', manager_id: 2, ethernet_interface: 2)).to eq(true) | ||
end | ||
end | ||
end |