Skip to content

Commit

Permalink
Merge pull request #229 from HewlettPackard/san_manager
Browse files Browse the repository at this point in the history
Support san  manager
  • Loading branch information
nabhajit-ray authored Nov 9, 2022
2 parents 0cd113c + 7fc9786 commit 25d9c6c
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 276 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 8.0.0
#### Notes
Extends support of the SDK to OneView REST API version 4600 (OneView v8.0.0)
#### Major changes
Added support for San Manager resources

# 7.2.0
#### Notes
Extends support of the SDK to OneView REST API version 4400 (OneView v7.2.0)
Expand Down
71 changes: 44 additions & 27 deletions examples/san_managers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
###
# (C) Copyright [2019] Hewlett Packard Enterprise Development LP
# (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.
Expand All @@ -21,7 +21,7 @@
from hpeOneView.oneview_client import OneViewClient

# This example has options pre-defined for 'Brocade Network Advisor' and 'Cisco' type SAN Managers
PROVIDER_NAME = 'Cisco'
PROVIDER_NAME = 'Brocade FOS Switch'

config = {
"ip": "<oneview_ip>",
Expand All @@ -34,44 +34,60 @@
# # To run this sample you must define the following resources for a Brocade Network Advisor
manager_host = '<san_manager_hostname_or_ip>'
manager_port = '<port_number_not_quoted>'
manager_username = '<san_manager_user_name>'
manager_username = '<san_manager_username>'
manager_password = '<san_manager_password>'

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

oneview_client = OneViewClient(config)
san_providers = oneview_client.san_providers
san_managers = oneview_client.san_managers


# Print default connection info for Brocade Network Advisor
print("\nGet {} default connection info:".format(PROVIDER_NAME))
default_info = oneview_client.san_managers.get_default_connection_info(PROVIDER_NAME)
default_info = san_providers.get_default_connection_info(PROVIDER_NAME)
print(default_info)
for property in default_info:
print(" '{name}' - '{value}'".format(**property))
# Add a Brocade Network Advisor
provider_uri = oneview_client.san_managers.get_provider_uri(PROVIDER_NAME)
provider_uri = san_providers.get_provider_uri(PROVIDER_NAME)

options_for_brocade = {
'providerDisplayName': PROVIDER_NAME,
'connectionInfo': [
{
'name': 'Host',
'value': manager_host
"name": "Host",
"displayName": "Host",
"required": True,
"value": manager_host,
"valueType": "String",
"valueFormat": "IPAddressOrHostname"
},
{
'name': 'Port',
'value': manager_port
"name": "Username",
"displayName": "Username",
"required": True,
"value": manager_username,
"valueType": "String",
"valueFormat": "None"
},
{
'name': 'Username',
'value': manager_username
"name": "Password",
"displayName": "Password",
"required": True,
"value": manager_password,
"valueType": "String",
"valueFormat": "SecuritySensitive"
},
{
'name': 'Password',
'value': manager_password
},
{
'name': 'UseSsl',
'value': True
"name": "UseHttps",
"displayName": "UseHttps",
"required": True,
"value": True,
"valueType": "Boolean",
"valueFormat": "None"
}
]
}
Expand Down Expand Up @@ -146,10 +162,10 @@
]
}

if PROVIDER_NAME == 'Brocade Network Advisor':
san_manager = oneview_client.san_managers.add(options_for_brocade, provider_uri)
if PROVIDER_NAME == 'Brocade FOS Switch':
san_manager = san_providers.add(options_for_brocade, provider_uri)
elif PROVIDER_NAME == 'Cisco':
san_manager = oneview_client.san_managers.add(options_for_cisco, provider_uri)
san_manager = san_providers.add(options_for_cisco, provider_uri)
else:
provider_error_msg = 'Options for the "%s" provider not pre-added to this example file. Validate '
provider_error_msg < 'and or create options for that provider and remove this exception.' % PROVIDER_NAME
Expand All @@ -161,22 +177,23 @@
info = {
'refreshState': "RefreshPending"
}
san_manager = oneview_client.san_managers.update(resource=info, id_or_uri=san_manager['uri'])
san_manager = san_managers.update(resource=info, id_or_uri=san_manager['uri'])
print(" 'refreshState' successfully updated to '{refreshState}'".format(**san_manager))

print("\nGet SAN manager by uri")
san_manager_byuri = oneview_client.san_managers.get(san_manager['uri'])
print(" Found '{name}' at uri: {uri}".format(**san_manager_byuri))
san_manager_byuri = san_managers.get_by_uri(san_manager['uri'])

print(" Found '{name}' at uri: {uri}".format(**san_manager_byuri.data))

print("\nGet all SAN managers")
san_managers = oneview_client.san_managers.get_all()
for manager in san_managers:
san_manager_all = san_managers.get_all()
for manager in san_manager_all:
print(" '{name}' at uri: {uri}".format(**manager))

print("\nGet a SAN Manager by name")
san_managers_by_name = oneview_client.san_managers.get_by_name(manager_host)
san_managers_by_name = san_managers.get_by_name(manager_host)
pprint(san_managers_by_name)

print("\nDelete the SAN Manager previously created...")
oneview_client.san_managers.remove(san_manager)
san_managers_by_name.remove()
print("The SAN Manager was deleted successfully.")
21 changes: 16 additions & 5 deletions hpeOneView/oneview_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from future import standard_library


standard_library.install_aliases()

import json
Expand Down Expand Up @@ -68,6 +69,7 @@
from hpeOneView.resources.facilities.datacenters import Datacenters
from hpeOneView.resources.fc_sans.managed_sans import ManagedSANs
from hpeOneView.resources.fc_sans.san_managers import SanManagers
from hpeOneView.resources.fc_sans.san_providers import SanProviders
from hpeOneView.resources.fc_sans.endpoints import Endpoints
from hpeOneView.resources.networking.logical_interconnects import LogicalInterconnects
from hpeOneView.resources.networking.logical_interconnect_groups import LogicalInterconnectGroups
Expand Down Expand Up @@ -170,6 +172,7 @@ def __init__(self, config, sessionID=None):
self.__roles = None
self.__datacenters = None
self.__san_managers = None
self.__san_providers = None
self.__endpoints = None
self.__logical_interconnects = None
self.__sas_logical_interconnects = None
Expand Down Expand Up @@ -792,14 +795,12 @@ def racks(self):
@property
def san_managers(self):
"""
Gets the SanManagers API client.
Gets the Repositories API client.
Returns:
SanManagers:
Repositories:
"""
if not self.__san_managers:
self.__san_managers = SanManagers(self.__connection)
return self.__san_managers
return SanManagers(self.__connection)

@property
def endpoints(self):
Expand Down Expand Up @@ -1287,3 +1288,13 @@ def repositories(self):
Repositories:
"""
return Repositories(self.__connection)

@property
def san_providers(self):
"""
Gets the Repositories API client.
Returns:
Repositories:
"""
return SanProviders(self.__connection)
106 changes: 26 additions & 80 deletions hpeOneView/resources/fc_sans/san_managers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
###
# (C) Copyright [2019] Hewlett Packard Enterprise Development LP
# (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.
Expand All @@ -25,26 +25,22 @@
standard_library.install_aliases()


from hpeOneView.resources.resource import ResourceClient
from hpeOneView.resources.resource import Resource


class SanManagers(object):
class SanManagers(Resource):
"""
SAN Managers API client.
"""
URI = '/rest/fc-sans/device-managers'
PROVIDER_URI = '/rest/fc-sans/providers'

def __init__(self, con):
self._connection = con
self._client = ResourceClient(con, self.URI)
self._provider_client = ResourceClient(con, self.PROVIDER_URI)
def __init__(self, connection, data=None):
super(SanManagers, self).__init__(connection, data)

def get_all(self, start=0, count=-1, query='', sort=''):
def get_all(self, start=0, count=-1, filter='', sort='', query=''):
"""
Retrieves the list of registered SAN Managers.
Args:
start:
The first item to return, using 0-based indexing.
Expand All @@ -53,6 +49,9 @@ def get_all(self, start=0, count=-1, query='', sort=''):
The number of resources to return. A count of -1 requests all items. The actual number of items in
the response may differ from the requested count if the sum of start and count exceed the total number
of items.
filter (list or str):
A general filter/query string to narrow the list of items returned. The
default is no filter; all resources are returned.
query:
A general query string to narrow the list of resources returned.
The default is no query - all resources are returned.
Expand All @@ -64,19 +63,7 @@ def get_all(self, start=0, count=-1, query='', sort=''):
list: A list of SAN managers.
"""
return self._client.get_all(start=start, count=count, query=query, sort=sort)

def get(self, id_or_uri):
"""
Retrieves a single registered SAN Manager by ID or URI.
Args:
id_or_uri: Can be either the SAN Manager resource ID or URI.
Returns:
dict: The SAN Manager resource.
"""
return self._client.get(id_or_uri=id_or_uri)
return self._helper.get_all(start=start, count=count, filter=filter, sort=sort, query=query,)

def update(self, resource, id_or_uri):
"""
Expand All @@ -89,68 +76,26 @@ def update(self, resource, id_or_uri):
Returns:
dict: The device manager resource.
"""
return self._client.update(resource=resource, uri=id_or_uri)

def add(self, resource, provider_uri_or_id, timeout=-1):
"""
Adds a Device Manager under the specified provider.
Args:
resource (dict): Object to add.
provider_uri_or_id: ID or URI of provider.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView, just stop waiting for its completion.
Returns:
dict: Added SAN Manager.
"""
uri = self._provider_client.build_uri(provider_uri_or_id) + "/device-managers"
return self._client.create(resource=resource, uri=uri, timeout=timeout)
return self._helper.update(resource=resource, uri=id_or_uri)

def get_provider_uri(self, provider_display_name):
def remove(self, force=False, timeout=-1):
"""
Gets uri for a specific provider.
Removes the SAN Manager from OneView.
Args:
provider_display_name: Display name of the provider.
Returns:
uri
"""
providers = self._provider_client.get_by('displayName', provider_display_name)
return providers[0]['uri'] if providers else None

def get_default_connection_info(self, provider_name):
"""
Gets default connection info for a specific provider.
Args:
provider_name: Name of the provider.
Returns:
dict: Default connection information.
"""
provider = self._provider_client.get_by_name(provider_name)
if provider:
return provider['defaultConnectionInfo']
else:
return {}

def remove(self, resource, timeout=-1):
"""
Removes a registered SAN Manager.
Args:
resource (dict): Object to delete.
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 if the resource was successfully removed.
dict: Details of associated resource.
"""
return self._client.delete(resource, timeout=timeout)
headers = {'If-Match': '*'}
return self.delete(force=force, timeout=timeout, custom_headers=headers)

def get_by_name(self, name):
"""
Expand All @@ -160,11 +105,12 @@ def get_by_name(self, name):
name: Name of the SAN Manager
Returns:
dict: SAN Manager.
SAN Manager.
"""
san_managers = self._client.get_all()
san_managers = self.get_all()
result = [x for x in san_managers if x['name'] == name]
return result[0] if result else None

return self.new(self._connection, result[0])if result else None

def get_by_provider_display_name(self, provider_display_name):
"""
Expand All @@ -174,8 +120,8 @@ def get_by_provider_display_name(self, provider_display_name):
provider_display_name: Name of the Provider Display Name
Returns:
dict: SAN Manager.
SAN Manager.
"""
san_managers = self._client.get_all()
san_managers = self.get_all()
result = [x for x in san_managers if x['providerDisplayName'] == provider_display_name]
return result[0] if result else None
return self.new(self._connection, result[0])if result else None
Loading

0 comments on commit 25d9c6c

Please sign in to comment.