Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unity fix the issue which when filesystem is None in get_share #696

Merged
merged 32 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f0c9413
fix the issue which when filesystem is None in get
tanjiangyu-ghca Sep 16, 2021
cf8f094
fix the issue which when filesystem is None in get_share
tanjiangyu-ghca Sep 16, 2021
7fde282
Merge pull request #238 from tanjiangyu-ghca/unity_0916
tanjiangyu-ghca Sep 16, 2021
a74134e
Merge branch 'master' into unity_0916
tanjiangyu-ghca Sep 16, 2021
c138b3b
fix some compatibility issue
tanjiangyu-ghca Sep 16, 2021
f5b1b43
Merge pull request #240 from tanjiangyu-ghca/unity_0916
tanjiangyu-ghca Sep 16, 2021
fc2601a
Merge branch 'master' into unity_0916
tanjiangyu-ghca Sep 23, 2021
a27c6b0
do some optimize
tanjiangyu-ghca Sep 23, 2021
7056324
Merge pull request #254 from tanjiangyu-ghca/unity_0916
tanjiangyu-ghca Sep 23, 2021
4757c4e
do some optimize
tanjiangyu-ghca Sep 23, 2021
ecef23e
change fcport connect_status
tanjiangyu-ghca Sep 23, 2021
31a119e
Merge pull request #258 from tanjiangyu-ghca/unity_0916
tanjiangyu-ghca Sep 23, 2021
edbd0b9
Merge branch 'master' into unity_0916
tanjiangyu-ghca Sep 23, 2021
cb81e5f
change fcport localtion
tanjiangyu-ghca Sep 24, 2021
2dc4992
Merge pull request #259 from tanjiangyu-ghca/unity_0916
tanjiangyu-ghca Sep 24, 2021
ab1bc35
Merge branch 'master' into unity_0916
tanjiangyu-ghca Sep 27, 2021
87836c4
change port speed and disk name
tanjiangyu-ghca Sep 28, 2021
bb094ea
change get alarm's timeout
tanjiangyu-ghca Sep 28, 2021
2ac74fb
change get alarm's timeout
tanjiangyu-ghca Sep 28, 2021
cf27b5d
Merge pull request #262 from tanjiangyu-ghca/unity_0916
tanjiangyu-ghca Sep 28, 2021
a7afa8f
Merge branch 'master' into unity_0916
tanjiangyu-ghca Sep 28, 2021
90353b6
change get alarm's timeout
tanjiangyu-ghca Sep 29, 2021
2d7c4d2
change get alarm's timeout
tanjiangyu-ghca Sep 29, 2021
fc900a9
change get alarm's timeout
tanjiangyu-ghca Sep 29, 2021
375fa2a
Merge pull request #263 from tanjiangyu-ghca/unity_0916
tanjiangyu-ghca Sep 29, 2021
b81681f
Merge branch 'unity_0916' of https://github.com/tanjiangyu-ghca/delfi…
tanjiangyu-ghca Sep 29, 2021
21180a5
remove the disk when it's slot is empty
tanjiangyu-ghca Sep 30, 2021
ca0eedc
Merge pull request #264 from tanjiangyu-ghca/unity_0916
tanjiangyu-ghca Sep 30, 2021
d5437e8
change disk physicaltype
tanjiangyu-ghca Sep 30, 2021
8e3b0bc
change disk physicaltype
tanjiangyu-ghca Sep 30, 2021
23ebf0a
Merge pull request #265 from tanjiangyu-ghca/unity_0916
tanjiangyu-ghca Sep 30, 2021
756a576
Merge branch 'master' into unity_0916
tanjiangyu-ghca Oct 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion delfin/drivers/dell_emc/unity/alert_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ def parse_queried_alerts(self, alert_model_list, alert_dict, query_para):
alert_model['description'] = content.get('description')
alert_model['resource_type'] = resource_type
alert_model['location'] = location
alert_model_list.append(alert_model)
alert_model['match_key'] = hashlib.md5(
content.get('message').encode()).hexdigest()
if alert_model['severity'] == 'Informational':
continue
alert_model_list.append(alert_model)
except Exception as e:
LOG.error(e)
err_msg = "Failed to build alert model as some attributes " \
Expand Down
2 changes: 2 additions & 0 deletions delfin/drivers/dell_emc/unity/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.

DEFAULT_TIMEOUT = 10
ALERT_TIMEOUT = 20
TRAP_DESC = {
"1:127486a": ["WARNING", "ALRT_LCC_FW_UPGRADE_FAILED",
"The link control card (LCC) will continue to function with "
Expand Down
53 changes: 36 additions & 17 deletions delfin/drivers/dell_emc/unity/rest_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from delfin import cryptor
from delfin import exception
from delfin.drivers.dell_emc.unity import consts
from delfin.drivers.utils.rest_client import RestClient

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -63,7 +64,8 @@ def login(self):
self.session.auth = requests.auth.HTTPBasicAuth(
self.rest_username, cryptor.decode(self.rest_password))
res = self.call_with_token(
RestHandler.REST_AUTH_URL, data, 'GET')
RestHandler.REST_AUTH_URL, data, 'GET',
consts.DEFAULT_TIMEOUT)
if res.status_code == 200:
self.session.headers[RestHandler.AUTH_KEY] = \
cryptor.encode(res.headers[RestHandler.AUTH_KEY])
Expand All @@ -81,44 +83,47 @@ def login(self):
LOG.error("Login error: %s", six.text_type(e))
raise e

def call_with_token(self, url, data, method):
def call_with_token(self, url, data, method, calltimeout):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data can set default ot None, method default to GET, calltimeout default to consts.DEFAULT_TIMEOUT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

auth_key = None
if self.session:
auth_key = self.session.headers.get(RestHandler.AUTH_KEY, None)
if auth_key:
self.session.headers[RestHandler.AUTH_KEY] \
= cryptor.decode(auth_key)
res = self.do_call(url, data, method)
res = self.do_call(url, data, method, calltimeout)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value of parameter calltimeout in do_call() is from driver code of HPE 3par, method do_call() is a common method, I think its default value should be also from common module or from its own.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if auth_key:
self.session.headers[RestHandler.AUTH_KEY] = auth_key
return res

def logout(self):
try:
if self.san_address:
self.call(RestHandler.REST_LOGOUT_URL, method='POST')
self.call(RestHandler.REST_LOGOUT_URL,
consts.DEFAULT_TIMEOUT,
data={}, method='POST')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter data can use default value of method call().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if self.session:
self.session.close()
except Exception as e:
err_msg = "Logout error: %s" % (six.text_type(e))
LOG.error(err_msg)
raise e

def get_rest_info(self, url, data=None, method='GET'):
def get_rest_info(self, url, data=None, method='GET',
calltimeout=consts.DEFAULT_TIMEOUT):
result_json = None
res = self.call(url, data, method)
res = self.call(url, calltimeout, data, method)
if res.status_code == 200:
result_json = res.json()
return result_json

def call(self, url, data=None, method=None):
def call(self, url, calltimeout, data=None, method=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the parameters of call() is the same as the parameters of call_with_token(), these parameters should be in the same order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

try:
res = self.call_with_token(url, data, method)
res = self.call_with_token(url, data, method, calltimeout)
if res.status_code == 401:
LOG.error("Failed to get token, status_code:%s,error_mesg:%s" %
(res.status_code, res.text))
self.login()
res = self.call_with_token(url, data, method)
res = self.call_with_token(url, data, method, calltimeout)
elif res.status_code == 503:
raise exception.InvalidResults(res.text)
return res
Expand Down Expand Up @@ -167,7 +172,16 @@ def get_all_alerts(self, page_number):
'messageId,message,description,'
'descriptionId,state',
page_number)
result_json = self.get_rest_info(url)
result_json = self.get_rest_info(url, consts.ALERT_TIMEOUT)
return result_json

def get_all_alerts_without_state(self, page_number):
url = '%s?%s&page=%s' % (RestHandler.REST_ALERTS_URL,
'fields=id,timestamp,severity,component,'
'messageId,message,description,'
'descriptionId',
page_number)
result_json = self.get_rest_info(url, consts.ALERT_TIMEOUT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second parameter of get_rest_info() is data, not calltimeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return result_json

def remove_alert(self, alert_id):
Expand All @@ -180,16 +194,15 @@ def remove_alert(self, alert_id):
def get_all_controllers(self):
url = '%s?%s' % (RestHandler.REST_CONTROLLER_URL,
'fields=id,name,health,model,slotNumber,'
'emcPartNumber,emcSerialNumber,manufacturer,'
'memorySize')
'manufacturer,memorySize')
result_json = self.get_rest_info(url)
return result_json

def get_all_disks(self):
url = '%s?%s' % (RestHandler.REST_DISK_URL,
'fields=id,name,health,model,slotNumber,'
'manufacturer,version,emcSerialNumber,wwn'
'emcPartNumber,rpm,size,diskGroup')
'manufacturer,version,emcSerialNumber,wwn,'
'rpm,size,diskGroup')
result_json = self.get_rest_info(url)
return result_json

Expand All @@ -203,7 +216,7 @@ def get_all_fcports(self):
def get_all_ethports(self):
url = '%s?%s' % (RestHandler.REST_ETHPORT_URL,
'fields=id,name,health,portNumber,storageProcessor,'
'speed,isLinkUp,macAddress,maxMtu')
'speed,isLinkUp,macAddress')
result_json = self.get_rest_info(url)
return result_json

Expand All @@ -221,6 +234,13 @@ def get_all_filesystems(self):
result_json = self.get_rest_info(url)
return result_json

def get_all_filesystems_without_flr(self):
url = '%s?%s' % (RestHandler.REST_FILESYSTEM_URL,
'fields=id,name,health,sizeAllocated,accessPolicy,'
'sizeTotal,sizeUsed,isThinEnabled,pool')
result_json = self.get_rest_info(url)
return result_json

def get_all_nfsshares(self):
url = '%s?%s' % (RestHandler.REST_NFSSHARE_URL,
'fields=id,filesystem,name,path')
Expand Down Expand Up @@ -249,7 +269,6 @@ def get_all_userquotas(self):

def get_quota_configs(self):
url = '%s?%s' % (RestHandler.REST_QUOTACONFIG_URL,
'fields=id,filesystem,treeQuota,quotaPolicy,'
'isUserQuotaEnabled,isAccessDenyEnabled')
'fields=id,filesystem,treeQuota,quotaPolicy')
result_json = self.get_rest_info(url)
return result_json
103 changes: 66 additions & 37 deletions delfin/drivers/dell_emc/unity/unity.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ def get_storage(self, context):
used = content.get('sizeUsed')
subs = content.get('sizeSubscribed')
break
soft_version = version_info.get('entries')
for soft_info in soft_version:
content = soft_info.get('content', {})
version = content.get('id')
break
if version_info:
soft_version = version_info.get('entries')
for soft_info in soft_version:
content = soft_info.get('content', {})
if content:
version = content.get('id')
break
system_result = {
'name': name,
'vendor': 'DELL EMC',
Expand Down Expand Up @@ -164,6 +166,8 @@ def list_volumes(self, context):
volume_list = []
while True:
luns = self.rest_handler.get_all_luns(page_number)
if luns is None:
break
if 'entries' not in luns:
break
if len(luns['entries']) < 1:
Expand All @@ -178,6 +182,11 @@ def list_alerts(self, context, query_para=None):
alert_model_list = []
while True:
alert_list = self.rest_handler.get_all_alerts(page_number)
if not alert_list:
alert_list = self.rest_handler.get_all_alerts_without_state(
page_number)
if alert_list is None:
break
if 'entries' not in alert_list:
break
if len(alert_list['entries']) < 1:
Expand Down Expand Up @@ -232,7 +241,7 @@ def get_eth_ports(self):
port_list = []
ports = self.rest_handler.get_all_ethports()
ip_interfaces = self.rest_handler.get_port_interface()
if ports is not None:
if ports:
port_entries = ports.get('entries')
for port in port_entries:
content = port.get('content')
Expand All @@ -250,22 +259,23 @@ def get_eth_ports(self):
ipv4_mask = None
ipv6 = None
ipv6_mask = None
for ip_info in ip_interfaces.get('entries'):
ip_content = ip_info.get('content')
if not ip_content:
continue
if content.get('id') == ip_content.get(
'ipPort').get('id'):
if ip_content.get('ipProtocolVersion') == 4:
ipv4 = UnityStorDriver.handle_port_ip(
ipv4, ip_content.get('ipAddress'))
ipv4_mask = UnityStorDriver.handle_port_ip(
ipv4_mask, ip_content.get('netmask'))
else:
ipv6 = UnityStorDriver.handle_port_ip(
ipv6, ip_content.get('ipAddress'))
ipv6_mask = UnityStorDriver.handle_port_ip(
ipv6_mask, ip_content.get('netmask'))
if ip_interfaces:
for ip_info in ip_interfaces.get('entries'):
ip_content = ip_info.get('content')
if not ip_content:
continue
if content.get('id') == ip_content.get(
'ipPort').get('id'):
if ip_content.get('ipProtocolVersion') == 4:
ipv4 = UnityStorDriver.handle_port_ip(
ipv4, ip_content.get('ipAddress'))
ipv4_mask = UnityStorDriver.handle_port_ip(
ipv4_mask, ip_content.get('netmask'))
else:
ipv6 = UnityStorDriver.handle_port_ip(
ipv6, ip_content.get('ipAddress'))
ipv6_mask = UnityStorDriver.handle_port_ip(
ipv6_mask, ip_content.get('netmask'))
port_result = {
'name': content.get('name'),
'storage_id': self.storage_id,
Expand All @@ -275,7 +285,8 @@ def get_eth_ports(self):
'health_status': status,
'type': constants.PortType.ETH,
'logical_type': '',
'max_speed': int(content.get('speed')) * units.Mi,
'speed': int(content.get('speed')) * units.M,
'max_speed': int(content.get('speed')) * units.M,
'native_parent_id':
content.get('storageProcessor', {}).get('id'),
'wwn': '',
Expand All @@ -291,28 +302,38 @@ def get_eth_ports(self):
def get_fc_ports(self):
port_list = []
ports = self.rest_handler.get_all_fcports()
if ports is not None:
if ports:
port_entries = ports.get('entries')
for port in port_entries:
content = port.get('content')
if not content:
continue
health_value = content.get('health', {}).get('value')
connect_value = \
content.get('health', {}).get('descriptionIds', [])
if 'ALRT_PORT_LINK_DOWN_NOT_IN_USE' in connect_value:
conn_status = constants.PortConnectionStatus.DISCONNECTED
elif 'ALRT_PORT_LINK_UP' in connect_value:
conn_status = constants.PortConnectionStatus.CONNECTED
else:
conn_status = constants.PortConnectionStatus.UNKNOWN
if health_value in UnityStorDriver.HEALTH_OK:
status = constants.PortHealthStatus.NORMAL
else:
status = constants.PortHealthStatus.ABNORMAL
conn_status = status
port_result = {
'name': content.get('name'),
'storage_id': self.storage_id,
'native_port_id': content.get('id'),
'location': content.get('slotNumber'),
'location': content.get('name'),
'connection_status': conn_status,
'health_status': status,
'type': constants.PortType.FC,
'logical_type': '',
'max_speed': int(content.get('currentSpeed')) * units.Gi,
'speed': int(
content.get('currentSpeed', 0)) * units.G,
'max_speed': int(
content.get('currentSpeed', 0)) * units.G,
'native_parent_id':
content.get('storageProcessor', {}).get('id'),
'wwn': content.get('wwn')
Expand Down Expand Up @@ -361,7 +382,7 @@ def list_disks(self, context):
'logical_type': '',
'native_disk_group_id':
content.get('diskGroup', {}).get('id'),
'location': content.get('slotNumber')
'location': content.get('name')
}
disk_list.append(disk_result)
return disk_list
Expand All @@ -374,6 +395,8 @@ def list_disks(self, context):
def list_filesystems(self, context):
try:
files = self.rest_handler.get_all_filesystems()
if not files:
files = self.rest_handler.get_all_filesystems_without_flr()
fs_list = []
if files is not None:
fs_entries = files.get('entries')
Expand Down Expand Up @@ -445,6 +468,8 @@ def list_qtrees(self, context):

def get_share_qtree(self, path, qtree_list):
qtree_id = None
if not qtree_list:
return qtree_id
qts_entries = qtree_list.get('entries')
for qtree in qts_entries:
content = qtree.get('content')
Expand All @@ -470,16 +495,17 @@ def get_share(self, protocol, qtree_list, filesystems):
content = share.get('content')
if not content:
continue
file_entries = filesystems.get('entries')
file_name = ''
for file in file_entries:
file_content = file.get('content')
if not file_content:
continue
if file_content.get('id') == content.get(
'filesystem', {}).get('id'):
file_name = file_content.get('name')
break
if filesystems:
file_entries = filesystems.get('entries')
for file in file_entries:
file_content = file.get('content')
if not file_content:
continue
if file_content.get('id') == content.get(
'filesystem', {}).get('id'):
file_name = file_content.get('name')
break
path = '/%s%s' % (file_name, content.get('path')) if \
file_name != '' else content.get('path')
fs = {
Expand All @@ -505,6 +531,9 @@ def list_shares(self, context):
share_list = []
qtrees = self.rest_handler.get_all_qtrees()
filesystems = self.rest_handler.get_all_filesystems()
if not filesystems:
filesystems = \
self.rest_handler.get_all_filesystems_without_flr()
share_list.extend(self.get_share('cifs', qtrees, filesystems))
share_list.extend(self.get_share('nfs', qtrees, filesystems))
return share_list
Expand Down
Loading