コード例 #1
0
 def disk(self, disk_ID):
     """Returns disk with the given ID"""
     try:
         return self._disks[disk_ID]
     except KeyError:
         util.error_message("couldn't find disk {} on vm {}".format(
             disk_ID, self.ID))
         raise
コード例 #2
0
ファイル: vm.py プロジェクト: simhaonline/addon-linstor
    def disk(self, disk_id):
        """
        Returns disk with the given ID

        :param disk_id:
        :return:
        """
        try:
            return self._disks[disk_id]
        except KeyError:
            util.error_message("couldn't find disk {} on vm {}".format(
                disk_id, self.id))
            raise
コード例 #3
0
    def _run_command(self, command):
        client_opts = ["linstor", "--no-color"]
        if self._controllers:
            client_opts += ["--controllers", self._controllers]
        final = client_opts + command

        util.log_info("running linstor {}".format(" ".join(command)))

        try:
            return subprocess.check_output(
                " ".join(final), shell=True, stderr=subprocess.STDOUT
            )
        except subprocess.CalledProcessError as cpe:
            util.error_message(cpe.output)
            raise
コード例 #4
0
ファイル: resource.py プロジェクト: arovietnam/addon-linstor
    def _is_client(self, list_output, target_node):
        res_states = json.loads(list_output)[0]["resources"]

        deployment_state = list(
            filter(
                lambda x: x["node_name"] == target_node and x["name"] == self.
                name,
                res_states,
            ))
        try:
            return "DISKLESS" in deployment_state[0].get("rsc_flags", [])
        except IndexError:
            util.error_message("Unable to find {} or {} in {}".format(
                self.name, target_node, res_states))
            raise
コード例 #5
0
ファイル: resource.py プロジェクト: arovietnam/addon-linstor
 def path(self, list_output):
     res_states = json.loads(list_output)[0]["resources"]
     try:
         self._path = list(
             filter(
                 lambda x: x["vlm_nr"] == 0 and "device_path" in x,
                 list(
                     map(lambda x: x["vlms"],
                         filter(self._match_nodes, res_states)))[0],
             ))[0]["device_path"]
     except KeyError:
         util.error_message(
             "Unable to locate device path for {}, please ensure the health of this reource"
             .format(self.name))
         raise
コード例 #6
0
    def _update_storage_info(self, sp_info):
        pool_data = json.loads(sp_info)[0].get("stor_pools", {})
        self._storage_pool_total_MiB = 0
        self._storage_pool_free_MiB = 0
        self._storage_pool_used_MiB = 0

        free_space_by_node = {}

        for pool in list(
            filter(lambda x: x["stor_pool_name"] == self.storage_pool, pool_data)
        ):
            free_space_by_node[pool["node_name"]] = pool["free_space"]

        if self.nodes:
            lowest_free_node = self.nodes[0]
            for node in self.nodes:
                try:
                    if (
                        free_space_by_node[node]["total_capacity"]
                        < free_space_by_node[node]["total_capacity"]
                    ):
                        lowest_free_node = node
                except KeyError:
                    util.error_message(
                        "Node {} does not appear to contain storage pool {}".format(
                            self.name, self.storage_pool
                        )
                    )
                    raise
            self._storage_pool_total_MiB += (
                free_space_by_node[lowest_free_node].get("total_capacity", 0) // 1024
            )
            self._storage_pool_free_MiB += (
                free_space_by_node[lowest_free_node].get("free_capacity", 0) // 1024
            )
        else:
            for space_info in free_space_by_node.values():
                self._storage_pool_total_MiB += (
                    space_info.get("total_capacity", 0) // int(self.auto_place)
                ) // 1024
                self._storage_pool_free_MiB += (
                    space_info.get("free_capacity", 0) // int(self.auto_place)
                ) // 1024

        self._storage_pool_used_MiB = (
            self._storage_pool_total_MiB - self._storage_pool_free_MiB
        )