Пример #1
0
def _validate_security_group(security_group):
    if "name" in security_group:
        if len(security_group["name"]) > GROUP_NAME_MAX_LENGTH:
            raise n_exc.InvalidInput(
                error_message="Group name must be 255 characters or less")

        if security_group["name"] == "default":
            raise sg_ext.SecurityGroupDefaultAlreadyExists()

    if ("description" in security_group and
            len(security_group["description"]) > GROUP_DESCRIPTION_MAX_LENGTH):
        raise n_exc.InvalidInput(
            error_message="Group description must be 255 characters or less")
Пример #2
0
def create_security_group(context, security_group):
    LOG.info("create_security_group for tenant %s" % (context.tenant_id))
    group = security_group["security_group"]
    group_name = group.get('name', '')
    if group_name == "default":
        raise sg_ext.SecurityGroupDefaultAlreadyExists()
    group_id = uuidutils.generate_uuid()

    with context.session.begin():
        group["id"] = group_id
        group["name"] = group_name
        group["tenant_id"] = context.tenant_id
        dbgroup = db_api.security_group_create(context, **group)
    return v._make_security_group_dict(dbgroup)