Skip to content

Commit

Permalink
Merge branch 'master' into san_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
nabhajit-ray authored Nov 9, 2022
2 parents 71e559d + 0cd113c commit 7fc9786
Show file tree
Hide file tree
Showing 5 changed files with 451 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/config-rename.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"server_hostname": "",
"server_username": "",
"server_password": "",
"rack_manager_hostname": "",
"rack_manager_username": "",
"rack_manager_password": "",
"storage_system_hostname": "",
"storage_system_username": "",
"storage_system_password": "",
Expand Down
146 changes: 146 additions & 0 deletions examples/rack_managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# -*- coding: utf-8 -*-
###
# (C) Copyright [2022] 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.
###

from pprint import pprint

from hpeOneView.oneview_client import OneViewClient
from config_loader import try_load_from_file

config = {
"ip": "<oneview_ip>",
"credentials": {
"userName": "<username>",
"password": "<password>"
}
}

# Try load config from a file (if there is a config file)
config = try_load_from_file(config)

options = {
"hostname": config['rack_manager_hostname'],
"username": config['rack_manager_username'],
"password": config['rack_manager_password'],
"force": False
}

oneview_client = OneViewClient(config)

rack_managers = oneview_client.rack_managers

# Get all rack managers
rackmanagers = []
print("\n## Get all rack managers")
rack_managers_all = rack_managers.get_all()
# pprint(rack_managers_all)
for rm in rack_managers_all:
print('%s' % rm['name'])
rackmanagers.append(rm['name'])

# Adds a rack manager
# This is only supported on appliance which support managers
print("\n## Add a rack manager")
added_rack_manager = rack_managers.add(options)
print("Added rack manager '%s'.\n uri = '%s'" % (added_rack_manager.data['name'], added_rack_manager.data['uri']))

# Get list of chassis from all rack managers
print("\n## Get list of chassis from all rack managers")
chassis_all = rack_managers.get_all_chassis()
for ch in chassis_all['members']:
pprint("Name:{} , ChassisType:{}".format(ch['name'], ch['chassisType']))

# Get list of manager resources from all rack managers
print("\n## Get list of manager resources from all rack managers")
managers_all = rack_managers.get_all_managers()
for mn in managers_all['members']:
pprint("Name:{} , ManagerType:{}".format(mn['name'], mn['managerType']))

# Get collection of partition resources from all rack managers
print("\n## Get collection of partition resources from all rack managers")
partition_all = rack_managers.get_all_partitions()
for pn in partition_all['members']:
pprint("Name:{} , partitionNum:{}".format(pn['name'], pn['partitionNum']))


# Get recently added rack manager resource
if rackmanagers:
rackmanager = rack_managers.get_by_name(rackmanagers[0])
pprint(rackmanager.data)

# Get all chassis associated with recently added rack manager
print("\n## Get all chassis associated with recently added rack manager")
if rackmanager:
associated_chassis = rackmanager.get_associated_chassis()
pprint(associated_chassis)

# Retrieves a specific chassis that is part of the rack manager.
print("\n## Retrieves a specific chassis that is part of the rack manager")
if associated_chassis:
chassis_uri = associated_chassis['members'][0]['uri']
pprint(rack_managers.get_a_specific_resource(chassis_uri))

# Get the environmental configuration of a rack manager
print("\n## Get the environmental configuration of a rack manager")
if rackmanager:
env_conf = rackmanager.get_environmental_configuration()
pprint(env_conf)

# Get all chassis associated with recently added rack manager
print("\n## Get all managers associated with recently added rack manager")
if rackmanager:
associated_manager = rackmanager.get_associated_managers()
pprint(associated_manager)

# Retrieves a specific manager that is part of the rack manager.
print("\n## Retrieves a specific chassis that is part of the rack manager")
if associated_manager:
manager_uri = associated_manager['members'][0]['uri']
pprint(rack_managers.get_a_specific_resource(manager_uri))

# Get all chassis associated with recently added rack manager
print("\n## Get all partitions associated with recently added rack manager")
if rackmanager:
associated_partitions = rackmanager.get_associated_partitions()
pprint(associated_partitions)

# Retrieves a specific partition that is part of the rack manager.
print("\n## Retrieves a specific chassis that is part of the rack manager")
if associated_partitions:
partition_uri = associated_partitions['members'][0]['uri']
pprint(rack_managers.get_a_specific_resource(partition_uri))

# Get the environmental configuration of a rack manager
print("\n## Get the remote support settings of a rack manager")
if rackmanager:
remote_conf = rackmanager.get_remote_support_settings()
pprint(remote_conf)

# Refreshes a rack manager
print("\n## Refreshes a rack manager")
if rackmanagers:
rm_name = rackmanagers[0]
rm_to_refresh = rack_managers.get_by_name(rm_name)
rm_to_refresh.patch('RefreshRackManagerOp', '', '')
print("Succesfully refreshed rack manager.")

# remove a recently added rack manager
print("\n## Remove a recently added rack manager")
if rackmanagers:
rm_name = rackmanagers[0]
rm_to_remove = rack_managers.get_by_name(rm_name)
rm_to_remove.remove()
print("Succesfully removed rack manager")
12 changes: 12 additions & 0 deletions hpeOneView/oneview_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from hpeOneView.resources.servers.enclosure_groups import EnclosureGroups
from hpeOneView.resources.servers.server_hardware import ServerHardware
from hpeOneView.resources.servers.server_hardware_types import ServerHardwareTypes
from hpeOneView.resources.servers.rack_manager import RackManager
from hpeOneView.resources.servers.id_pools_ranges import IdPoolsRanges
from hpeOneView.resources.servers.id_pools_ipv4_ranges import IdPoolsIpv4Ranges
from hpeOneView.resources.servers.id_pools_ipv4_subnets import IdPoolsIpv4Subnets
Expand Down Expand Up @@ -153,6 +154,7 @@ def __init__(self, config, sessionID=None):
self.__metric_streaming = None
self.__server_hardware = None
self.__server_hardware_types = None
self.__rack_managers = None
self.__id_pools_vsn_ranges = None
self.__id_pools_vmac_ranges = None
self.__id_pools_vwwn_ranges = None
Expand Down Expand Up @@ -473,6 +475,16 @@ def server_hardware_types(self):
"""
return ServerHardwareTypes(self.__connection)

@property
def rack_managers(self):
"""
Gets the Rack Manager API client.
Returns:
RackManager:
"""
return RackManager(self.__connection)

@property
def id_pools_vsn_ranges(self):
"""
Expand Down
151 changes: 151 additions & 0 deletions hpeOneView/resources/servers/rack_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# -*- coding: utf-8 -*-
###
# (C) Copyright [2022] 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.
###


from hpeOneView.resources.resource import Resource, ResourcePatchMixin, ensure_resource_client


class RackManager(ResourcePatchMixin, Resource):
"""
The rack manager resource provides methods for managing one or more rack managers and its components.
"""

URI = '/rest/rack-managers'

def __init__(self, connection, data=None):
super(RackManager, self).__init__(connection, data)

def add(self, information, timeout=-1):
"""
Adds a rack manager for management by the appliance.
Args:
information (dict): Object to create
timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
Returns:
dict: Created Rack Manager
"""
return self.create(information, timeout=timeout)

def get_all_chassis(self):
"""
Gets the list of chassis from all rack managers.
Returns: List of Chassis
"""
uri = self.URI + "/chassis"
return self._helper.do_get(uri)

@ensure_resource_client
def get_associated_chassis(self):
"""
Gets the list of chassis that are part of a rack manager.
Returns: List of Chassis
"""
uri = "{}/chassis".format(self.data["uri"])
return self._helper.do_get(uri)

def get_a_specific_resource(self, uri):
"""
Gets a specific resource that is part of a rack manager.
Returns:
dict: Resource
"""
return self._helper.do_get(uri)

def get_all_managers(self):
"""
Gets the list of manager resources from all rack managers.
Returns: list of managers
"""
uri = self.URI + "/managers"
return self._helper.do_get(uri)

def get_all_partitions(self):
"""
Gets the list of partition resources from all rack managers.
Returns: List of partitions
"""
uri = self.URI + "/partitions"
return self._helper.do_get(uri)

def remove(self, force=False, timeout=-1):
"""
Removes the rack manager with the specified URI.
Note: This operation is only supported on appliances that support rack managers.
Args:
force (bool):
If set to true, the operation completes despite any problems with
network connectivity or errors on the resource itself. The default is false.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView; it just stops waiting for its completion.
Returns:
bool: Indicates whether the resource was successfully removed.
"""
return self.delete(force=force, timeout=timeout)

@ensure_resource_client
def get_environmental_configuration(self):
"""
Gets the environmental configuration of a rack manager.
Returns:
dict: Environmental confifuration
"""
uri = "{}/environmentalConfiguration".format(self.data["uri"])
return self._helper.do_get(uri)

@ensure_resource_client
def get_associated_managers(self):
"""
Gets the list of managers that are part of a rack manager.
Returns: List of Managers
"""
uri = "{}/managers".format(self.data["uri"])
return self._helper.do_get(uri)

@ensure_resource_client
def get_associated_partitions(self):
"""
Gets the list of partitions that are part of a rack manager.
Returns: List of Partitions
"""
uri = "{}/partitions".format(self.data["uri"])
return self._helper.do_get(uri)

@ensure_resource_client
def get_remote_support_settings(self):
"""
Gets the remote support settings of a rack manager.
Returns:
dict: Environmental confifuration
"""
uri = "{}/remoteSupportSettings".format(self.data["uri"])
return self._helper.do_get(uri)
Loading

0 comments on commit 7fc9786

Please sign in to comment.