Esempio n. 1
0
 def __init__(self, tenant_id, resource, hard_limit,
              id=utils.generate_uuid(), created=utils.utcnow(),
              update=utils.utcnow()):
     self.tenant_id = tenant_id
     self.resource = resource
     self.hard_limit = hard_limit
     self.id = id
     self.created = created
     self.update = update
Esempio n. 2
0
    def delete(self):
        self['updated'] = utils.utcnow()
        LOG.debug(_("Deleting %s: %s") %
                  (self.__class__.__name__, self.__dict__))

        if self.preserve_on_delete:
            self['deleted_at'] = utils.utcnow()
            self['deleted'] = True
            return self.db_api.save(self)
        else:
            return self.db_api.delete(self)
Esempio n. 3
0
 def save(self):
     if not self.is_valid():
         raise exception.InvalidModelError(errors=self.errors)
     self['updated'] = utils.utcnow()
     LOG.debug(_("Saving %s: %s") %
               (self.__class__.__name__, self.__dict__))
     return self.db_api.save(self)
Esempio n. 4
0
 def create(cls, **values):
     values['id'] = utils.generate_uuid()
     values['created'] = utils.utcnow()
     instance = cls(**values).save()
     if not instance.is_valid():
         raise exception.InvalidModelError(errors=instance.errors)
     return instance
Esempio n. 5
0
    def save(self):
        if not self.is_valid():
            raise InvalidModelError(self.errors)
#        self._convert_columns_to_proper_type()
#        self._before_save()
        self['updated_at'] = utils.utcnow()
        LOG.debug("Saving %s: %s" % (self.__class__.__name__, self.__dict__))
        return db.db_api.save(self)
Esempio n. 6
0
 def setUp(self):
     super(BackupORMTest, self).setUp()
     util.init_db()
     self.context, self.instance_id = _prep_conf(utils.utcnow())
     models.DBBackup.create(tenant_id=self.context.tenant,
                            name=BACKUP_NAME,
                            state=BACKUP_STATE,
                            instance_id=self.instance_id,
                            deleted=False)
     self.deleted = False
Esempio n. 7
0
 def create(cls, **values):
     if 'id' not in values:
         values['id'] = utils.generate_uuid()
     if hasattr(cls, 'deleted') and 'deleted' not in values:
         values['deleted'] = False
     values['created'] = utils.utcnow()
     instance = cls(**values).save()
     if not instance.is_valid():
         raise exception.InvalidModelError(errors=instance.errors)
     return instance
    def mock_out_client(self):
        """Stubs out a fake server returned from novaclient.
           This is akin to calling Client.servers.get(uuid)
           and getting the server object back."""
        self.FAKE_SERVER = self.mock.CreateMock(object)
        self.FAKE_SERVER.name = self.expected_name
        self.FAKE_SERVER.status = 'ACTIVE'
        self.FAKE_SERVER.updated = utils.utcnow()
        self.FAKE_SERVER.created = utils.utcnow()
        self.FAKE_SERVER.id = self.expected_id
        self.FAKE_SERVER.flavor = ('http://localhost/1234/flavors/',
                                   '52415800-8b69-11e0-9b19-734f1195ff37')
        self.FAKE_SERVER.links = [
            {
                "href": "http://localhost/1234/instances/123",
                "rel": "self",
            },
            {
                "href": "http://localhost/1234/instances/123",
                "rel": "bookmark",
            },
        ]
        self.FAKE_SERVER.addresses = {
            "private": [
                {
                    "addr": "10.0.0.4",
                    "version": 4
                },
            ],
        }

        client = self.mock.CreateMock(novaclient.v1_1.Client)
        servers = self.mock.CreateMock(novaclient.v1_1.servers.ServerManager)
        servers.get(mox.IgnoreArg()).AndReturn(self.FAKE_SERVER)
        client.servers = servers
        self.mock.StubOutWithMock(models.NovaRemoteModelBase, 'get_client')
        models.NovaRemoteModelBase.get_client(mox.IgnoreArg()). \
            AndReturn(client)
        self.mock.ReplayAll()
    def mock_out_client_create(self):
        """Stubs out a fake server returned from novaclient.
           This is akin to calling Client.servers.get(uuid)
           and getting the server object back."""
        self.FAKE_SERVER = self.mock.CreateMock(object)
        self.FAKE_SERVER.name = 'my_name'
        self.FAKE_SERVER.status = 'ACTIVE'
        self.FAKE_SERVER.updated = utils.utcnow()
        self.FAKE_SERVER.created = utils.utcnow()
        self.FAKE_SERVER.id = utils.generate_uuid()
        self.FAKE_SERVER.flavor = 'http://localhost/1234/flavors/1234'
        self.FAKE_SERVER.links = [{
                    "href": "http://localhost/1234/instances/123",
                    "rel": "self"
                },
                {
                    "href": "http://localhost/1234/instances/123",
                    "rel": "bookmark"
                }]
        self.FAKE_SERVER.addresses = {
                "private": [
                    {
                        "addr": "10.0.0.4",
                        "version": 4
                    }
                ]
            }

        client = self.mock.CreateMock(novaclient.v1_1.Client)
        servers = self.mock.CreateMock(novaclient.v1_1.servers.ServerManager)
        servers.create(mox.IgnoreArg(),
                       mox.IgnoreArg(),
                       mox.IgnoreArg()).AndReturn(self.FAKE_SERVER)
        client.servers = servers
        self.mock.StubOutWithMock(models.NovaRemoteModelBase, 'get_client')
        models.NovaRemoteModelBase.get_client(mox.IgnoreArg()). \
            AndReturn(client)
Esempio n. 10
0
 def delete(cls, id):
     """
     update Backup table on deleted flag for given Backup
     :param cls:
     :param id: Backup uuid
     :return:
     """
     #TODO: api (service.py) might take care of actual deletion
     # on remote swift
     try:
         db_info = DBBackup.find_by(id=id, deleted=False)
         db_info.update(deleted=True, deleted_at=utils.utcnow())
     except exception.NotFound:
         raise exception.NotFound(uuid=id)
     except exception.ReddwarfError as ex:
         LOG.exception("Backup record cannot be updated for "
                       "backup: %s", id)
         raise exception.BackupUpdateError(str(ex))
Esempio n. 11
0
 def __init__(self, instance_id, user):
     self.id = instance_id
     self.user = user
     self.created = utils.utcnow()
Esempio n. 12
0
 def update(self, **values):
     for key in values:
         if hasattr(self, key):
             setattr(self, key, values[key])
     self['updated'] = utils.utcnow()
     return self.db_api.save(self)
Esempio n. 13
0
 def delete(self):
     self['updated'] = utils.utcnow()
     LOG.debug(_("Deleting %s: %s") %
               (self.__class__.__name__, self.__dict__))
     return self.db_api.delete(self)
Esempio n. 14
0
 def setUp(self):
     super(BackupCreateTest, self).setUp()
     util.init_db()
     self.context, self.instance_id = _prep_conf(utils.utcnow())
     self.created = False