Esempio n. 1
0
 def is_extension_resource_limits_setup_completed(self, extension_name):
     unit_file_install_path = systemd.get_unit_file_install_path()
     extension_slice_path = os.path.join(unit_file_install_path,
                                         SystemdCgroupsApi.get_extension_slice_name(extension_name))
     if os.path.exists(extension_slice_path):
         return True
     return False
Esempio n. 2
0
        def stop_tracking_extension_cgroups(self, extension_name):
            """
            TODO: remove extension Memory cgroups from tracked list
            """
            try:
                extension_slice_name = SystemdCgroupsApi.get_extension_slice_name(extension_name)
                cgroup_relative_path = os.path.join(_AZURE_VMEXTENSIONS_SLICE,
                                                    extension_slice_name)

                cpu_cgroup_mountpoint, _ = self._cgroups_api.get_cgroup_mount_points()
                cpu_cgroup_path = os.path.join(cpu_cgroup_mountpoint, cgroup_relative_path)

                if cpu_cgroup_path is not None:
                    CGroupsTelemetry.stop_tracking(CpuCgroup(extension_name, cpu_cgroup_path))

            except Exception as exception:
                logger.info("Failed to stop tracking resource usage for the extension service: {0}", ustr(exception))
Esempio n. 3
0
 def remove_extension_slice(self, extension_name):
     """
     This method ensures that the extension slice gets removed from /lib/systemd/system if it exist
     Lastly stop the unit. This would ensure the cleanup the /sys/fs/cgroup controller paths
     """
     if self.enabled():
         unit_file_install_path = systemd.get_unit_file_install_path()
         extension_slice_name = SystemdCgroupsApi.get_extension_slice_name(extension_name)
         extension_slice_path = os.path.join(unit_file_install_path, extension_slice_name)
         if os.path.exists(extension_slice_path):
             self.stop_tracking_extension_cgroups(extension_name)
             CGroupConfigurator._Impl.__cleanup_unit_file(extension_slice_path)
         # stop the unit gracefully; the extensions slices will be removed from /sys/fs/cgroup path
         try:
             logger.info("Executing systemctl stop {0}".format(extension_slice_name))
             shellutil.run_command(["systemctl", "stop", extension_slice_name])
         except Exception as exception:
             _log_cgroup_warning("systemctl stop failed (remove slice): {0}", ustr(exception))
Esempio n. 4
0
        def setup_extension_slice(self, extension_name):
            """
            Each extension runs under its own slice (Ex "Microsoft.CPlat.Extension.slice"). All the slices for
            extensions are grouped under "azure-vmextensions.slice.

            This method ensures that the extension slice is created. Setup should create
            under /lib/systemd/system if it is not exist.
            TODO: set cpu and memory quotas
            """
            if self.enabled():
                unit_file_install_path = systemd.get_unit_file_install_path()
                extension_slice_path = os.path.join(unit_file_install_path,
                                                     SystemdCgroupsApi.get_extension_slice_name(extension_name))
                try:
                    slice_contents = _EXTENSION_SLICE_CONTENTS.format(extension_name=extension_name)
                    CGroupConfigurator._Impl.__create_unit_file(extension_slice_path, slice_contents)
                except Exception as exception:
                    _log_cgroup_warning("Failed to create unit files for the extension slice: {0}", ustr(exception))
                    CGroupConfigurator._Impl.__cleanup_unit_file(extension_slice_path)