def set_extension_services_cpu_memory_quota()

in azurelinuxagent/ga/cgroupconfigurator.py [0:0]


        def set_extension_services_cpu_memory_quota(self, services_list):
            """
            Each extension service will have name, systemd path and it's quotas.
            This method ensure limits set with systemtctl at runtime
            TODO: set memory quotas
            """
            if self.enabled() and services_list is not None:
                for service in services_list:
                    service_name = service.get('name', None)
                    unit_file_path = systemd.get_unit_file_install_path()
                    if service_name is not None and unit_file_path is not None:
                        # remove drop files from disk, new agent use systemdctl set-property
                        files_to_remove = []
                        drop_in_path = os.path.join(unit_file_path, "{0}.d".format(service_name))
                        drop_in_file_cpu_accounting = os.path.join(drop_in_path,
                                                                   _DROP_IN_FILE_CPU_ACCOUNTING)
                        files_to_remove.append(drop_in_file_cpu_accounting)
                        drop_in_file_memory_accounting = os.path.join(drop_in_path,
                                                                      _DROP_IN_FILE_MEMORY_ACCOUNTING)
                        files_to_remove.append(drop_in_file_memory_accounting)

                        drop_in_file_cpu_quota = os.path.join(drop_in_path, _DROP_IN_FILE_CPU_QUOTA)
                        files_to_remove.append(drop_in_file_cpu_quota)
                        self._cleanup_all_files(files_to_remove)

                        cpu_quota = service.get('cpuQuotaPercentage')
                        cpu_quota = "{0}%".format(cpu_quota) if cpu_quota is not None else "infinity"  # following systemd convention for no-quota (infinity)
                        try:
                            properties_to_update, properties_values = self._get_unit_properties_requiring_update(service_name, cpu_quota)
                        except Exception as exception:
                            log_cgroup_warning("Failed to get the properties to update for {0}: {1}".format(service_name, ustr(exception)))
                            # when we fail to get the properties to update, we will skip the set-property and continue for next service
                            continue
                        # If systemd is unaware of extension services and not loaded in the system yet, we get error while setting quotas. Hence, added unit loaded check.
                        if systemd.is_unit_loaded(service_name) and len(properties_to_update) > 0:
                            if cpu_quota != "infinity":
                                log_cgroup_info("Setting {0}'s CPUQuota to {1}".format(service_name, cpu_quota))
                            else:
                                log_cgroup_info("CPUQuota not set for {0}".format(service_name))
                            log_cgroup_info("Setting up resource properties: {0} for {1}" .format(properties_to_update, service_name))
                            try:
                                systemd.set_unit_run_time_properties(service_name, properties_to_update, properties_values)
                            except Exception as exception:
                                log_cgroup_warning("Failed to set the quotas for {0}: {1}".format(service_name, ustr(exception)))