• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.DBInstance类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中trove.instance.models.DBInstance的典型用法代码示例。如果您正苦于以下问题:Python DBInstance类的具体用法?Python DBInstance怎么用?Python DBInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DBInstance类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _add_shard_cluster

        def _add_shard_cluster():

            db_instances = DBInstance.find_all(cluster_id=cluster_id,
                                               shard_id=shard_id).all()
            instance_ids = [db_instance.id for db_instance in db_instances]
            LOG.debug("instances in shard %s: %s" % (shard_id,
                                                     instance_ids))
            if not self._all_instances_ready(instance_ids, cluster_id,
                                             shard_id):
                return

            members = [Instance.load(context, instance_id)
                       for instance_id in instance_ids]

            db_query_routers = DBInstance.find_all(cluster_id=cluster_id,
                                                   type='query_router',
                                                   deleted=False).all()
            query_routers = [Instance.load(context, db_query_router.id)
                             for db_query_router in db_query_routers]

            if not self._create_shard(query_routers[0], members):
                return

            for member in members:
                self.get_guest(member).cluster_complete()
开发者ID:Hopebaytech,项目名称:trove,代码行数:25,代码来源:taskmanager.py


示例2: test_show_deleted_mgmt_instances

    def test_show_deleted_mgmt_instances(self):
        args = {'deleted': 0, 'cluster_id': None}
        db_infos_active = DBInstance.find_all(**args)
        args = {'deleted': 1, 'cluster_id': None}
        db_infos_deleted = DBInstance.find_all(**args)
        args = {'cluster_id': None}
        # db_infos_all = DBInstance.find_all(**args)

        # TODO(SlickNik) Fix this assert to work reliably in the gate.
        # This fails intermittenly when the unit tests run in parallel.
        # self.assertTrue(db_infos_all.count() ==
        #                 db_infos_active.count() +
        #                 db_infos_deleted.count())

        with patch.object(self.context, 'is_admin', return_value=True):
            deleted_instance = db_infos_deleted.all()[0]
            active_instance = db_infos_active.all()[0]

            instance = DBInstance.find_by(context=self.context,
                                          id=active_instance.id)
            self.assertEqual(active_instance.id, instance.id)

            self.assertRaises(
                exception.ModelNotFoundError,
                DBInstance.find_by,
                context=self.context,
                id=deleted_instance.id,
                deleted=False)

            instance = DBInstance.find_by(context=self.context,
                                          id=deleted_instance.id,
                                          deleted=True)
            self.assertEqual(deleted_instance.id, instance.id)
开发者ID:ww102111,项目名称:trove,代码行数:33,代码来源:test_models.py


示例3: _run_query

def _run_query(start_date, end_date):
    created_filters = [DBInstance.created < end_date,
                       DBInstance.deleted == 0]
    created_columns = [DBInstance.created.label('timestamp'),
                       literal_column("0").label('deleted'),
                       DBDatastoreVersion.id.label('dsvid')]
    deleted_filters = [DBInstance.created < end_date,
                       DBInstance.deleted_at >= start_date,
                       DBInstance.deleted == 1]
    deleted_columns = [DBInstance.deleted_at.label('timestamp'),
                       literal_column("1").label('deleted'),
                       DBDatastoreVersion.id.label('dsvid')]

    query1 = DBInstance.query().\
        join(DBDatastoreVersion).\
        add_columns(*created_columns)
    query1 = query1.filter(*created_filters)

    query2 = DBInstance.query().\
        join(DBDatastoreVersion).\
        add_columns(*created_columns)
    query2 = query2.filter(*deleted_filters)

    query3 = DBInstance.query().\
        join(DBDatastoreVersion).\
        add_columns(*deleted_columns)
    query3 = query3.filter(*deleted_filters)

    union_query = query1.union(query2, query3).\
        order_by(text('anon_1.timestamp'))

    return union_query.all()
开发者ID:Tesora,项目名称:tesora-trove,代码行数:32,代码来源:usage_report.py


示例4: _get_cluster_instance_id

 def _get_cluster_instance_id(self, tenant_id, cluster_id):
     args = {'tenant_id': tenant_id, 'cluster_id': cluster_id}
     cluster_instances = DBInstance.find_all(**args).all()
     instance_ids = [db_instance.id for db_instance in cluster_instances]
     args = {'tenant_id': tenant_id, 'cluster_id': cluster_id, 'type':
             'master'}
     master_instance = DBInstance.find_by(**args)
     master_instance_id = master_instance.id
     return master_instance_id, instance_ids
开发者ID:pombredanne,项目名称:trove,代码行数:9,代码来源:service.py


示例5: setUp

 def setUp(self):
     super(SimpleInstanceTest, self).setUp()
     db_info = DBInstance(InstanceTasks.BUILDING, name="TestInstance")
     self.instance = SimpleInstance(None, db_info, "BUILD",
                                    ds_version=Mock(), ds=Mock())
     db_info.addresses = {"private": [{"addr": "123.123.123.123"}],
                          "internal": [{"addr": "10.123.123.123"}],
                          "public": [{"addr": "15.123.123.123"}]}
     self.orig_conf = CONF.network_label_regex
     self.orig_ip_regex = CONF.ip_regex
开发者ID:NeCTAR-RC,项目名称:trove,代码行数:10,代码来源:test_instance_models.py


示例6: build_db_instance

 def build_db_instance(self, status, task_status=InstanceTasks.NONE):
     version = datastore_models.DBDatastoreVersion.get_by(name='5.5')
     instance = DBInstance(InstanceTasks.NONE,
                           name='test_name',
                           id=str(uuid.uuid4()),
                           flavor_id='flavor_1',
                           datastore_version_id=
                           version.id,
                           compute_instance_id='compute_id_1',
                           server_id='server_id_1',
                           tenant_id='tenant_id_1',
                           server_status=
                           rd_instance.ServiceStatuses.
                           BUILDING.api_status,
                           deleted=False)
     instance.save()
     service_status = InstanceServiceStatus(
         rd_instance.ServiceStatuses.RUNNING,
         id=str(uuid.uuid4()),
         instance_id=instance.id,
     )
     service_status.save()
     instance.set_task_status(task_status)
     instance.server_status = status
     instance.save()
     return instance, service_status
开发者ID:AlexeyDeyneko,项目名称:trove,代码行数:26,代码来源:test_models.py


示例7: update_statuses_on_failure

    def update_statuses_on_failure(self, cluster_id, shard_id=None):

        if CONF.update_status_on_fail:
            if shard_id:
                db_instances = DBInstance.find_all(cluster_id=cluster_id,
                                                   shard_id=shard_id).all()
            else:
                db_instances = DBInstance.find_all(
                    cluster_id=cluster_id).all()

            for db_instance in db_instances:
                db_instance.set_task_status(
                    InstanceTasks.BUILDING_ERROR_SERVER)
                db_instance.save()
开发者ID:ShaguftaMethwani,项目名称:trove,代码行数:14,代码来源:taskmanager.py


示例8: setUp

 def setUp(self):
     super(SimpleInstanceTest, self).setUp()
     db_info = DBInstance(
         InstanceTasks.BUILDING, name="TestInstance")
     self.instance = SimpleInstance(
         None, db_info, InstanceServiceStatus(
             ServiceStatuses.BUILDING), ds_version=Mock(), ds=Mock(),
         locality='affinity')
     db_info.addresses = {"private": [{"addr": "123.123.123.123"}],
                          "internal": [{"addr": "10.123.123.123"}],
                          "public": [{"addr": "15.123.123.123"}]}
     self.orig_conf = CONF.network_label_regex
     self.orig_ip_regex = CONF.ip_regex
     self.orig_black_list_regex = CONF.black_list_regex
开发者ID:cdelatte,项目名称:tesora-trove,代码行数:14,代码来源:test_instance_models.py


示例9: _init

 def _init(self):
     self.mock = mox.Mox()
     self.instance_id = 500
     context = TroveContext()
     self.db_info = DBInstance.create(
         name="instance",
         flavor_id=OLD_FLAVOR_ID,
         tenant_id=999,
         volume_size=None,
         service_type='mysql',
         task_status=InstanceTasks.RESIZING)
     self.server = self.mock.CreateMock(Server)
     self.instance = models.BuiltInstanceTasks(context,
                                               self.db_info,
                                               self.server,
                                               service_status="ACTIVE")
     self.instance.server.flavor = {'id': OLD_FLAVOR_ID}
     self.guest = self.mock.CreateMock(guest.API)
     self.instance._guest = self.guest
     self.instance._refresh_compute_server_info = lambda: None
     self.instance._refresh_compute_service_status = lambda: None
     self.mock.StubOutWithMock(self.instance, 'update_db')
     self.mock.StubOutWithMock(self.instance,
                               '_set_service_status_to_paused')
     self.poll_until_mocked = False
     self.action = None
开发者ID:CiscoSystems,项目名称:openstack-trove,代码行数:26,代码来源:instances_resize.py


示例10: update_statuses_on_time_out

    def update_statuses_on_time_out(self):

        if CONF.update_status_on_fail:
            #Updating service status
            service = InstanceServiceStatus.find_by(instance_id=self.id)
            service.set_status(ServiceStatuses.
                               FAILED_TIMEOUT_GUESTAGENT)
            service.save()
            LOG.error(_("Service status: %(status)s") %
                      {'status': ServiceStatuses.
                       FAILED_TIMEOUT_GUESTAGENT.api_status})
            LOG.error(_("Service error description: %(desc)s") %
                      {'desc': ServiceStatuses.
                       FAILED_TIMEOUT_GUESTAGENT.description})
            #Updating instance status
            db_info = DBInstance.find_by(name=self.name)
            db_info.set_task_status(InstanceTasks.
                                    BUILDING_ERROR_TIMEOUT_GA)
            db_info.save()
            LOG.error(_("Trove instance status: %(action)s") %
                      {'action': InstanceTasks.
                       BUILDING_ERROR_TIMEOUT_GA.action})
            LOG.error(_("Trove instance status description: %(text)s") %
                      {'text': InstanceTasks.
                       BUILDING_ERROR_TIMEOUT_GA.db_text})
开发者ID:adamfokken,项目名称:trove,代码行数:25,代码来源:models.py


示例11: setUp

    def setUp(self):
        util.init_db()

        self.datastore = datastore_models.DBDatastore.create(
            id=str(uuid.uuid4()), name="name", default_version_id=str(uuid.uuid4())
        )

        self.datastore_version = datastore_models.DBDatastoreVersion.create(
            id=self.datastore.default_version_id,
            name="name",
            image_id=str(uuid.uuid4()),
            packages=str(uuid.uuid4()),
            datastore_id=self.datastore.id,
            manager="mysql",
            active=1,
        )

        self.master = DBInstance(
            InstanceTasks.NONE,
            id=str(uuid.uuid4()),
            name="TestMasterInstance",
            datastore_version_id=self.datastore_version.id,
        )
        self.master.set_task_status(InstanceTasks.NONE)
        self.master.save()
        self.master_status = InstanceServiceStatus(
            ServiceStatuses.RUNNING, id=str(uuid.uuid4()), instance_id=self.master.id
        )
        self.master_status.save()

        self.safe_nova_client = models.create_nova_client
        models.create_nova_client = nova.fake_create_nova_client
        super(TestReplication, self).setUp()
开发者ID:pombredanne,项目名称:RDS,代码行数:33,代码来源:test_instance_models.py


示例12: _grow_cluster

        def _grow_cluster():

            db_instances = DBInstance.find_all(cluster_id=cluster_id).all()
            cluster_head = next(Instance.load(context, db_inst.id)
                                for db_inst in db_instances
                                if db_inst.id not in new_instance_ids)
            if not cluster_head:
                raise TroveError("Unable to determine existing Redis cluster "
                                 "member")

            (cluster_head_ip, cluster_head_port) = (
                self.get_guest(cluster_head).get_node_ip())

            # Wait for cluster members to get to cluster-ready status.
            if not self._all_instances_ready(new_instance_ids, cluster_id):
                return

            LOG.debug("All members ready, proceeding for cluster setup.")
            new_insts = [Instance.load(context, instance_id)
                         for instance_id in new_instance_ids]
            new_guests = map(self.get_guest, new_insts)

            # Connect nodes to the cluster head
            for guest in new_guests:
                guest.cluster_meet(cluster_head_ip, cluster_head_port)

            for guest in new_guests:
                guest.cluster_complete()
开发者ID:Hopebaytech,项目名称:trove,代码行数:28,代码来源:taskmanager.py


示例13: _shrink_cluster

        def _shrink_cluster():
            db_instances = DBInstance.find_all(cluster_id=cluster_id,
                                               deleted=False).all()

            all_instance_ids = [db_instance.id for db_instance in db_instances]

            remove_instances = [Instance.load(context, instance_id)
                                for instance_id in instance_ids]

            left_instances = [Instance.load(context, instance_id)
                              for instance_id
                              in all_instance_ids
                              if instance_id not in instance_ids]

            remove_member_ips = [self.get_ip(instance)
                                 for instance in remove_instances]

            k = VerticaCluster.k_safety(len(left_instances))

            for db_instance in db_instances:
                if db_instance['type'] == 'master':
                    master_instance = Instance.load(context,
                                                    db_instance.id)
                    if self.get_ip(master_instance) in remove_member_ips:
                        raise RuntimeError(_("Cannot remove master instance!"))
                    LOG.debug(_("Marking cluster k-safety: %s") % k)
                    self.get_guest(master_instance).mark_design_ksafe(k)
                    self.get_guest(master_instance).shrink_cluster(
                        remove_member_ips)
                    break

            for r in remove_instances:
                Instance.delete(r)
开发者ID:Hopebaytech,项目名称:trove,代码行数:33,代码来源:taskmanager.py


示例14: _get_cluster_instance_id

 def _get_cluster_instance_id(self, tenant_id, cluster_id):
     instance_ids = self._find_cluster_node_ids(tenant_id, cluster_id)
     args = {'tenant_id': tenant_id, 'cluster_id': cluster_id, 'type':
             'master'}
     master_instance = DBInstance.find_by(**args)
     master_instance_id = master_instance.id
     return master_instance_id, instance_ids
开发者ID:HoratiusTang,项目名称:trove,代码行数:7,代码来源:service.py


示例15: _init

 def _init(self):
     self.mock = mox.Mox()
     self.instance_id = 500
     context = trove_testtools.TroveTestContext(self)
     self.db_info = DBInstance.create(
         name="instance",
         flavor_id=OLD_FLAVOR_ID,
         tenant_id=999,
         volume_size=None,
         datastore_version_id=test_config.dbaas_datastore_version_id,
         task_status=InstanceTasks.RESIZING)
     self.server = self.mock.CreateMock(Server)
     self.instance = models.BuiltInstanceTasks(
         context,
         self.db_info,
         self.server,
         datastore_status=InstanceServiceStatus.create(
             instance_id=self.db_info.id,
             status=rd_instance.ServiceStatuses.RUNNING))
     self.instance.server.flavor = {'id': OLD_FLAVOR_ID}
     self.guest = self.mock.CreateMock(guest.API)
     self.instance._guest = self.guest
     self.instance.refresh_compute_server_info = lambda: None
     self.instance._refresh_datastore_status = lambda: None
     self.mock.StubOutWithMock(self.instance, 'update_db')
     self.mock.StubOutWithMock(self.instance,
                               'set_datastore_status_to_paused')
     self.poll_until_mocked = False
     self.action = None
开发者ID:paramtech,项目名称:tesora-trove,代码行数:29,代码来源:instances_resize.py


示例16: prepare

    def prepare(
        self,
        memory_mb,
        databases,
        users,
        device_path=None,
        mount_point=None,
        backup_id=None,
        config_contents=None,
        root_password=None,
    ):
        from trove.instance.models import DBInstance
        from trove.instance.models import InstanceServiceStatus
        from trove.guestagent.models import AgentHeartBeat

        LOG.debug("users... %s" % users)
        LOG.debug("databases... %s" % databases)
        instance_name = DBInstance.find_by(id=self.id).name
        self.create_user(users)
        self.create_database(databases)

        def update_db():
            status = InstanceServiceStatus.find_by(instance_id=self.id)
            if instance_name.endswith("GUEST_ERROR"):
                status.status = rd_instance.ServiceStatuses.FAILED
            else:
                status.status = rd_instance.ServiceStatuses.RUNNING
            status.save()
            AgentHeartBeat.create(instance_id=self.id)

        eventlet.spawn_after(1.0, update_db)
开发者ID:jeredding,项目名称:trove,代码行数:31,代码来源:guestagent.py


示例17: test_create_replica_from_replica

 def test_create_replica_from_replica(self):
     self.replica_datastore_version = Mock(spec=datastore_models.DBDatastoreVersion)
     self.replica_datastore_version.id = "UUID"
     self.replica_datastore_version.manager = "mysql"
     self.replica_info = DBInstance(
         InstanceTasks.NONE,
         id="UUID",
         name="TestInstance",
         datastore_version_id=self.replica_datastore_version.id,
         slave_of_id=self.master.id,
     )
     self.replica_info.save()
     self.assertRaises(
         exception.Forbidden,
         Instance.create,
         None,
         "name",
         2,
         "UUID",
         [],
         [],
         None,
         self.datastore_version,
         1,
         None,
         slave_of_id=self.replica_info.id,
     )
开发者ID:pombredanne,项目名称:RDS,代码行数:27,代码来源:test_instance_models.py


示例18: all_instances_marked_deleted

 def all_instances_marked_deleted():
     non_deleted_instances = DBInstance.find_all(
         cluster_id=cluster_id, deleted=False).all()
     non_deleted_ids = [db_instance.id for db_instance
                        in non_deleted_instances]
     return not bool(
         set(instance_ids).intersection(set(non_deleted_ids))
     )
开发者ID:Hopebaytech,项目名称:trove,代码行数:8,代码来源:taskmanager.py


示例19: load

 def load(context, id):
     client = create_nova_client(context)
     account = client.accounts.get_instances(id)
     db_infos = DBInstance.find_all(tenant_id=id, deleted=False)
     servers = [Server(server) for server in account.servers]
     instances = MgmtInstances.load_status_from_existing(context, db_infos,
                                                         servers)
     return Account(id, instances)
开发者ID:abansal,项目名称:trove,代码行数:8,代码来源:models.py


示例20: test_upgrade

    def test_upgrade(self, task_upgrade):
        instance_model = DBInstance(
            InstanceTasks.NONE,
            id=str(uuid.uuid4()),
            name="TestUpgradeInstance",
            datastore_version_id=self.datastore_version1.id)
        instance_model.set_task_status(InstanceTasks.NONE)
        instance_model.save()
        instance_status = InstanceServiceStatus(
            ServiceStatuses.RUNNING,
            id=str(uuid.uuid4()),
            instance_id=instance_model.id)
        instance_status.save()
        self.assertIsNotNone(instance_model)
        instance = models.load_instance(models.Instance, self.context,
                                        instance_model.id)

        try:
            instance.upgrade(self.datastore_version2)

            self.assertEqual(self.datastore_version2.id,
                             instance.db_info.datastore_version_id)
            self.assertEqual(InstanceTasks.UPGRADING,
                             instance.db_info.task_status)
            self.assertTrue(task_upgrade.called)
        finally:
            instance_status.delete()
            instance_model.delete()
开发者ID:Tesora-Release,项目名称:tesora-trove,代码行数:28,代码来源:test_instance_models.py



注:本文中的trove.instance.models.DBInstance类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Instance类代码示例发布时间:2022-05-27
下一篇:
Python models.load_any_instance函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap