コード例 #1
0
  def __create_all_volumes(self, list_volumes, transport, stripe, replica, quota, directory, list_nodes):
    gluster = Gluster()
    volume_manager = gluster.get_volume_manager()

    for volume in list_volumes:
        try:
            volume_manager.info(volume)
        except Exception,e:
            if e.message.find("Volume " + volume +" does not exist") >= 0:
                list_bricks = []
                for node in list_nodes.itervalues():
                    list_bricks.append(node['ip'] + ':' + directory + '/' + volume)
                volume_manager.create(volume, list_bricks, transport, stripe, replica, quota)
                print("Volume '" + volume + "' has been created")
            else:
                raise e
コード例 #2
0
    def manage_cluster(self):
        gluster = Gluster()
        peer_manager = gluster.get_peer_manager()
        volume_manager = gluster.get_volume_manager()
        metadata_manager = MetadataAPI()

        # I check there are more than 1 container
        number_node = self.__get_numbers_of_node_in_service()

        # I get my container info
        current_container = self.__get_my_container_info()

        # I get all other containers
        list_containers = self.__get_other_container_in_service(
            current_container)

        # If I am not on cluster and there are no cluster and I am the master, so I create the gluster
        if (self.__is_already_on_glusterfs() is False) and (self._is_master(
                current_container, list_containers) is True) and (
                    self.__is_cluster_already_exist(list_containers) is False):
            self.__create_cluster(list_containers, number_node)

        # If I am already on cluster and there are new peer, I guest them.
        if (self.__is_already_on_glusterfs() is
                True) and (number_node > self.__get_numbers_peer()):

            list_nodes = {}
            peer_status = self.__get_peers()
            for container in list_containers.itervalues():
                if container['ip'] not in peer_status["host"]:
                    list_nodes[container["name"]] = container
                    print("New host : " + container["name"])

            self.__create_cluster(list_nodes, number_node)
            list_containers = list_nodes

        # I create all volumes
        if self.__is_already_on_glusterfs() is True:
            list_nodes = list_containers.copy()
            list_nodes[current_container["name"]] = current_container
            self.__create_all_volumes(self.__list_volumes, self.__transport,
                                      self.__stripe, self.__replica,
                                      self.__quota, self.__gluster_directory,
                                      list_nodes)
コード例 #3
0
    def __create_all_volumes(self, list_volumes, transport, stripe, replica,
                             quota, directory, list_nodes):
        gluster = Gluster()
        volume_manager = gluster.get_volume_manager()

        for volume in list_volumes:
            try:
                volume_manager.info(volume)
            except Exception, e:
                if e.message.find("Volume " + volume + " does not exist") >= 0:
                    list_bricks = []
                    for node in list_nodes.itervalues():
                        list_bricks.append(node['ip'] + ':' + directory + '/' +
                                           volume)
                    volume_manager.create(volume, list_bricks, transport,
                                          stripe, replica, quota)
                    print("Volume '" + volume + "' has been created")
                else:
                    raise e
コード例 #4
0
  def manage_cluster(self):
    gluster = Gluster()
    peer_manager = gluster.get_peer_manager()
    volume_manager = gluster.get_volume_manager()
    metadata_manager = MetadataAPI()

    # I check there are more than 1 container
    number_node = self.__get_numbers_of_node_in_service()

    # I get my container info
    current_container = self.__get_my_container_info()

    # I get all other containers
    list_containers = self.__get_other_container_in_service(current_container["name"])

    # If I am not on cluster and there are no cluster and I am the master, so I create the gluster
    if (self.__is_already_on_glusterfs() is False) and (self._is_master(current_container, list_containers) is True) and (self.__is_cluster_already_exist(list_containers) is False):
        self.__create_cluster(list_containers, number_node)



    # If I am already on cluster and there are new peer, I guest them.
    if (self.__is_already_on_glusterfs() is True) and (number_node > self.__get_numbers_peer()):

        list_nodes = {}
        peer_status = self.__get_peers()
        for container in list_containers.itervalues():
            if container['ip'] not in peer_status["host"]:
                list_nodes[container["name"]] = container
                print("New host : " + container["name"])


        self.__create_cluster(list_nodes, number_node)
        list_containers = list_nodes


    # I create all volumes
    if self.__is_already_on_glusterfs() is True:
        list_nodes = list_containers.copy()
        list_nodes[current_container["name"]] = current_container
        self.__create_all_volumes(self.__list_volumes, self.__transport, self.__stripe, self.__replica, self.__quota,self.__gluster_directory,list_nodes)