Esempio n. 1
0
    def add_host(self, hostname, groupname=None):
        """add host

        if groupname is none, create a new host
        if group name is not none, add host to group
        """
        if groupname and groupname not in self._groups:
            raise NotInInventory(u._('Group'), groupname)

        if groupname and hostname not in self._hosts:
            # if a groupname is specified, the host must already exist
            raise NotInInventory(u._('Host'), hostname)

        if not groupname and not self.remote_mode and len(self._hosts) >= 1:
            raise InvalidConfiguration(
                u._('Cannot have more than one host when in local deploy '
                    'mode.'))

        changed = False
        # create new host if it doesn't exist
        host = Host(hostname)
        if hostname not in self.get_hostnames():
            # a new host is being added to the inventory
            changed = True
            self._hosts[hostname] = host

        # a host is to be added to an existing group
        elif groupname:
            group = self._groups[groupname]
            if hostname not in group.get_hostnames():
                changed = True
                group.add_host(host)
        return changed
Esempio n. 2
0
    def set_deploy_mode(self, remote_flag):
        if not remote_flag and len(self._hosts) > 1:
            raise InvalidConfiguration(
                u._('Cannot set local deploy mode when multiple hosts exist.'))
        self.remote_mode = remote_flag

        for group in self.get_groups():
            group.set_remote(remote_flag)
Esempio n. 3
0
    def _run_deploy_rules(self, playbook):
        properties = AnsibleProperties()
        inventory = Inventory.load()

        # cannot have both groups and hosts
        if playbook.hosts and playbook.groups:
            raise InvalidArgument(
                u._('Hosts and Groups arguments cannot '
                    'both be present at the same time.'))

        # verify that all services exists
        if playbook.services:
            for service in playbook.services:
                valid_service = inventory.get_service(service)
                if not valid_service:
                    raise NotInInventory(u._('Service'), service)

        # check that every group with enabled services
        # has hosts associated to it
        group_services = inventory.get_group_services()
        failed_groups = []
        failed_services = []
        if group_services:
            for (groupname, servicenames) in group_services.items():
                group = inventory.get_group(groupname)
                hosts = group.get_hostnames()

                group_needs_host = False
                if not hosts:
                    for servicename in servicenames:
                        if self._is_service_enabled(servicename, inventory,
                                                    properties):
                            group_needs_host = True
                            failed_services.append(servicename)
                    if group_needs_host:
                        failed_groups.append(groupname)

            if len(failed_groups) > 0:
                raise InvalidConfiguration(
                    u._('Deploy failed. '
                        'Groups: {groups} with enabled '
                        'services : {services} '
                        'have no associated hosts').format(
                            groups=failed_groups, services=failed_services))
Esempio n. 4
0
    def precheck(self, hostnames=[], servicenames=[]):
        '''run check playbooks on a set of hosts'''

        # check that password file has no empty password values
        empty_keys = get_empty_password_values()
        if empty_keys:
            raise InvalidConfiguration(
                u._('password check failed. There are empty password values '
                    'in {etc}passwords.yml. '
                    'Please run kolla-cli password init or '
                    'kolla-cli password set(key) to correct them. '
                    '\nEmpty passwords: '
                    '{keys}').format(etc=get_kolla_etc(), keys=empty_keys))

        # define 'hosts' to be all, but inventory filtering will subset
        # that down to the hosts in playbook.hosts.
        self.playbook.hosts = hostnames
        self.playbook.services = servicenames
        self.playbook.extra_vars = 'kolla_action=precheck'
        self.playbook.print_output = True
        job = self.playbook.run()
        return job
Esempio n. 5
0
def _run_deploy_rules(playbook):
    properties = AnsibleProperties()
    inventory = Inventory.load()

    # check that password file has no empty password values
    empty_keys = get_empty_password_values()
    if empty_keys:
        raise InvalidConfiguration(
            u._('Deploy failed. There are empty password values '
                'in {etc}passwords.yml. '
                'Please run kolla-cli password init or '
                'kolla-cli password set(key) to correct them. '
                '\nEmpty passwords: '
                '{keys}').format(etc=get_kolla_etc(), keys=empty_keys))

    # cannot have both groups and hosts
    if playbook.hosts and playbook.groups:
        raise InvalidArgument(
            u._('Hosts and Groups arguments cannot '
                'both be present at the same time.'))

    # verify that all services exists
    if playbook.services:
        for service in playbook.services:
            valid_service = inventory.get_service(service)
            if not valid_service:
                raise NotInInventory(u._('Service'), service)

    # check that every group with enabled services
    # has hosts associated to it
    group_services = inventory.get_group_services()
    failed_groups = []
    failed_services = []
    if group_services:
        for (groupname, servicenames) in group_services.items():
            group = inventory.get_group(groupname)
            hosts = group.get_hostnames()

            group_needs_host = False
            if not hosts:
                for servicename in servicenames:
                    if _is_service_enabled(servicename, inventory, properties):
                        group_needs_host = True
                        failed_services.append(servicename)
                if group_needs_host:
                    failed_groups.append(groupname)

        if len(failed_groups) > 0:
            raise InvalidConfiguration(
                u._('Deploy failed. '
                    'Groups: {groups} with enabled '
                    'services : {services} '
                    'have no associated hosts').format(
                        groups=failed_groups, services=failed_services))

    # check that ring files are in /etc/kolla/config/swift if
    # swift is enabled
    expected_files = ['account.ring.gz', 'container.ring.gz', 'object.ring.gz']
    is_swift_enabled = _is_service_enabled('swift', inventory, properties)

    if is_swift_enabled:
        path_pre = os.path.join(get_kolla_etc(), 'config', 'swift')
        for expected_file in expected_files:
            path = os.path.join(path_pre, expected_file)
            if not os.path.isfile(path):
                msg = u._('Deploy failed. '
                          'Swift is enabled but ring buffers have '
                          'not yet been set up. Please see the '
                          'documentation for swift configuration '
                          'instructions.')
                raise InvalidConfiguration(msg)