Exemplo n.º 1
0
def chkopts(opts):
    reg = re.compile("[^a-zA-Z0-9\./_:-]")

    if opts.name:
        if reg.search(opts.name):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-n or --name', opts.name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' %
                                     '-n or --name')

    if opts.type:
        if opts.type not in STORAGE_POOL_TYPE.values():
            raise KssCommandOptException(
                'ERROR: Type is not available. type=%s' % opts.type)
    else:
        raise KssCommandOptException('ERROR: %s option is required.' %
                                     '-t or --type')

    if opts.type == STORAGE_POOL_TYPE["TYPE_DIR"]:
        # type:dir
        if not opts.target_path:
            raise KssCommandOptException('ERROR: %s option is required.' %
                                         '-p or --target_path')

    elif opts.type == STORAGE_POOL_TYPE["TYPE_ISCSI"]:
        # type:iscsi
        if not opts.host_name:
            raise KssCommandOptException('ERROR: %s option is required.' %
                                         '-b or --host_name')
        if not opts.device_path:
            raise KssCommandOptException('ERROR: %s option is required.' %
                                         '-d or --device_path')

    elif opts.type == STORAGE_POOL_TYPE["TYPE_FS"]:
        # type:fs
        if not opts.target_path:
            raise KssCommandOptException('ERROR: %s option is required.' %
                                         '-p or --target_path')
        if not opts.device_path:
            raise KssCommandOptException('ERROR: %s option is required.' %
                                         '-d or --device_path')

    else:
        raise KssCommandOptException(
            'ERROR: The type that does not exist. type=%s' % opts.type)

    if opts.label:
        if reg.search(opts.label):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-l or --label', opts.label))

    reg = re.compile("[^0-9]")
    if opts.owner:
        if reg.search(opts.owner):
            if opts.owner not in [user[0] for user in get_pwd_info()]:
                raise KssCommandOptException(
                    'ERROR: Permission user not found. owner=%s' %
                    (opts.owner))
        else:
            if int(opts.owner) not in [user[2] for user in get_pwd_info()]:
                raise KssCommandOptException(
                    'ERROR: Permission user not found. owner=%s' %
                    (opts.owner))

    if opts.group:
        if reg.search(opts.group):
            if opts.group not in [group[0] for group in get_grp_info()]:
                raise KssCommandOptException(
                    'ERROR: Permission user not found. group=%s' %
                    (opts.group))
        else:
            if int(opts.group) not in [group[2] for group in get_grp_info()]:
                raise KssCommandOptException(
                    'ERROR: Permission user not found. group=%s' %
                    (opts.group))

    reg = re.compile("^[0-9]{3,4}$")
    if opts.mode:
        if not reg.match(opts.mode):
            raise KssCommandOptException(
                'ERROR: Illigal permission mode. mode=%s' % (opts.mode))
Exemplo n.º 2
0
def chkopts(opts):
    reg = re.compile("[^a-zA-Z0-9\./_:-]")

    if opts.name:
        if reg.search(opts.name):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-n or --name', opts.name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name')

    if opts.pool_name:
        if reg.search(opts.pool_name):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-p or --pool_name', opts.pool_name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-p or --pool_name')

    if opts.volume_name:
        if reg.search(opts.pool_name):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-p or --pool_name', opts.pool_name))

    if opts.format:
        if reg.search(opts.format):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-f or --format', opts.format))

        if opts.format not in STORAGE_VOLUME_FORMAT.values():
            raise KssCommandOptException('ERROR: Format is not available. '
                                         'raw or qcow2... is available. format=%s' % opts.format)
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-f or format')

    if opts.unit:
        if opts.unit not in STORAGE_VOLUME_UNIT.keys():
            raise KssCommandOptException('ERROR: Volume size unit is not available. '
                                         'K or M... is available. unit=%s' % opts.unit)

    reg = re.compile("[^0-9]")
    if opts.permission_owner:
        if reg.search(opts.permission_owner):
            if opts.permission_owner not in [user[0] for user in get_pwd_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. owner=%s' % (opts.permission_owner))
        else:
            if int(opts.permission_owner) not in [user[2] for user in get_pwd_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. owner=%s' % (opts.permission_owner))

    if opts.permission_group:
        if reg.search(opts.permission_group):
            if opts.permission_group not in [group[0] for group in get_grp_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. group=%s' % (opts.permission_group))
        else:
            if int(opts.permission_group) not in [group[2] for group in get_grp_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. group=%s' % (opts.permission_group))

    reg = re.compile("^[0-9]{3,4}$")
    if opts.permission_mode:
        if not reg.match(opts.permission_mode):
            raise KssCommandOptException('ERROR: Illigal permission mode. mode=%s' % (opts.permission_mode))

    if opts.use:
        if opts.use not in DISK_USES.values():
            raise KssCommandOptException('ERROR: Disk usage is not available. '
                                         'images or disk is available. use=%s' % opts.use)

        if opts.use == DISK_USES["IMAGES"]:
            if not opts.volume_name:
                raise KssCommandOptException('ERROR: %s option is required.' % '-v or --volume_name')
Exemplo n.º 3
0
def chkopts(opts):
    reg = re.compile("[^a-zA-Z0-9\./_:-]")

    if opts.name:
        if reg.search(opts.name):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-n or --name', opts.name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name')

    if opts.type:
        if opts.type not in STORAGE_POOL_TYPE.values():
            raise KssCommandOptException('ERROR: Type is not available. type=%s' % opts.type)
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-t or --type')

    if opts.type == STORAGE_POOL_TYPE["TYPE_DIR"]:
        # type:dir
        if not opts.target_path:
            raise KssCommandOptException('ERROR: %s option is required.' % '-p or --target_path')

    elif opts.type == STORAGE_POOL_TYPE["TYPE_ISCSI"]:
        # type:iscsi
        if not opts.host_name:
            raise KssCommandOptException('ERROR: %s option is required.' % '-b or --host_name')
        if not opts.device_path:
            raise KssCommandOptException('ERROR: %s option is required.' % '-d or --device_path')

    elif opts.type == STORAGE_POOL_TYPE["TYPE_FS"]:
        # type:fs
        if not opts.target_path:
            raise KssCommandOptException('ERROR: %s option is required.' % '-p or --target_path')
        if not opts.device_path:
            raise KssCommandOptException('ERROR: %s option is required.' % '-d or --device_path')

    else:
        raise KssCommandOptException('ERROR: The type that does not exist. type=%s' % opts.type)

    if opts.label:
        if reg.search(opts.label):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-l or --label', opts.label))

    reg = re.compile("[^0-9]")
    if opts.owner:
        if reg.search(opts.owner):
            if opts.owner not in [user[0] for user in get_pwd_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. owner=%s' % (opts.owner))
        else:
            if int(opts.owner) not in [user[2] for user in get_pwd_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. owner=%s' % (opts.owner))

    if opts.group:
        if reg.search(opts.group):
            if opts.group not in [group[0] for group in get_grp_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. group=%s' % (opts.group))
        else:
            if int(opts.group) not in [group[2] for group in get_grp_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. group=%s' % (opts.group))

    reg = re.compile("^[0-9]{3,4}$")
    if opts.mode:
        if not reg.match(opts.mode):
            raise KssCommandOptException('ERROR: Illigal permission mode. mode=%s' % (opts.mode))
Exemplo n.º 4
0
def chkopts(opts):
    reg = re.compile("[^a-zA-Z0-9\./_:-]")

    if opts.name:
        if reg.search(opts.name):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-n or --name', opts.name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name')

    if opts.pool_name:
        if reg.search(opts.pool_name):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-p or --pool_name', opts.pool_name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-p or --pool_name')

    if opts.volume_name:
        if reg.search(opts.pool_name):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-p or --pool_name', opts.pool_name))

    if opts.format:
        if reg.search(opts.format):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-f or --format', opts.format))

        if opts.format not in STORAGE_VOLUME_FORMAT.values():
            raise KssCommandOptException('ERROR: Format is not available. '
                                         'raw or qcow2... is available. format=%s' % opts.format)
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-f or format')

    if opts.unit:
        if opts.unit not in STORAGE_VOLUME_UNIT.keys():
            raise KssCommandOptException('ERROR: Volume size unit is not available. '
                                         'K or M... is available. unit=%s' % opts.unit)

    reg = re.compile("[^0-9]")
    if opts.permission_owner:
        if reg.search(opts.permission_owner):
            if opts.permission_owner not in [user[0] for user in get_pwd_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. owner=%s' % (opts.permission_owner))
        else:
            if int(opts.permission_owner) not in [user[2] for user in get_pwd_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. owner=%s' % (opts.permission_owner))

    if opts.permission_group:
        if reg.search(opts.permission_group):
            if opts.permission_group not in [group[0] for group in get_grp_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. group=%s' % (opts.permission_group))
        else:
            if int(opts.permission_group) not in [group[2] for group in get_grp_info()]:
                raise KssCommandOptException('ERROR: Permission user not found. group=%s' % (opts.permission_group))

    reg = re.compile("^[0-9]{3,4}$")
    if opts.permission_mode:
        if not reg.match(opts.permission_mode):
            raise KssCommandOptException('ERROR: Illigal permission mode. mode=%s' % (opts.permission_mode))

    if opts.use:
        if opts.use not in DISK_USES.values():
            raise KssCommandOptException('ERROR: Disk usage is not available. '
                                         'images or disk is available. use=%s' % opts.use)

        if opts.use == DISK_USES["IMAGES"]:
            if not opts.volume_name:
                raise KssCommandOptException('ERROR: %s option is required.' % '-v or --volume_name')