# -*- coding:utf-8 -*-
"""
Function: get_sp_drive_erase.py moudle. This moudle mainly involves the
 querying the Hard Drive Erase Configuration Resources of
  the Smart Provisioning Service function.
Copyright Information: xFusion Digital Technologies Co.,
 Ltd. All Rights Reserved © 2019-2021
"""
from scripts import common_function

FORMAT = '%-30s: %s'


def getspdriveerase_init(parser, parser_dict):
    """
    Function Description:initializing the Command for
     querying the Hard Drive Erase Configuration
      Resources of the Smart Provisioning Service
    Parameter:parser object: action object
    parser_dict dict: dictionary format of subcommand and ArgumentParser
    Return Value: subcommand
    """
    sub_parser = parser.add_parser('getspdriveerasetask', help='''
    obtain Smart Provisioning hard drive erasing task config.''')

    parser_dict['getspdriveerasetask'] = sub_parser

    return 'getspdriveerasetask'


def getspdriveerase(client, _):
    """
    Function Description: Query the hard drive erase configuration
     resources of the Smart Provisioning service.
    Parameter:client redfishClient
    Return Value: resp dict:result of the redfish interface
    """
    slotid = client.get_slotid()
    if slotid is None:
        return None
    url = "/redfish/v1/Managers/%s/SPService/SPDriveErase/1" % slotid
    resp = client.get_resource(url)
    if resp is None:
        return None
    if resp['status_code'] == 200:
        print_result(resp)
    else:
        common_function.get_error_info(resp)

    return resp


def print_result(resp):
    """
    功能描述：打印 请求结果
    参数：resp (dict):redfish 接口返回值
    返回值：None
    异常描述：None
    修改：None
    """
    info = resp.get('resource', None)
    if info is None:
        print('No data is available for the resource.')
        return
    driveerase_dic = info.get("DriveErase", None)
    if not driveerase_dic:
        print('No data is available for the resource.')
        return
    print(FORMAT % ("EraseMode", driveerase_dic.get("EraseMode", None)))
    print(FORMAT %
          ("EraseStrategy", driveerase_dic.get("EraseStrategy", None)))
    print("-" * 40)
