当前位置: 首页>>代码示例>>Python>>正文


Python VolumeController.get_recommended_nodes方法代码示例

本文整理汇总了Python中lunr.api.controller.volume.VolumeController.get_recommended_nodes方法的典型用法代码示例。如果您正苦于以下问题:Python VolumeController.get_recommended_nodes方法的具体用法?Python VolumeController.get_recommended_nodes怎么用?Python VolumeController.get_recommended_nodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lunr.api.controller.volume.VolumeController的用法示例。


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

示例1: test_recommend_nodes_ordered_by_volumes_with_weights

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
    def test_recommend_nodes_ordered_by_volumes_with_weights(self):
        c = Controller({'account_id':  self.account_id}, self.mock_app)
        n = db.models.Node('node3', 13, volume_type=self.vtype,
                           hostname='10.127.0.3', port=8083)
        self.db.add(n)
        self.db.add(db.models.Volume(1, 'vtype', node=self.node1,
                                     account_id=self.account_id,
                                     volume_type=self.vtype))
        self.db.add(db.models.Volume(1, 'vtype', node=n,
                                     account_id=self.account_id))
        n.calc_storage_used()
        self.db.commit()
        nodes = c.get_recommended_nodes(self.vtype.name, 1)
        # node0/2 have 0 volumes, they should be included.
        # node1/3 have 1 volume. 3 should be included because it's bigger.
        node_ids = [node.id for node in nodes]
        expected_ids = [self.node0.id, self.node2.id, n.id]
        self.assertEqual(sorted(node_ids), sorted(expected_ids))

        # Weight should override these.
        self.node1.weight = 200
        self.node2.weight = 200
        n.weight = 200
        self.db.add_all([self.node1, self.node2, n])
        self.db.commit
        nodes = c.get_recommended_nodes(self.vtype.name, 1)
        node_ids = [node.id for node in nodes]
        # Due to weights, we should want 1, 2, and 3
        expected_ids = [self.node1.id, self.node2.id, n.id]
        self.assertEqual(sorted(node_ids), sorted(expected_ids))
开发者ID:rackerlabs,项目名称:lunr,代码行数:32,代码来源:test_volume.py

示例2: test_recommended_nodes_affinity_node

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
 def test_recommended_nodes_affinity_node(self):
     self.mock_app.fill_strategy = 'deep_fill'
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     nodes = c.get_recommended_nodes(self.vtype.name, 1)
     node_ids = [node.id for node in nodes]
     # Our test nodes are in order by size, 0 = 10, 1 = 11, etc.
     expected_ids = [self.node0.id, self.node1.id, self.node2.id]
     self.assertEqual(node_ids, expected_ids)
     # Now add a volume for this account
     v1 = db.models.Volume(1, 'vtype', node=self.node0,
         account_id=self.account_id, volume_type=self.vtype)
     v2 = db.models.Volume(2, 'vtype', node=self.node1,
         account_id=self.account_id, volume_type=self.vtype)
     v3 = db.models.Volume(2, 'vtype', node=self.node2,
         account_id=self.account_id, volume_type=self.vtype)
     self.db.add_all([v1, v2, v3])
     self.db.commit()
     # Should prefer the second node
     affinity = 'different_node:%s' % v1.id
     nodes = c.get_recommended_nodes(self.vtype.name, 3,
                                     affinity=affinity)
     self.assertEquals(2, len(nodes))
     self.assertEquals(nodes[0].id, self.node1.id)
     # Add a volume to the second node
     # Should prefer the last node
     affinity = 'different_node:%s,%s' % (v1.id, v2.id)
     nodes = c.get_recommended_nodes(self.vtype.name, 1,
                                     affinity=affinity)
     self.assertEquals(1, len(nodes))
     self.assertEquals(nodes[0].id, self.node2.id)
     # Recommendation fails.
     affinity = 'different_node:%s,%s,%s' % (v1.id, v2.id, v3.id)
     self.assertRaises(HTTPInsufficientStorage, c.get_recommended_nodes,
                       self.vtype.name, 1, affinity=affinity)
开发者ID:corystone,项目名称:lunr,代码行数:36,代码来源:test_volume.py

示例3: test_deep_recommended_nodes

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
 def test_deep_recommended_nodes(self):
     self.mock_app.fill_strategy = 'deep_fill'
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     nodes = c.get_recommended_nodes(self.vtype.name, 1)
     node_ids = [node.id for node in nodes]
     # Our test nodes are in order by size, 0 = 10, 1 = 11, etc.
     expected_ids = [self.node0.id, self.node1.id, self.node2.id]
     self.assertEqual(node_ids, expected_ids)
     # Add Volume from a different account,
     self.db.add(db.models.Volume(1, 'vtype', node=self.node0,
                                  account_id=self.account_id2,
                                  volume_type=self.vtype))
     # node0 should still be preferred
     nodes = c.get_recommended_nodes(self.vtype.name, 1)
     self.assertEquals(3, len(nodes))
     self.assertEquals(nodes[0].id, self.node0.id)
     # Now add a volume for this account
     self.db.add(db.models.Volume(1, 'vtype', node=self.node0,
                                  account_id=self.account_id,
                                  volume_type=self.vtype))
     # Should prefer the second node
     nodes = c.get_recommended_nodes(self.vtype.name, 3)
     self.assertEquals(3, len(nodes))
     self.assertEquals(nodes[0].id, self.node1.id)
     # Add a volume to the second node
     self.db.add(db.models.Volume(3, 'vtype', node=self.node1,
                                  account_id=self.account_id,
                                  volume_type=self.vtype))
     # Should prefer the last node
     nodes = c.get_recommended_nodes(self.vtype.name, 1)
     self.assertEquals(3, len(nodes))
     self.assertEquals(nodes[0].id, self.node2.id)
开发者ID:corystone,项目名称:lunr,代码行数:34,代码来源:test_volume.py

示例4: test_recommended_nodes_force_node

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
    def test_recommended_nodes_force_node(self):
        self.mock_app.fill_strategy = 'deep_fill'
        c = Controller({'account_id':  self.account_id}, self.mock_app)
        node = self.node0

        nodes = c.get_recommended_nodes(self.vtype.name, 1,
                                        force_node=node.name)
        self.assertEqual(len(nodes), 1)
        self.assertEqual(nodes[0].id, node.id)

        nodes = c.get_recommended_nodes(self.vtype.name, 1,
                                        force_node=node.id)
        self.assertEqual(len(nodes), 1)
        self.assertEqual(nodes[0].id, node.id)
开发者ID:corystone,项目名称:lunr,代码行数:16,代码来源:test_volume.py

示例5: test_get_recommended_nodes_weights

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
 def test_get_recommended_nodes_weights(self):
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     size = 1
     count = 1
     nodes = c.get_recommended_nodes(self.vtype.name, size, count)
     # 2 is preferred since it's biggest
     self.assertEqual(nodes[0].id, self.node2.id)
     self.node0.weight = 202
     self.node1.weight = 201
     self.node2.weight = 200
     self.db.add_all([self.node0, self.node1, self.node2])
     self.db.commit()
     # 0 is preferred due to weight
     nodes = c.get_recommended_nodes(self.vtype.name, size, count)
     self.assertEqual(nodes[0].id, self.node0.id)
开发者ID:rackerlabs,项目名称:lunr,代码行数:17,代码来源:test_volume.py

示例6: test_get_recommended_nodes_is_random

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
 def test_get_recommended_nodes_is_random(self):
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     size = 1
     nodes1 = c.get_recommended_nodes(self.vtype.name, size)
     attempts = 0
     while True:
         nodes2 = c.get_recommended_nodes(self.vtype.name, size)
         try:
             self.assertNotEquals(nodes1, nodes2)
         except AssertionError:
             if attempts >= 3:
                 raise
         else:
             break
         attempts += 1
     self.assertEquals(len(nodes1), len(nodes2))
     nodes1.sort()
     nodes2.sort()
     self.assertEqual(nodes1, nodes2)
开发者ID:corystone,项目名称:lunr,代码行数:21,代码来源:test_volume.py

示例7: test_recommended_nodes_affinity_cab

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
 def test_recommended_nodes_affinity_cab(self):
     self.mock_app.fill_strategy = 'deep_fill'
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     nodes = c.get_recommended_nodes(self.vtype.name, 1)
     node_ids = [node.id for node in nodes]
     # Our test nodes are in order by size, 0 = 10, 1 = 11, etc.
     expected_ids = [self.node0.id, self.node1.id, self.node2.id]
     self.assertEqual(node_ids, expected_ids)
     # Set up cabs.
     self.node0.affinity_group = 'cab1'
     self.node1.affinity_group = 'cab2'
     self.node2.affinity_group = 'cab1'
     # Now add some volumes to these cabs.
     # v1,v3 = cab1, v2 = cab2
     self.db.add_all([self.node0, self.node1, self.node2])
     v1 = db.models.Volume(1, 'vtype', node=self.node0,
         account_id=self.account_id, volume_type=self.vtype)
     v2 = db.models.Volume(1, 'vtype', node=self.node1,
         account_id=self.account_id, volume_type=self.vtype)
     v3 = db.models.Volume(1, 'vtype', node=self.node2,
         account_id=self.account_id, volume_type=self.vtype)
     self.db.add_all([v1, v2, v3])
     self.db.commit()
     # Should only show node1 (cab2)
     affinity = 'different_group:%s' % v1.id
     nodes = c.get_recommended_nodes(self.vtype.name, 3,
                                     affinity=affinity)
     self.assertEquals(1, len(nodes))
     self.assertEquals(nodes[0].id, self.node1.id)
     # Should show node0 and node2 (cab1)
     affinity = 'different_group:%s' % v2.id
     nodes = c.get_recommended_nodes(self.vtype.name, 1,
                                     affinity=affinity)
     self.assertEquals(2, len(nodes))
     self.assertEquals(nodes[0].id, self.node0.id)
     self.assertEquals(nodes[1].id, self.node2.id)
     # Recommendation fails.
     affinity = 'different_group:%s,%s' % (v1.id, v2.id)
     self.assertRaises(HTTPInsufficientStorage, c.get_recommended_nodes,
                       self.vtype.name, 1, affinity=affinity)
开发者ID:corystone,项目名称:lunr,代码行数:42,代码来源:test_volume.py

示例8: test_recommended_nodes_for_image

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
 def test_recommended_nodes_for_image(self):
     self.mock_app.fill_strategy = 'deep_fill'
     self.mock_app.image_convert_limit = 1
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     nodes = c.get_recommended_nodes(self.vtype.name, 1)
     node_ids = [node.id for node in nodes]
     # Our test nodes are in order by size, 0 = 10, 1 = 11, etc.
     expected_ids = [self.node0.id, self.node1.id, self.node2.id]
     self.assertEqual(node_ids, expected_ids)
     # Add an imaging volume to node0
     self.db.add(db.models.Volume(1, 'vtype', node=self.node0,
                                  account_id=self.account_id2,
                                  volume_type=self.vtype, status='IMAGING'))
     nodes = c.get_recommended_nodes(self.vtype.name, 1)
     self.assertEquals(3, len(nodes))
     node_ids = [node.id for node in nodes]
     self.assertIn(self.node0.id, node_ids)
     # Now try recommendations for imaging
     nodes = c.get_recommended_nodes(self.vtype.name, 1, imaging=True)
     self.assertEquals(2, len(nodes))
     node_ids = [node.id for node in nodes]
     self.assertNotIn(self.node0.id, node_ids)
开发者ID:corystone,项目名称:lunr,代码行数:24,代码来源:test_volume.py

示例9: test_dont_recommend_full_nodes

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
 def test_dont_recommend_full_nodes(self):
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     size = 2
     # (10 - (10 - 3 - 2)) / 10 == .5, IN!
     self.db.add(db.models.Volume(3, 'vtype', node=self.node0,
                                  account_id=self.account_id))
     # (11 - (11 - 4 - 2)) / 11 > .5, OUT!
     self.db.add(db.models.Volume(4, 'vtype', node=self.node1,
                                  account_id=self.account_id))
     # (12 - (12 - 20 - 2)) / 12 > .5, OUT!
     self.db.add(db.models.Volume(5, 'vtype', node=self.node2,
                                  account_id=self.account_id))
     nodes1 = c.get_recommended_nodes(self.vtype.name, size)
     self.assertEquals(nodes1, [self.node0])
开发者ID:corystone,项目名称:lunr,代码行数:16,代码来源:test_volume.py

示例10: test_get_recommended_ignores_deleted_volumes

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
 def test_get_recommended_ignores_deleted_volumes(self):
     c = Controller({'account_id':  self.account_id}, self.mock_app)
     vtype = db.models.VolumeType('something_else')
     n = db.models.Node('newnode', 10, volume_type=vtype,
                        hostname='10.127.0.42', port=8242)
     self.db.add_all([vtype, n])
     self.db.commit()
     nodes = c.get_recommended_nodes('something_else', 1)
     self.assertNotEquals([], nodes)
     self.assertEquals(n.id, nodes[0].id)
     # Fill it to the gills.
     v = db.models.Volume(10, 'something_else', node=n,
                          account_id=self.account_id)
     self.db.add(v)
     self.db.commit()
     self.assertRaises(HTTPError, c.get_recommended_nodes,
                       'something_else', 1)
     v.status = 'DELETED'
     self.db.add(v)
     self.db.commit()
     nodes = c.get_recommended_nodes('something_else', 1)
     self.assertNotEquals([], nodes)
     self.assertEquals(n.id, nodes[0].id)
开发者ID:corystone,项目名称:lunr,代码行数:25,代码来源:test_volume.py

示例11: test_create_from_image

# 需要导入模块: from lunr.api.controller.volume import VolumeController [as 别名]
# 或者: from lunr.api.controller.volume.VolumeController import get_recommended_nodes [as 别名]
    def test_create_from_image(self):
        image_id = 'my_image'
        base.urlopen = MockUrlopenWithImage
        c = Controller({'account_id': self.account_id, 'id': 'test1'},
                       self.mock_app)
        self.mock_called = False

        def mock_get_recommended_nodes(*args, **kwargs):
            self.assert_('imaging' in kwargs)
            self.assertTrue(kwargs['imaging'])
            self.mock_called = True
            return [self.node0]
        c.get_recommended_nodes = mock_get_recommended_nodes

        req = Request.blank('?size=2&volume_type_name=vtype&image_id=%s' %
                            image_id)
        res = c.create(req)

        self.assertTrue(self.mock_called)
        self.assertEqual(res.body['id'], 'test1')
        self.assertEqual(res.body['size'], 2)
        self.assertEqual(res.body['status'], 'IMAGING')
        self.assertEqual(res.body['image_id'], image_id)
开发者ID:corystone,项目名称:lunr,代码行数:25,代码来源:test_volume.py


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