Esempio n. 1
0
 def _uuid_check(self, gid=None, network_id=None):
     if gid:
         if not uuidutils.is_uuid_like(gid):
             raise exception.GroupNotFound(gid=gid)
     if network_id:
         if not uuidutils.is_uuid_like(network_id):
             raise exception.NetworkNotFound(network_id=network_id)
Esempio n. 2
0
 def _uuid_check(self, gid=None, keypair_id=None):
     if gid:
         if not uuidutils.is_uuid_like(gid):
             raise exception.GroupNotFound(gid=gid)
     if keypair_id:
         if not uuidutils.is_uuid_like(keypair_id):
             raise exception.KeypairNotFound(keypair_id=keypair_id)
Esempio n. 3
0
File: api.py Progetto: yanyuge/rack
def group_get_by_gid(context, gid):
    session = get_session()
    group = session.query(models.Group)\
        .filter_by(user_id=context.user_id)\
        .filter_by(gid=gid)\
        .filter_by(deleted=0)\
        .first()

    if not group:
        raise exception.GroupNotFound(gid=gid)
    return dict(group)
Esempio n. 4
0
File: api.py Progetto: yanyuge/rack
def group_update(context, values):
    session = get_session()
    group_ref = session.query(models.Group). \
        filter(models.Group.gid == values["gid"]).first()
    if group_ref is None:
        raise exception.GroupNotFound(gid=values["gid"])

    group_ref.update(values)
    group_ref.save(session)

    return dict(group_ref)
Esempio n. 5
0
    def test_create_exception_HTTPNotFound_gid_not_found(self):
        self.mox.StubOutWithMock(db, "group_get_by_gid")
        db.group_get_by_gid(IsA(context.RequestContext),
                            GID)\
            .AndRaise(exception.GroupNotFound(gid=GID))
        self.mox.ReplayAll()
        name = "test_securitygroup"
        request_body = {"securitygroup": {"name": name, "is_default": "true"}}

        url = get_base_url(GID)
        req = get_request(url, 'POST', request_body)
        res = req.get_response(self.app)

        self.assertEqual(res.status_code, 404)
Esempio n. 6
0
    def test_create_raise_exception_by_db_keypair_create(self):
        self.mox.StubOutWithMock(db, "group_get_by_gid")
        db.group_get_by_gid(IsA(context.RequestContext), GID)\
            .AndRaise(exception.GroupNotFound(gid=GID))
        self.mox.ReplayAll()

        request_body = {
            "keypair": {
                "name": "test_key",
            }
        }
        url = '/v1/groups/' + GID + '/keypairs'
        req = get_request(url, 'POST', request_body)
        res = req.get_response(self.app)
        self.assertEqual(res.status_code, 404)
Esempio n. 7
0
File: api.py Progetto: yanyuge/rack
def group_delete(context, gid):
    session = get_session()
    group_ref = session.query(models.Group)\
        .filter_by(deleted=0)\
        .filter_by(gid=gid)\
        .first()
    if group_ref is None:
        raise exception.GroupNotFound(gid=gid)

    values = {
        "status": "DELETING",
        "deleted": 1,
        "deleted_at": timeutils.utcnow()
    }
    group_ref.update(values)
    group_ref.save(session)

    return dict(group_ref)
Esempio n. 8
0
 def _uuid_check(self,
                 gid=None,
                 pid=None,
                 keypair_id=None,
                 securitygroup_id=None):
     if gid:
         if not uuidutils.is_uuid_like(gid):
             raise exception.GroupNotFound(gid=gid)
     if pid:
         if not uuidutils.is_uuid_like(pid):
             raise exception.ProcessNotFound(pid=pid)
     if keypair_id:
         if not uuidutils.is_uuid_like(keypair_id):
             raise exception.KeypairNotFound(keypair_id=keypair_id)
     if securitygroup_id:
         if not uuidutils.is_uuid_like(securitygroup_id):
             raise exception.SecuritygroupNotFound(
                 securitygroup_id=securitygroup_id)
Esempio n. 9
0
    def test_create_validate_exception_by_gid_notfound(self):
        self.mox.StubOutWithMock(db, "group_get_by_gid")
        db.group_get_by_gid(IsA(context.RequestContext),
                            GID).AndRaise(exception.GroupNotFound(gid=GID))
        self.mox.ReplayAll()

        request_body = {
            "network": {
                "name": "test_network",
                "is_admin": "True",
                "cidr": "10.0.0.0/24",
                "gateway": "10.0.0.254",
                "dns_nameservers": ["8.8.8.8", "8.8.4.4"],
                "ext_router_id": "91212048-abc3-43cc-89b3-377341426aca"
            }
        }
        url = '/v1/groups/' + GID + '/networks'
        req = get_request(url, 'POST', request_body)
        res = req.get_response(self.app)
        self.assertEqual(res.status_code, 404)
Esempio n. 10
0
        def _validate(body, gid):
            if not self.is_valid_body(body, 'group'):
                msg = _("Invalid request body")
                raise exception.InvalidInput(reason=msg)

            values = body["group"]
            name = values.get("name")
            description = values.get("description")

            if not uuidutils.is_uuid_like(gid):
                raise exception.GroupNotFound(gid=gid)

            if name is None and description is None:
                msg = _("Group name or description is required")
                raise exception.InvalidInput(reason=msg)

            if name is not None:
                if isinstance(name, six.string_types):
                    name = name.strip()
                utils.check_string_length(name,
                                          'name',
                                          min_length=1,
                                          max_length=255)

            if description is not None:
                utils.check_string_length(description,
                                          'description',
                                          min_length=0,
                                          max_length=255)

            valid_values = {}
            if name:
                valid_values["display_name"] = name
            # allow blank string to clear description
            if description is not None:
                valid_values["display_description"] = description
            valid_values["gid"] = gid
            return valid_values
Esempio n. 11
0
 def _validate(gid):
     if not uuidutils.is_uuid_like(gid):
         raise exception.GroupNotFound(gid=gid)
Esempio n. 12
0
def raise_group_not_found(context, kwargs):
    raise exception.GroupNotFound(gid=GID)