def property_clear(self, property_list, property_type=GLOBAL_TYPE, change_set=None): # type: (List[str], str, List[str]) -> None """Clear a property :param property_list: property list :type property_list: list :param property_type: one of 'global', 'group' or 'host' :type property_type: string :param change_set: for group or host clears this is the list of groups or hosts to clear the property for :type change_set: list of strings """ check_arg(property_list, u._('Property List'), list) property_list = safe_decode(property_list) 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) ansible_properties = AnsibleProperties() if property_type == GLOBAL_TYPE: ansible_properties.clear_property(property_list) elif property_type == GROUP_TYPE: ansible_properties.clear_group_property(property_list, change_set) else: ansible_properties.clear_host_property(property_list, change_set)
def password_clear(self, name): # type: (str) -> None """Clear password :param name: name of the password :type name: string """ check_arg(name, u._('Password name'), str) clear_password(name)
def password_clear(self, name): # type: (str) -> None """Clear password :param name: name of the password :type name: string """ password_name_string = u._('Password name') check_arg(name, password_name_string, str) disallow_chars(name, password_name_string, '\'') clear_password(name)
def group_get(self, groupnames): # type: (List[str]) -> List[Group] """Get selected groups in the inventory :param groupnames: names of groups to be read :type groupnames: list of strings :return: groups :rtype: list of Group objects """ check_arg(groupnames, u._('Group names'), list) groupnames = safe_decode(groupnames) return self._get_groups(groupnames)
def service_get(self, servicenames): # type: (List[str]) -> List[Service] """Get selected services in the inventory :param servicenames: names of services to be read :type servicenames: list of strings :return: services :rtype: list of Service objects """ check_arg(servicenames, u._('Service names'), list) servicenames = safe_decode(servicenames) return self._get_services(servicenames)
def pull(verbose_level=1): """Pull. Pull container images onto appropriate hosts. :param verbose_level: the higher the number, the more verbose :type verbose_level: integer :return: Job object :rtype: Job """ check_arg(verbose_level, u._('Verbose level'), int) ansible_job = actions.pull(verbose_level) return Job(ansible_job)
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)
def reconfigure(verbose_level=1): # type: (int) -> Job """Reconfigure. Reconfigure containers on hosts. :param verbose_level: the higher the number, the more verbose :type verbose_level: integer :return: Job object :rtype: Job """ check_arg(verbose_level, u._('Verbose level'), int) ansible_job = actions.reconfigure(verbose_level) return Job(ansible_job)
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)
def certificate_init(verbose_level=1): """Certificate Init. Creates a self-signed certificate for secure TLS communication. :param verbose_level: the higher the number, the more verbose :type verbose_level: integer :return: Job object :rtype: Job """ check_arg(verbose_level, u._('Verbose level'), int) action = KollaAction(verbose_level=verbose_level, playbook_name='certificates.yml') ansible_job = action.certificate_init() return Job(ansible_job)
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)
def postdeploy(verbose_level=1): """Post-Deploy. Do post deploy on deploy node. :param verbose_level: the higher the number, the more verbose :type verbose_level: integer :return: Job object :rtype: Job """ check_arg(verbose_level, u._('Verbose level'), int) action = KollaAction(verbose_level=verbose_level, playbook_name='post-deploy.yml') ansible_job = action.postdeploy() return Job(ansible_job)
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)
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)
def password_set(self, name, value): # type: (str, str) -> None """Set password :param name: name of the password :type name: string :param value: value of the password :type value: string """ check_arg(name, u._('Password name'), str) check_arg(value, u._('Password value'), str, display_param=False, empty_ok=True, none_ok=True) set_password(name, value)
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)
def host_get(hostnames): # type: (List[str]) -> List[Host] """Get selected hosts in the inventory :param hostnames: list of strings :return: hosts :rtype: list of Host objects """ check_arg(hostnames, u._('Host names'), list) hostnames = safe_decode(hostnames) inventory = Inventory.load() inventory.validate_hostnames(hostnames) hosts = [] host_groups = inventory.get_host_groups() for hostname in hostnames: hosts.append(Host(hostname, host_groups[hostname])) return hosts
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)
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)
def host_setup(hosts_info): # type: (Dict[str,Dict[str,object]]) -> None """Setup multiple hosts for ssh access hosts_info is a dictionary of form: - {hostname': { 'password': password 'uname': user_name}, ... } The uname entry is optional. :param hosts_info: dictionary """ check_arg(hosts_info, u._('Hosts info'), dict) inventory = Inventory.load() inventory.validate_hostnames(hosts_info.keys()) inventory.setup_hosts(hosts_info)
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)
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)
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)
def host_ssh_check(hostnames): # type: (List[str]) -> Dict[str,Dict[str,object]] """Check hosts for ssh connectivity Check status is a dictionary of form: - {hostname: { 'success':<True|False>, 'msg':message_string}, ... } :param hostnames: list of strings :return: check status :rtype: dictionary """ check_arg(hostnames, u._('Host names'), list) inventory = Inventory.load() hostnames = safe_decode(hostnames) inventory.validate_hostnames(hostnames) summary = inventory.ssh_check_hosts(hostnames) return summary
def password_set(self, name, value): # type: (str, str) -> None """Set password :param name: name of the password :type name: string :param value: value of the password :type value: string """ password_name_string = u._('Password name') password_value_string = u._('Password value') check_arg(name, password_name_string, str) disallow_chars(name, password_name_string, '\'') check_arg(value, password_value_string, str, display_param=False, empty_ok=True, none_ok=True) disallow_chars(value, password_value_string, '\'') set_password(name, value)
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
def stop(verbose_level=1, hostnames=[], servicenames=[]): # type: (int, List[str], List[str]) -> Job """Stop Hosts. Stops all kolla related docker containers on the specified hosts. :param hostnames: host names :type hostnames: list :param verbose_level: the higher the number, the more verbose :type verbose_level: integer :param servicenames: services to stop. If empty, then stop all. :type servicenames: list of strings :return: Job object :rtype: Job """ check_arg(verbose_level, u._('Verbose level'), int) check_arg(hostnames, u._('Host names'), list, empty_ok=True, none_ok=True) check_arg(servicenames, u._('Service names'), list, empty_ok=True, none_ok=True) check_kolla_args(hostnames=hostnames, servicenames=servicenames) hostnames = safe_decode(hostnames) servicenames = safe_decode(servicenames) action = KollaAction(verbose_level=verbose_level, playbook_name='site.yml') ansible_job = action.stop(hostnames, servicenames) return Job(ansible_job)
def check(verbose_level=1, hostnames=[], servicenames=[]): # type: (int, List[str], List[str]) -> Job """Do post-deployment smoke tests. :param hostnames: host names :type hostnames: list :param verbose_level: the higher the number, the more verbose :type verbose_level: integer :param servicenames: services to check. If empty, then check all. :type servicenames: list of strings :return: Job object :rtype: Job """ check_arg(verbose_level, u._('Verbose level'), int) check_arg(hostnames, u._('Host names'), list, empty_ok=True, none_ok=True) check_arg(servicenames, u._('Service names'), list, empty_ok=True, none_ok=True) check_kolla_args(servicenames=servicenames) hostnames = safe_decode(hostnames) servicenames = safe_decode(servicenames) action = KollaAction(verbose_level=verbose_level, playbook_name='site.yml') ansible_job = action.check(hostnames, servicenames) return Job(ansible_job)
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)
def pull(verbose_level=1, hostnames=[], servicenames=[]): """Pull. Pull all images for containers (only pulls, no running container). :param verbose_level: the higher the number, the more verbose :param hostnames: hosts to pull to. If empty, then pull to all. :type hostnames: list of strings :type verbose_level: integer :param servicenames: services to pull. If empty, then pull all. :return: Job object :rtype: Job """ check_arg(hostnames, u._('Host names'), list, empty_ok=True, none_ok=True) check_arg(verbose_level, u._('Verbose level'), int) check_arg(servicenames, u._('Service names'), list, empty_ok=True, none_ok=True) check_kolla_args(hostnames=hostnames, servicenames=servicenames) hostnames = safe_decode(hostnames) servicenames = safe_decode(servicenames) action = KollaAction(verbose_level=verbose_level, playbook_name='site.yml') ansible_job = action.pull(hostnames, servicenames) return Job(ansible_job)