Skip to content

Commit

Permalink
Merge pull request #426 from joseph-v/update_oceanstor
Browse files Browse the repository at this point in the history
Update oceanstor for Controller, Port and Disk resource support
  • Loading branch information
NajmudheenCT authored Dec 21, 2020
2 parents fc2b2a7 + d221a69 commit 7cbfc3b
Show file tree
Hide file tree
Showing 5 changed files with 813 additions and 6 deletions.
93 changes: 93 additions & 0 deletions delfin/drivers/huawei/oceanstor/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.

from delfin.common import constants

STATUS_HEALTH = '1'
STATUS_ACTIVE = '43'
STATUS_RUNNING = '10'
Expand All @@ -25,6 +27,97 @@
SNAPSHOT_TYPE = '27'
STATUS_POOL_ONLINE = '27'
STATUS_STORAGE_NORMAL = '1'
STATUS_CTRLR_OFFLINE = '28'
STATUS_CTRLR_UNKNOWN = '0'

PORT_TYPE_FC = '212'
PORT_TYPE_ETH = '213'
PORT_TYPE_SAS = '214'
PORT_TYPE_FCOE = '252'
PORT_TYPE_PCIE = '233'
PORT_TYPE_BOND = '235'

PORT_LOGICTYPE_HOST = '0'
PORT_HEALTH_UNKNOWN = '0'
PORT_HEALTH_NORMAL = '1'
PORT_HEALTH_FAULTY = '2'
PORT_HEALTH_ABOUTFAIL = '3'
PORT_HEALTH_PARTIALLYDAMAGED = '4'
PORT_HEALTH_INCONSISTENT = '9'

PORT_RUNNINGSTS_UNKNOWN = '0'
PORT_RUNNINGSTS_NORMAL = '1'
PORT_RUNNINGSTS_RUNNING = '2'
PORT_RUNNINGSTS_LINKUP = '10'
PORT_RUNNINGSTS_LINKDOWN = '11'
PORT_RUNNINGSTS_TOBERECOVERED = '33'

PORT_LOGICTYPE_HOST = '0'
PORT_LOGICTYPE_EXPANSION = '1'
PORT_LOGICTYPE_MANAGEMENT = '2'
PORT_LOGICTYPE_INTERNAL = '3'
PORT_LOGICTYPE_MAINTENANCE = '4'
PORT_LOGICTYPE_SERVICE = '5'
PORT_LOGICTYPE_MAINTENANCE2 = '6'
PORT_LOGICTYPE_INTERCONNECT = '11'

PortTypeMap = {
PORT_TYPE_FC: constants.PortType.FC,
PORT_TYPE_FCOE: constants.PortType.FCOE,
PORT_TYPE_ETH: constants.PortType.ETH,
PORT_TYPE_PCIE: constants.PortType.OTHER,
PORT_TYPE_SAS: constants.PortType.SAS,
PORT_TYPE_BOND: constants.PortType.OTHER,
}

PortLogicTypeMap = {
PORT_LOGICTYPE_HOST:
constants.PortLogicalType.SERVICE,
PORT_LOGICTYPE_EXPANSION:
constants.PortLogicalType.OTHER,
PORT_LOGICTYPE_MANAGEMENT:
constants.PortLogicalType.MANAGEMENT,
PORT_LOGICTYPE_INTERNAL:
constants.PortLogicalType.INTERNAL,
PORT_LOGICTYPE_MAINTENANCE:
constants.PortLogicalType.MAINTENANCE,
PORT_LOGICTYPE_SERVICE:
constants.PortLogicalType.SERVICE,
PORT_LOGICTYPE_MAINTENANCE2:
constants.PortLogicalType.MAINTENANCE,
PORT_LOGICTYPE_INTERCONNECT:
constants.PortLogicalType.INTERCONNECT,
}

DISK_STATUS_UNKNOWN = '0'
DISK_STATUS_NORMAL = '1'
DISK_STATUS_OFFLINE = '28'

DISK_TYPE_SAS = '1'
DISK_TYPE_SATA = '2'
DISK_TYPE_SSD = '3'

DISK_LOGICTYPE_FREE = '1'
DISK_LOGICTYPE_MEMBER = '2'
DISK_LOGICTYPE_HOTSPARE = '3'
DISK_LOGICTYPE_CACHE = '4'

DiskPhysicalTypeMap = {
DISK_TYPE_SATA: constants.DiskPhysicalType.SATA,
DISK_TYPE_SAS: constants.DiskPhysicalType.SAS,
DISK_TYPE_SSD: constants.DiskPhysicalType.SSD,
}

DiskLogicalTypeMap = {
DISK_LOGICTYPE_FREE:
constants.DiskLogicalType.FREE,
DISK_LOGICTYPE_MEMBER:
constants.DiskLogicalType.MEMBER,
DISK_LOGICTYPE_HOTSPARE:
constants.DiskLogicalType.HOTSPARE,
DISK_LOGICTYPE_CACHE:
constants.DiskLogicalType.CACHE,
}

ERROR_CONNECT_TO_SERVER = -403
ERROR_UNAUTHORIZED_TO_SERVER = -401
Expand Down
175 changes: 171 additions & 4 deletions delfin/drivers/huawei/oceanstor/oceanstor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import six

from oslo_log import log
from delfin.common import constants
from delfin.drivers.huawei.oceanstor import rest_client, consts, alert_handler
Expand All @@ -38,7 +40,7 @@ def get_storage(self, context):
storage = self.client.get_storage()

# Get firmware version
controller = self.client.get_controller()
controller = self.client.get_all_controllers()
firmware_ver = controller[0]['SOFTVER']

# Get status
Expand Down Expand Up @@ -179,13 +181,178 @@ def list_volumes(self, context):
'Failed to get list volumes from OceanStor')

def list_controllers(self, context):
pass
try:
# Get list of OceanStor controller details
controllers = self.client.get_all_controllers()

controller_list = []
for controller in controllers:
status = constants.ControllerStatus.NORMAL
if controller['RUNNINGSTATUS'] == consts.STATUS_CTRLR_UNKNOWN:
status = constants.ControllerStatus.UNKNOWN
if controller['RUNNINGSTATUS'] == consts.STATUS_CTRLR_OFFLINE:
status = constants.ControllerStatus.OFFLINE

c = {
'name': controller['NAME'],
'storage_id': self.storage_id,
'native_controller_id': controller['ID'],
'status': status,
'location': controller['LOCATION'],
'soft_version': controller['SOFTVER'],
'cpu_info': controller['CPUINFO'],
'memory_size': controller['MEMORYSIZE'],
}
controller_list.append(c)

return controller_list

except exception.DelfinException as err:
err_msg = "Failed to get controller metrics from OceanStor: %s" %\
(six.text_type(err))
LOG.error(err_msg)
raise err

except Exception as err:
err_msg = "Failed to get controller metrics from OceanStor: %s" %\
(six.text_type(err))
LOG.error(err_msg)
raise exception.InvalidResults(err_msg)

def list_ports(self, context):
pass
try:
# Get list of OceanStor port details
ports = self.client.get_all_ports()

port_list = []
for port in ports:
health_status = constants.PortHealthStatus.ABNORMAL
conn_status = constants.PortConnectionStatus.CONNECTED

logical_type = consts.PortLogicTypeMap.get(
port.get('LOGICTYPE'), constants.PortLogicalType.OTHER)

if port['HEALTHSTATUS'] == consts.PORT_HEALTH_UNKNOWN:
health_status = constants.PortHealthStatus.UNKNOWN
if port['HEALTHSTATUS'] == consts.PORT_HEALTH_NORMAL:
health_status = constants.PortHealthStatus.UNKNOWN

if port['RUNNINGSTATUS'] == consts.PORT_RUNNINGSTS_UNKNOWN:
conn_status = constants.PortConnectionStatus.UNKNOWN
if port['RUNNINGSTATUS'] == consts.PORT_RUNNINGSTS_LINKDOWN:
conn_status = constants.PortConnectionStatus.DISCONNECTED

speed = port.get('RUNSPEED') # ether -1 or M bits/sec
if speed == '-1':
speed = None
max_speed = port.get('MAXSPEED')

port_type = consts.PortTypeMap.get(port['TYPE'],
constants.PortType.OTHER)
# FC
if port['TYPE'] == consts.PORT_TYPE_FC:
max_speed = port['MAXSUPPORTSPEED'] # in 1000 M bits/s

# Ethernet
if port['TYPE'] == consts.PORT_TYPE_ETH:
max_speed = port['maxSpeed'] # in M bits/s
speed = port['SPEED'] # in M bits/s

# PCIE
if port['TYPE'] == consts.PORT_TYPE_PCIE:
speed = port['PCIESPEED']
logical_type = constants.PortLogicalType.OTHER

p = {
'name': port['NAME'],
'storage_id': self.storage_id,
'native_port_id': port['ID'],
'location': port.get('LOCATION'),
'connection_status': conn_status,
'health_status': health_status,
'type': port_type,
'logical_type': logical_type,
'speed': speed,
'max_speed': max_speed,
'native_parent_id': port.get('PARENTID'),
'wwn': port.get('WWN'),
'mac_address': port.get('MACADDRESS'),
'ipv4': port.get('IPV4ADDR'),
'ipv4_mask': port.get('IPV4MASK'),
'ipv6': port.get('IPV6ADDR'),
'ipv6_mask': port.get('IPV6MASK'),
}
port_list.append(p)

return port_list

except exception.DelfinException as err:
err_msg = "Failed to get port metrics from OceanStor: %s" %\
(six.text_type(err))
LOG.error(err_msg)
raise err

except Exception as err:
err_msg = "Failed to get port metrics from OceanStor: %s" %\
(six.text_type(err))
LOG.error(err_msg)
raise exception.InvalidResults(err_msg)

def list_disks(self, context):
pass
try:
# Get list of OceanStor disks details
disks = self.client.get_all_disks()

disk_list = []
for disk in disks:
status = constants.DiskStatus.NORMAL
if disk['RUNNINGSTATUS'] == consts.DISK_STATUS_OFFLINE:
status = constants.DiskStatus.OFFLINE
if disk['RUNNINGSTATUS'] == consts.DISK_STATUS_UNKNOWN:
status = constants.DiskStatus.ABNORMAL

physical_type = consts.DiskPhysicalTypeMap.get(
disk['DISKTYPE'], constants.DiskPhysicalType.UNKNOWN)

logical_type = consts.DiskLogicalTypeMap.get(
disk['LOGICTYPE'], constants.DiskLogicalType.UNKNOWN)

health_score = disk['HEALTHMARK']

capacity = int(disk['SECTORS']) * int(disk['SECTORSIZE'])

d = {
'name': disk['MODEL'] + ':' + disk['SERIALNUMBER'],
'storage_id': self.storage_id,
'native_disk_id': disk['ID'],
'serial_number': disk['SERIALNUMBER'],
'manufacturer': disk['MANUFACTURER'],
'model': disk['MODEL'],
'firmware': disk['FIRMWAREVER'],
'speed': int(disk['SPEEDRPM']),
'capacity': capacity,
'status': status,
'physical_type': physical_type,
'logical_type': logical_type,
'health_score': health_score,
'native_disk_group_id': None,
'location': disk['LOCATION'],
}
disk_list.append(d)

return disk_list

except exception.DelfinException as err:
err_msg = "Failed to get disk metrics from OceanStor: %s" %\
(six.text_type(err))
LOG.error(err_msg)
raise err

except Exception as err:
err_msg = "Failed to get disk metrics from OceanStor: %s" %\
(six.text_type(err))
LOG.error(err_msg)
raise exception.InvalidResults(err_msg)

def add_trap_config(self, context, trap_config):
pass
Expand Down
34 changes: 33 additions & 1 deletion delfin/drivers/huawei/oceanstor/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def get_storage(self):

return result['data']

def get_controller(self):
def get_all_controllers(self):
url = "/controller"
result = self.call(url, method='GET', log_filter_flag=True)

Expand All @@ -263,10 +263,42 @@ def get_controller(self):

return result['data']

def get_all_ports(self):
url = "/fc_port"
fc_ports = self.paginated_call(
url, None, "GET", log_filter_flag=True)

url = "/fcoe_port"
fcoe_ports = self.paginated_call(
url, None, "GET", log_filter_flag=True)

url = "/eth_port"
eth_ports = self.paginated_call(
url, None, "GET", log_filter_flag=True)

url = "/pcie_port"
pcie_ports = self.paginated_call(
url, None, "GET", log_filter_flag=True)

url = "/bond_port"
bond_ports = self.paginated_call(
url, None, "GET", log_filter_flag=True)

url = "/sas_port"
sas_ports = self.paginated_call(
url, None, "GET", log_filter_flag=True)

return fc_ports + fcoe_ports + eth_ports\
+ pcie_ports + bond_ports + sas_ports

def get_all_volumes(self):
url = "/lun"
return self.paginated_call(url, None, "GET", log_filter_flag=True)

def get_all_disks(self):
url = "/disk"
return self.paginated_call(url, None, "GET", log_filter_flag=True)

def get_all_pools(self):
url = "/storagepool"
return self.paginated_call(url, None, "GET", log_filter_flag=True)
Expand Down
Loading

0 comments on commit 7cbfc3b

Please sign in to comment.