示例#1
0
    def from_xml(cls, data):
        model = cls()

        root = etree.fromstring(data)
        for cn in root.findall('.//StorageNode'):
            ndata = {}
            for attr, val in cn.items():
                ndata[attr] = val
            volume_type = ndata.get('volume_type')
            if volume_type:
                ndata['volume_type'] = [volume_type]
            node = element.StorageNode(**ndata)
            model.add_node(node)

        for p in root.findall('.//Pool'):
            pool = element.Pool(**p.attrib)
            model.add_pool(pool)

            parent = p.getparent()
            if parent.tag == 'StorageNode':
                node = model.get_node_by_name(parent.get('host'))
                model.map_pool(pool, node)
            else:
                model.add_pool(pool)

        for vol in root.findall('.//Volume'):
            volume = element.Volume(**vol.attrib)
            model.add_volume(volume)

            parent = vol.getparent()
            if parent.tag == 'Pool':
                pool = model.get_pool_by_pool_name(parent.get('name'))
                model.map_volume(volume, pool)
            else:
                model.add_volume(volume)

        return model
示例#2
0
 def test_add_node(self):
     model = model_root.StorageModelRoot()
     hostname = "host@backend"
     node = element.StorageNode(host=hostname)
     model.add_node(node)
     self.assertEqual(node, model.get_node_by_name(hostname))
示例#3
0
 def test_assert_node_raise(self):
     model = model_root.StorageModelRoot()
     node = element.StorageNode(host="host@backend")
     model.add_node(node)
     self.assertRaises(exception.IllegalArgumentException,
                       model.assert_node, "obj")
示例#4
0
    def build_scenario_1(self):

        model = modelroot.StorageModelRoot()
        # number of nodes
        node_count = 2
        # number of pools per node
        pool_count = 2
        # number of volumes
        volume_count = 9

        for i in range(0, node_count):
            host = "host_{0}@backend_{0}".format(i)
            zone = "zone_{0}".format(i)
            volume_type = "type_{0}".format(i)
            node_attributes = {
                "host": host,
                "zone": zone,
                "status": 'enabled',
                "state": 'up',
                "volume_type": volume_type,
            }
            node = element.StorageNode(**node_attributes)
            model.add_node(node)

            for j in range(0, pool_count):
                name = "host_{0}@backend_{0}#pool_{1}".format(i, j)
                pool_attributes = {
                    "name": name,
                    "total_volumes": 2,
                    "total_capacity_gb": 500,
                    "free_capacity_gb": 420,
                    "provisioned_capacity_gb": 80,
                    "allocated_capacity_gb": 80,
                    "virtual_free": 420,
                }
                pool = element.Pool(**pool_attributes)
                model.add_pool(pool)

        mappings = [
            ("host_0@backend_0#pool_0", "host_0@backend_0"),
            ("host_0@backend_0#pool_1", "host_0@backend_0"),
            ("host_1@backend_1#pool_0", "host_1@backend_1"),
            ("host_1@backend_1#pool_1", "host_1@backend_1"),
        ]

        for pool_name, node_name in mappings:
            model.map_pool(
                model.get_pool_by_pool_name(pool_name),
                model.get_node_by_name(node_name),
            )

        for k in range(volume_count):
            uuid = "VOLUME_{0}".format(k)
            name = "name_{0}".format(k)
            project_id = "project_{0}".format(k)
            volume_attributes = {
                "size": 40,
                "status": "in-use",
                "uuid": uuid,
                "attachments":
                '[{"server_id": "server","attachment_id": "attachment"}]',
                "name": name,
                "multiattach": 'True',
                "snapshot_id": uuid,
                "project_id": project_id,
                "metadata": '{"readonly": false,"attached_mode": "rw"}',
                "bootable": 'False'
            }
            volume = element.Volume(**volume_attributes)
            model.add_volume(volume)

        mappings = [
            ("VOLUME_0", "host_0@backend_0#pool_0"),
            ("VOLUME_1", "host_0@backend_0#pool_0"),
            ("VOLUME_2", "host_0@backend_0#pool_1"),
            ("VOLUME_3", "host_0@backend_0#pool_1"),
            ("VOLUME_4", "host_1@backend_1#pool_0"),
            ("VOLUME_5", "host_1@backend_1#pool_0"),
            ("VOLUME_6", "host_1@backend_1#pool_1"),
            ("VOLUME_7", "host_1@backend_1#pool_1"),
        ]

        for volume_uuid, pool_name in mappings:
            model.map_volume(
                model.get_volume_by_uuid(volume_uuid),
                model.get_pool_by_pool_name(pool_name),
            )

        return model
示例#5
0
    def build_scenario_1(self):

        model = modelroot.StorageModelRoot()
        # number of nodes
        node_count = 2
        # number of pools per node
        pool_count = 2
        # number of volumes
        volume_count = 9

        for i in range(0, node_count):
            host = "host_{0}@backend_{0}".format(i)
            zone = "zone_{0}".format(i)
            volume_type = ["type_{0}".format(i)]
            node_attributes = {
                "host": host,
                "zone": zone,
                "status": 'enabled',
                "state": 'up',
                "volume_type": volume_type,
            }
            node = element.StorageNode(**node_attributes)
            model.add_node(node)

            for j in range(0, pool_count):
                name = "host_{0}@backend_{0}#pool_{1}".format(i, j)
                pool_attributes = {
                    "name": name,
                    "total_volumes": 2,
                    "total_capacity_gb": 500,
                    "free_capacity_gb": 420,
                    "provisioned_capacity_gb": 80,
                    "allocated_capacity_gb": 80,
                    "virtual_free": 420,
                }
                pool = element.Pool(**pool_attributes)
                model.add_pool(pool)

        mappings = [
            ("host_0@backend_0#pool_0", "host_0@backend_0"),
            ("host_0@backend_0#pool_1", "host_0@backend_0"),
            ("host_1@backend_1#pool_0", "host_1@backend_1"),
            ("host_1@backend_1#pool_1", "host_1@backend_1"),
        ]

        for pool_name, node_name in mappings:
            model.map_pool(
                model.get_pool_by_pool_name(pool_name),
                model.get_node_by_name(node_name),
            )

        volume_uuid_mapping = [
            "5028b1eb-8749-48ae-a42c-5bdd1323976f",
            "74454247-a064-4b34-8f43-89337987720e",
            "a16c811e-2521-4fd3-8779-6a94ccb3be73",
            "37856b95-5be4-4864-8a49-c83f55c66780",
            "694f8fb1-df96-46be-b67d-49f2c14a495e",
            "66b094b0-8fc3-4a94-913f-a5f9312b11a5",
            "e9013810-4b4c-4b94-a056-4c36702d51a3",
            "07976191-6a57-4c35-9f3c-55b3b5ecd6d5",
            "4d1c952d-95d0-4aac-82aa-c3cb509af9f3",
        ]

        for k in range(volume_count):
            uuid = volume_uuid_mapping[k]
            name = "name_{0}".format(k)
            volume_attributes = {
                "size": 40,
                "status": "in-use",
                "uuid": uuid,
                "attachments":
                '[{"server_id": "server","attachment_id": "attachment"}]',
                "name": name,
                "multiattach": 'True',
                "snapshot_id": uuid,
                "project_id": "91FFFE30-78A0-4152-ACD2-8310FF274DC9",
                "metadata": '{"readonly": false,"attached_mode": "rw"}',
                "bootable": 'False'
            }
            volume = element.Volume(**volume_attributes)
            model.add_volume(volume)

        mappings = [
            (volume_uuid_mapping[0], "host_0@backend_0#pool_0"),
            (volume_uuid_mapping[1], "host_0@backend_0#pool_0"),
            (volume_uuid_mapping[2], "host_0@backend_0#pool_1"),
            (volume_uuid_mapping[3], "host_0@backend_0#pool_1"),
            (volume_uuid_mapping[4], "host_1@backend_1#pool_0"),
            (volume_uuid_mapping[5], "host_1@backend_1#pool_0"),
            (volume_uuid_mapping[6], "host_1@backend_1#pool_1"),
            (volume_uuid_mapping[7], "host_1@backend_1#pool_1"),
        ]

        for volume_uuid, pool_name in mappings:
            model.map_volume(
                model.get_volume_by_uuid(volume_uuid),
                model.get_pool_by_pool_name(pool_name),
            )

        return model