コード例 #1
0
def check_arg(param,
              param_name,
              expected_type,
              none_ok=False,
              empty_ok=False,
              display_param=True):
    if param is None:
        if none_ok:
            return
        # None arg
        raise MissingArgument(param_name)

    if ((isinstance(param, six.string_types) or isinstance(param, dict)
         or isinstance(param, list)) and not param and not empty_ok):
        # empty string, dict or list
        raise MissingArgument(param_name)

    # if expected type is None, skip the type checking
    if expected_type is None:
        return
    # normalize expected string types for py2 and py3
    if expected_type is str:
        expected_type = six.string_types

    if not isinstance(param, expected_type):
        # wrong type
        if display_param:
            raise InvalidArgument(
                u._('{name} ({param}) is not a {type}').format(
                    name=param_name, param=param, type=expected_type))
        else:
            raise InvalidArgument(
                u._('{name} is not a {type}').format(name=param_name,
                                                     type=expected_type))
コード例 #2
0
ファイル: support.py プロジェクト: run4life/kolla-cli
    def support_get_logs(self, servicenames, hostname, dirpath):
        # type: (List[str], str, str) -> None
        """get container logs

        Fetch the container log files of services from the specified hosts.
        The log files will be placed in the named directory. All the containers
        for the host will be placed in a directory named hostname. The file
        names for each log will be servicename_id.log.

        :param servicenames: names of services (ie nova, glance, etc)
        :type servicenames: list of strings
        :param hostname: name of host to look for logs on
        :type hostname: string
        :param dirpath: path of directory where log files will be written
        :type dirpath: string
        """
        check_arg(dirpath, u._('Directory path'), str)
        dirpath = safe_decode(dirpath)
        if not os.path.exists(dirpath):
            raise InvalidArgument(
                u._('Directory path: {path} does not exist').format(
                    path=dirpath))

        check_arg(servicenames, u._('Service names'), list)
        servicenames = safe_decode(servicenames)
        check_arg(hostname, u._('Host names'), str)
        hostname = safe_decode(hostname)

        get_logs(servicenames, hostname, dirpath)
コード例 #3
0
    def property_set(self,
                     property_dict,
                     property_type=GLOBAL_TYPE,
                     change_set=None):
        # type: (Dict[str,str], str, List[str]) -> None
        """Set a property

        :param property_dict: property dictionary containing key / values
        :type property_dict: dictionary
        :param property_type: one of 'global', 'group' or 'host'
        :type property_type: string
        :param change_set: for group or host sets this is the list of groups
                           or hosts to set the property for
        :type change_set: list of strings

        """
        ansible_properties = AnsibleProperties()
        for key, value in property_dict.items():
            check_arg(key, u._('Property Key'), str)
            current_property = ansible_properties.get_property(key)
            if current_property is not None:
                current_property_type = current_property.value_type
                if current_property_type is not str:
                    original_value = value
                    value = yaml.safe_load(value)

                    # this check is to make sure that we can assign an empty
                    # string to a property.  without this safe_load will turn
                    # an empty string into a None which is different than an
                    # empty string.
                    if isinstance(original_value, six.string_types)\
                            and value is None:
                        value = ''
                    if current_property.value is None:
                        current_property_type = None
                    check_arg(value,
                              u._('Property Value'),
                              current_property_type,
                              empty_ok=True)
                    property_dict[key] = value
            else:
                check_arg(value, u._('Property Value'), str, empty_ok=True)
            if type(value) is str and '"' in value:
                raise InvalidArgument(
                    u._('Cannot use double quotes in '
                        'a property value.'))

        self._check_type(property_type)
        if property_type is not GLOBAL_TYPE:
            check_arg(change_set, u._('Change Set'), list, none_ok=True)
            change_set = safe_decode(change_set)

        if property_type == GLOBAL_TYPE:
            ansible_properties.set_property(property_dict)
        elif property_type == GROUP_TYPE:
            ansible_properties.set_group_property(property_dict, change_set)
        else:
            ansible_properties.set_host_property(property_dict, change_set)
コード例 #4
0
def disallow_chars(param, param_name, chars):
    if param is None:
        return

    for char in chars:
        if char in param:
            raise InvalidArgument(
                u._('{name} contains invalid character {chars}').format(
                    name=param_name, chars=chars))
コード例 #5
0
def get_property_list_length():
    envvar = 'KOLLA_PROP_LIST_LENGTH'
    length_str = os.environ.get(envvar, '50')
    try:
        length = int(length_str)
    except Exception:
        raise InvalidArgument(
            u._('Environmental variable ({env_var}) is not an '
                'integer ({prop_length}).').format(env_var=envvar,
                                                   prop_length=length_str))
    return length
コード例 #6
0
def get_kolla_log_file_size():
    envvar = 'KOLLA_LOG_FILE_SIZE'
    size_str = os.environ.get(envvar, '500000')
    try:
        size = int(size_str)
    except Exception:
        raise InvalidArgument(
            u._('Environmental variable ({env_var}) is not an '
                'integer ({log_size}).').format(env_var=envvar,
                                                log_size=size_str))
    return size
コード例 #7
0
ファイル: inventory.py プロジェクト: vmlinuxer/kolla-cli
    def remove_group(self, groupname):
        if groupname in PROTECTED_GROUPS:
            raise InvalidArgument(
                u._('Cannot remove {group} group. It is required by kolla.').
                format(group=groupname))

        # remove group from services
        for service in self._services.values():
            service.remove_groupname(groupname)

        group_vars = os.path.join(get_group_vars_dir(), groupname)
        if os.path.exists(group_vars) and groupname != '__GLOBAL__':
            os.remove(group_vars)

        if groupname in self._groups:
            del self._groups[groupname]
コード例 #8
0
ファイル: inventory.py プロジェクト: vmlinuxer/kolla-cli
    def add_group(self, groupname):

        # Group names cannot overlap with service names:
        if groupname in self._services:
            raise InvalidArgument(
                u._('Invalid group name. A service name '
                    'cannot be used for a group name.'))

        if groupname not in self._groups:
            self._groups[groupname] = HostGroup(groupname)

        group = self._groups[groupname]

        group.set_remote(self.remote_mode)

        return group
コード例 #9
0
ファイル: config.py プロジェクト: run4life/kolla-cli
    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)
コード例 #10
0
ファイル: actions.py プロジェクト: run4life/kolla-cli
    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))
コード例 #11
0
    def host_destroy(hostnames,
                     destroy_type,
                     verbose_level=1,
                     include_data=False,
                     remove_images=False):
        # type: (List[str], str, int, bool, bool) -> Job
        """Destroy Hosts.

        Stops and removes all kolla related docker containers on the
        specified hosts.

        :param hostnames: host names
        :type hostnames: list
        :param destroy_type: either 'kill' or 'stop'
        :type destroy_type: string
        :param verbose_level: the higher the number, the more verbose
        :type verbose_level: integer
        :param include_data: if true, destroy data containers too.
        :type include_data: boolean
        :param remove_images: if true, destroy will remove the docker images
        :type remove_images: boolean
        :return: Job object
        :rtype: Job
        """
        check_arg(hostnames, u._('Host names'), list)
        check_arg(destroy_type, u._('Destroy type'), str)
        check_arg(verbose_level, u._('Verbose level'), int)
        check_arg(include_data, u._('Include data'), bool)
        check_arg(remove_images, u._('Remove images'), bool)
        if destroy_type not in ['stop', 'kill']:
            raise InvalidArgument(
                u._('Invalid destroy type ({type}). Must be either '
                    '"stop" or "kill".').format(type=destroy_type))

        hostnames = safe_decode(hostnames)
        inventory = Inventory.load()
        inventory.validate_hostnames(hostnames)

        action = KollaAction(verbose_level=verbose_level,
                             playbook_name='destroy.yml')
        ansible_job = action.destroy_hosts(hostnames, destroy_type,
                                           include_data, remove_images)
        return Job(ansible_job)
コード例 #12
0
ファイル: support.py プロジェクト: run4life/kolla-cli
    def support_dump(self, dirpath):
        # type: (str) -> str
        """Dumps configuration data for debugging.

        Dumps most files in /etc/kolla and /usr/share/kolla into a
        tar file so be given to support / development to help with
        debugging problems.

        :param dirpath: path to directory where dump will be placed
        :type dirpath: string
        :return: path to dump file
        :rtype: string
        """
        check_arg(dirpath, u._('Directory path'), str)
        dirpath = safe_decode(dirpath)
        if not os.path.exists(dirpath):
            raise InvalidArgument(
                u._('Directory path: {path} does not exist').format(
                    path=dirpath))
        dumpfile_path = dump(dirpath)
        return dumpfile_path
コード例 #13
0
 def _check_type(self, property_type):
     if property_type is None or property_type not in PROP_TYPES:
         raise InvalidArgument(
             u._('Property Type ({value} is not one of '
                 'global, group or host').format(value=property_type))
コード例 #14
0
ファイル: actions.py プロジェクト: vmlinuxer/kolla-cli
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)