Example #1
0
def qcs_trgt_set_chap(trgt_iqn, chap_opts):
    enable = 0
    if chap_opts['enable'] or chap_opts['mutual_enable'] == 1: #at least 1 enable
        enable = 1
    # enable auth
    cmd = TRGT_CHAP_CTRL%(trgt_iqn, enable)
    ret = cmd_utils(cmd).check_output()
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_trgt_set_chap:%s"%(ret['return_code'], cmd))
    # set userid
    cmd = TRGT_SET_CHAP%(trgt_iqn, "userid", chap_opts['userid']) 
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_trgt_set_chap:%s"%(ret['return_code'], cmd))
    ret = cmd_utils(cmd).check_output()
    # set password
    cmd = TRGT_SET_CHAP%(trgt_iqn, "password", chap_opts['password']) 
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_trgt_set_chap:%s"%(ret['return_code'], cmd))
    ret = cmd_utils(cmd).check_output()
    # set mutual_userid
    cmd = TRGT_SET_CHAP%(trgt_iqn, "mutual_userid", chap_opts['mutual_userid']) 
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_trgt_set_chap:%s"%(ret['return_code'], cmd))
    ret = cmd_utils(cmd).check_output()
    # set mutual_password
    cmd = TRGT_SET_CHAP%(trgt_iqn, "mutual_password", chap_opts['mutual_password']) 
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_trgt_set_chap:%s"%(ret['return_code'], cmd))
    ret = cmd_utils(cmd).check_output()
    return ret['return_code']
Example #2
0
def qcs_create_target(trgt_iqn):
    cmd = CREATE_TRGT%(trgt_iqn)
    ret = cmd_utils(cmd).check_output()
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_create_target:%s"%(ret['return_code'], cmd))
    # add network portal
    ip = qcs_get_vm_host_ip()
    cmd = ADD_TRGT_NP%(trgt_iqn, ip, "3260")
    ret = cmd_utils(cmd).check_output()
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_create_target:%s"%(ret['return_code'], cmd))
    return ret['return_code']
Example #3
0
def qcs_trgt_set_crc(trgt_iqn, crc_opts):
    # Set DataDigest
    if crc_opts['data_digest'] is 1:
        cmd = TRGT_SET_CRC%(trgt_iqn, "DataDigest", "CRC32C")
    else:
        cmd = TRGT_SET_CRC%(trgt_iqn, "DataDigest", "CRC32C,None")
    ret = cmd_utils(cmd).check_output()
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_trgt_set_crc:%s"%(ret['return_code'], cmd))
    # Set HeaderDigest
    if crc_opts['header_digest'] is 1:
        cmd = TRGT_SET_CRC%(trgt_iqn, "HeaderDigest", "CRC32C")
    else:
        cmd = TRGT_SET_CRC%(trgt_iqn, "HeaderDigest", "CRC32C,None")
    ret = cmd_utils(cmd).check_output()
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_trgt_set_crc:%s"%(ret['return_code'], cmd))
    return ret['return_code']
Example #4
0
 def _qcs_unmap_rbd_from_device(self, pool_name, lun_name):
     cmd = self.RBD_UNMAP_DEVICE %(pool_name, lun_name, pool_name, pool_name) 
     ret = cmd_utils(cmd).check_output()
     ERR_TRACE(TRACE_ENTRY, "ret:%d _qcs_unmap_rbd_from_device:%s"%(ret['return_code'], cmd))
     if ret['return_code'] is not 0:
         ERR_TRACE(TRACE_ERROR, "_qcs_unmap_rbd_from_device: unmap %s fail."%(lun_name))
     return ret['return_code']
Example #5
0
def qcs_resize_lun(pool, lun_name, disk_size):
    HOST_LUN_CONFIG = qcs_get_host_lun_conf(pool)
    data = qcs_get_disk_data(HOST_LUN_CONFIG)
    image_name = data[lun_name]['image_name']
    cmd = RBD_RESIZE_IMAGE %(pool, image_name, disk_size)
    ret = cmd_utils(cmd).check_output()
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_resize_lun:%s"%(ret['return_code'], cmd))
    if ret['return_code'] is 0:
        ERR_TRACE(TRACE_ENTRY, "qcs_resize_lun:%s resize %s to %s "%(lun_name, data[lun_name]['size'], disk_size))
        data[lun_name]['size'] = disk_size
        ret = JSON_CONF(HOST_LUN_CONFIG).JSON_Write_Conf(data)
    return ret
Example #6
0
def qcs_add_init(trgt_iqn, init_iqn):
    cmd = ADD_INIT%(trgt_iqn, init_iqn)
    ret = cmd_utils(cmd).check_output()
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_add_init:%s"%(ret['return_code'], cmd))
    # After adding init, must check chap and chap_mutual
    enable, chap = get_target_chap(trgt_iqn)
    if enable:
        # set userid
        cmd = INIT_SET_CHAP%(trgt_iqn, init_iqn, "userid", chap['userid'])
        ret = cmd_utils(cmd).check_output()
        # set password
        cmd = INIT_SET_CHAP%(trgt_iqn, init_iqn, "password", chap['password'])
        ret = cmd_utils(cmd).check_output()
        # set mutual_userid
        cmd = INIT_SET_CHAP%(trgt_iqn, init_iqn, "mutual_userid", chap['mutual_userid'])
        ret = cmd_utils(cmd).check_output()
        # set mutual_password
        cmd = INIT_SET_CHAP%(trgt_iqn, init_iqn, "mutual_password", chap['mutual_password'])
        ret = cmd_utils(cmd).check_output()
    # disable do nothing
    ERR_TRACE(TRACE_ENTRY, "qcs_add_init:chap enable=%d"%(enable))
    return ret['return_code']
Example #7
0
def get_target_chap(trgt_iqn):
    cmd = TRGT_CHAP_STATUS%(trgt_iqn)
    ret = cmd_utils(cmd).check_output()
    enable = 1 if ret['json_output'][0]['raw_data'].split('=')[1] is '1' else 0
    dic = {}
    if enable: #get auth value
        # get userid
        cmd = TRGT_GET_CHAP%(trgt_iqn, "userid")
        ret = cmd_utils(cmd).check_output()
        userid = ret['json_output'][0]['raw_data'].split('=')[1]
        # get password
        cmd = TRGT_GET_CHAP%(trgt_iqn, "password")
        ret = cmd_utils(cmd).check_output()
        password = ret['json_output'][0]['raw_data'].split('=')[1]
        # get mutual_userid
        cmd = TRGT_GET_CHAP%(trgt_iqn, "mutual_userid")
        ret = cmd_utils(cmd).check_output()
        mutual_userid = ret['json_output'][0]['raw_data'].split('=')[1]
        # get mutual_password
        cmd = TRGT_GET_CHAP%(trgt_iqn, "mutual_password")
        ret = cmd_utils(cmd).check_output()
        mutual_password = ret['json_output'][0]['raw_data'].split('=')[1]
        dic = {'userid': userid, 'password': password, 'mutual_userid': mutual_userid, 'mutual_password': mutual_password}
    return enable, dic
Example #8
0
 def qcs_check_image_exist(self, pool_name, lun_name):
     cmd = self.RBD_GET_INFO %(pool_name, lun_name, pool_name, pool_name) 
     ret = cmd_utils(cmd).check_output()
     return ret['return_code']
Example #9
0
def qcs_get_ceph_root():
    cmd = "mount | grep CEPH | grep -Ev bind | awk '{print $3}'"
    ret = cmd_utils(cmd).check_output()
    return ret['json_output'][0]['raw_data']
Example #10
0
def qcs_remove_init(trgt_iqn, init_iqn):
    cmd = REMOVE_INIT%(trgt_iqn, init_iqn)
    ret = cmd_utils(cmd).check_output()
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_remove_init:%s"%(ret['return_code'], cmd))
    return ret['return_code']
Example #11
0
def qcs_init_unlink_lun(trgt_iqn, init_iqn, lun_name):
    cmd = INIT_UNLINK_LUN%(trgt_iqn, init_iqn, lun_name['index'])
    ret = cmd_utils(cmd).check_output()
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_init_unlink_lun:%s"%(ret['return_code'], cmd))
    return ret['return_code']
Example #12
0
 def _qcs_remove_rbd_image(self, pool_name, lun_name):
     cmd = self.RBD_REMOVE_IMAGE %(pool_name, lun_name, pool_name, pool_name)
     ret = cmd_utils(cmd).check_output()
     ERR_TRACE(TRACE_ENTRY, "ret:%d _qcs_remove_rbd_image:%s"%(ret['return_code'], cmd))
     return ret['return_code']
Example #13
0
def qcs_unmap_lun_from_trgt(trgt_iqn, lun_name):
    cmd = TRGT_UNMAP_LUN%(trgt_iqn, lun_name['index'])
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_unmap_lun_from_trgt:%s"%(ret['return_code'], cmd))
    ret = cmd_utils(cmd).check_output()
    return ret['return_code']
Example #14
0
def qcs_map_lun_to_trgt(trgt_iqn, lun_name):
    cmd = TRGT_MAP_LUN%(trgt_iqn, lun_name['stor_object'], lun_name['index'])
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_map_lun_to_trgt:%s"%(ret['return_code'], cmd))
    ret = cmd_utils(cmd).check_output()
    return ret['return_code']
Example #15
0
def qcs_target_ctrl(trgt_iqn, enable):
    cmd = TRGT_CTRL%(trgt_iqn, "enable") if enable else TRGT_CTRL%(trgt_iqn, "disable")
    ret = cmd_utils(cmd).check_output()
    ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_target_ctrl:%s"%(ret['return_code'], cmd))
    return ret['return_code']
Example #16
0
 def _qcs_create_rbd_image(self, disk_size, pool_name, lun_name):
     cmd = self.RBD_CREATE_IMAGE %(disk_size, pool_name, lun_name, pool_name, pool_name)
     ret = cmd_utils(cmd).check_output()
     ERR_TRACE(TRACE_ENTRY, "ret:%d _qcs_create_rbd_image:%s"%(ret['return_code'], cmd))
     return ret['return_code']
Example #17
0
 def _qcs_map_rbd_to_device(pool_name, lun_name):
     cmd = self.RBD_MAP_DEVICE %(pool_name, lun_name, pool_name, pool_name)
     ret = cmd_utils(cmd).check_output()
     ERR_TRACE(TRACE_ENTRY, "ret:%d _qcs_map_rbd_to_device:%s dev:%s"%(ret['return_code'], cmd, ret['json_output'][0]['raw_data']))
     return ret['return_code'], ret['json_output'][0]['raw_data']
Example #18
0
def qcs_init_link_lun(trgt_iqn, init_iqn, lun_name, access):
    if access is not -1:
        cmd = INIT_LINK_LUN%(trgt_iqn, init_iqn, file_data[lun]['index'], file_data[lun]['index'], access)
        ret = cmd_utils(cmd).check_output()
        ERR_TRACE(TRACE_ENTRY, "ret:%d qcs_init_link_lun:%s"%(ret['return_code'], cmd))
    return ret['return_code']