예제 #1
0
    def group_remove(self, groupnames):
        # type: (List[str]) -> None
        """Remove groups from the inventory

        :param groupnames: names of the groups to remove from the inventory
        :type groupnames: list of strings
        """
        check_arg(groupnames, u._('Group names'), list)
        groupnames = safe_decode(groupnames)

        inventory = Inventory.load()
        for groupname in groupnames:
            inventory.remove_group(groupname)
        Inventory.save(inventory)
예제 #2
0
    def group_add(self, groupnames):
        # type: (List[str]) -> None
        """Add groups to the inventory

        :param groupnames: names of the groups to add to the inventory
        :type groupnames: list of strings

        """
        check_arg(groupnames, u._('Group names'), list)
        groupnames = safe_decode(groupnames)

        inventory = Inventory.load()
        for groupname in groupnames:
            inventory.add_group(groupname)
        Inventory.save(inventory)
예제 #3
0
    def host_remove(hostnames):
        # type: (List[str]) -> None
        """Remove hosts from the inventory

        :param hostnames: list of strings
        """
        check_arg(hostnames, u._('Host names'), list)
        hostnames = safe_decode(hostnames)

        inventory = Inventory.load()
        any_changed = False
        for hostname in hostnames:
            changed = inventory.remove_host(hostname)
            if changed:
                any_changed = True
        if any_changed:
            Inventory.save(inventory)
예제 #4
0
    def config_import_inventory(self, file_path):
        # type: (str) -> None
        """Config Import Inventory

        Import groups and child associations from the provided
        inventory file. This currently does not import hosts, group
        vars, or host vars that may also exist in the inventory file.

        :param file_path: path to inventory file to import
        :type file_path: string
        """
        check_arg(file_path, u._('File path'), str)
        if not os.path.isfile(file_path):
            raise InvalidArgument(
                u._('File {path} is not valid.').format(path=file_path))
        inventory = Inventory(file_path)
        Inventory.save(inventory)
예제 #5
0
    def set_deploy_mode(remote_mode):
        # type: (bool) -> None
        """Set deploy mode.

        Set deploy mode to either local or remote. Local indicates
        that the openstack deployment will be to the local host.
        Remote means that the deployment is executed via ssh.

        NOTE: local mode is not supported and should never be used
        in production environments.

        :param remote_mode: if remote mode is True deployment is done via ssh
        :type remote_mode: bool
        """
        check_arg(remote_mode, u._('Remote mode'), bool)
        inventory = Inventory.load()
        inventory.set_deploy_mode(remote_mode)
        Inventory.save(inventory)
예제 #6
0
    def add_service(self, servicename):
        # type: (str) -> None
        """Add service to group

        :param servicename: name of the service to add to the group
        :type servicename: string
        """
        check_arg(servicename, u._('Service name'), str)
        servicename = safe_decode(servicename)
        inventory = Inventory.load()
        inventory.validate_servicenames([servicename], client_filter=True)

        group_services = inventory.get_group_services()
        self._servicenames = group_services[self.name]
        if servicename not in self._servicenames:
            # service not associated with group, add it
            inventory.add_group_to_service(self.name, servicename)
            self._servicenames.append(servicename)
            Inventory.save(inventory)
예제 #7
0
    def remove_host(self, hostname):
        # type: (str) -> None
        """Remove host from group

        :param hostname: name of the host to remove from the group
        :type hostname: string

        """
        check_arg(hostname, u._('Host name'), str)
        hostname = safe_decode(hostname)
        inventory = Inventory.load()
        inventory.validate_hostnames([hostname])

        group = inventory.get_group(self.name)
        self._hostnames = group.get_hostnames()
        if hostname in self._hostnames:
            # host is associated with group, remove it
            inventory.remove_host(hostname, self.name)
            self._hostnames.remove(hostname)
            Inventory.save(inventory)
예제 #8
0
    def add_host(self, hostname):
        # type: (str) -> None
        """Add host to group

        :param hostname: name of the host to add to the group
        :type hostname: string

        """
        check_arg(hostname, u._('Host name'), str)
        hostname = safe_decode(hostname)
        inventory = Inventory.load()
        inventory.validate_hostnames([hostname])

        group = inventory.get_group(self.name)
        self._hostnames = group.get_hostnames()
        if hostname not in self._hostnames:
            # host not associated with group, add it
            inventory.add_host(hostname, self.name)
            self._hostnames.append(hostname)
            Inventory.save(inventory)
예제 #9
0
    def remove_service(self, servicename):
        # type: (str) -> None
        """Remove service from group

        :param servicename: name of the service to remove from the group
        :type servicename: string

        """
        check_arg(servicename, u._('Service name'), str)
        servicename = safe_decode(servicename)
        inventory = Inventory.load()
        inventory.validate_servicenames([servicename], client_filter=True)

        group_services = inventory.get_group_services()
        self._servicenames = group_services[self.name]
        if servicename in self._servicenames:
            # service is associated with group, remove it
            inventory.remove_group_from_service(self.name, servicename)
            self._servicenames.remove(servicename)
            Inventory.save(inventory)