-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into san_manager
- Loading branch information
Showing
5 changed files
with
451 additions
and
0 deletions.
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
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") |
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,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) |
Oops, something went wrong.