Skip to content

Commit

Permalink
Merge pull request #24 from vranystepan/net_settings
Browse files Browse the repository at this point in the history
Manager/EthernetInterface settings
  • Loading branch information
jsmartt committed Jun 23, 2017
2 parents 1a1d0b6 + 48ff716 commit ac171cd
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# See default at https://github.com/bbatsov/rubocop/blob/master/config/default.yml
AllCops:
TargetRubyVersion: 2.1

Metrics/ClassLength:
Max: 200
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,25 @@ ntp_servers = ['10.1.1.1', '10.1.1.2']
client.set_ntp_server(ntp_servers)
```

#### Manager EthernetInterface settings

```ruby
# Get EthernetInteface settings
client.get_ilo_ethernet_interface
# Set EthernetInterface to obtain all IPv4 parameters from DHCP server
client.set_ilo_ipv4_dhcp
# Set static IPv4 address, netmask and gateway
client.set_ilo_ipv4_static(ip: '192.168.1.1', netmask: '255.255.255.0', gateway: '192.168.1.254')
# Set IPv4 DNS servers
client.set_ilo_ipv4_dns_servers(dns_servers: ['2.2.2.2', '4.4.4.4', '8.8.8.8'])
# Set hostname and domain name 'server-ilo.domain.local'
client.set_ilo_hostname(hostname: 'server-ilo', domain_name: 'domain.local')
```

#### Firmware

```ruby
Expand Down
1 change: 1 addition & 0 deletions lib/ilo-sdk/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ def initialize(options = {})
include ChassisHelper
include ServiceRootHelper
include HttpsCertHelper
include EthernetInterfaceHelper
end
end
108 changes: 108 additions & 0 deletions lib/ilo-sdk/helpers/ethernet_interface_helper.rb
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
2 changes: 1 addition & 1 deletion lib/ilo-sdk/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

# Gem version defined here
module ILO_SDK
VERSION = '1.2.2'.freeze
VERSION = '1.3.0'.freeze
end
147 changes: 147 additions & 0 deletions spec/unit/helpers/ethernet_interface_helper_spec.rb
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

0 comments on commit ac171cd

Please sign in to comment.