Esempio n. 1
0
 def test_get_handler(self):
     osutil.get_osutil()
     protocol.get_protocol_util()
     dhcp.get_dhcp_handler()
     provision.get_provision_handler()
     deprovision.get_deprovision_handler()
     daemon.get_daemon_handler()
     resourcedisk.get_resourcedisk_handler()
     scvmm.get_scvmm_handler()
     monitor.get_monitor_handler()
     update.get_update_handler()
     exthandlers.get_exthandlers_handler()
Esempio n. 2
0
 def test_get_handler(self):
     osutil.get_osutil()
     protocol.get_protocol_util()
     dhcp.get_dhcp_handler()
     provision.get_provision_handler()
     deprovision.get_deprovision_handler()
     daemon.get_daemon_handler()
     resourcedisk.get_resourcedisk_handler()
     scvmm.get_scvmm_handler()
     monitor.get_monitor_handler()
     update.get_update_handler()
     exthandlers.get_exthandlers_handler()
Esempio n. 3
0
    def test_dhcp_lease_ubuntu(self):
        with patch.object(glob, "glob", return_value=['/var/lib/dhcp/dhclient.eth0.leases']):
            with patch(open_patch(), mock.mock_open(read_data=load_data("dhcp.leases"))):
                endpoint = get_osutil(distro_name='ubuntu', distro_version='12.04').get_dhcp_lease_endpoint()
                self.assertTrue(endpoint is not None)
                self.assertEqual(endpoint, "168.63.129.16")

                endpoint = get_osutil(distro_name='ubuntu', distro_version='12.04').get_dhcp_lease_endpoint()
                self.assertTrue(endpoint is not None)
                self.assertEqual(endpoint, "168.63.129.16")

                endpoint = get_osutil(distro_name='ubuntu', distro_version='14.04').get_dhcp_lease_endpoint()
                self.assertTrue(endpoint is not None)
                self.assertEqual(endpoint, "168.63.129.16")
Esempio n. 4
0
    def test_dhcp_lease_ubuntu(self):
        with patch.object(glob, "glob", return_value=['/var/lib/dhcp/dhclient.eth0.leases']):
            with patch(open_patch(), mock.mock_open(read_data=load_data("dhcp.leases"))):
                endpoint = get_osutil(distro_name='ubuntu', distro_version='12.04').get_dhcp_lease_endpoint()
                self.assertTrue(endpoint is not None)
                self.assertEqual(endpoint, "168.63.129.16")

                endpoint = get_osutil(distro_name='ubuntu', distro_version='12.04').get_dhcp_lease_endpoint()
                self.assertTrue(endpoint is not None)
                self.assertEqual(endpoint, "168.63.129.16")

                endpoint = get_osutil(distro_name='ubuntu', distro_version='14.04').get_dhcp_lease_endpoint()
                self.assertTrue(endpoint is not None)
                self.assertEqual(endpoint, "168.63.129.16")
Esempio n. 5
0
 def __init__(self):
     self.lock = threading.Lock()
     self.lock_wireserver_endpoint = threading.Lock()
     self.protocol = None
     self.endpoint = None
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
Esempio n. 6
0
 def run(self):
     _install.run(self)
     if self.register_service:
         osutil = get_osutil()
         osutil.register_agent_service()
         osutil.stop_agent_service()
         osutil.start_agent_service()
Esempio n. 7
0
 def __init__(self, protocol):
     self.os_util = get_osutil()
     self.protocol = protocol
     self.cryptUtil = CryptUtil(conf.get_openssl_cmd())
     self.remote_access = None
     self.incarnation = 0
     self.error_message = ""
    def __init__(self):
        self.osutil = get_osutil()
        self.protocol_util = get_protocol_util()
        self.imds_client = get_imds_client()

        self.event_thread = None
        self.last_reset_loggers_time = None
        self.last_event_collection = None
        self.last_telemetry_heartbeat = None
        self.last_cgroup_polling_telemetry = None
        self.last_cgroup_report_telemetry = None
        self.last_host_plugin_heartbeat = None
        self.last_imds_heartbeat = None
        self.protocol = None
        self.health_service = None
        self.last_route_table_hash = b''
        self.last_nic_state = {}

        self.counter = 0
        self.sysinfo = []
        self.should_run = True
        self.heartbeat_id = str(uuid.uuid4()).upper()
        self.host_plugin_errorstate = ErrorState(
            min_timedelta=MonitorHandler.HOST_PLUGIN_HEALTH_PERIOD)
        self.imds_errorstate = ErrorState(
            min_timedelta=MonitorHandler.IMDS_HEALTH_PERIOD)
Esempio n. 9
0
 def _evaluate(self):
     if not self._require_64bit or get_osutil().is_64bit:
         d = ','.join(platform.linux_distribution())
         for v in self._versions:
             if re.match(v, d):
                 self._is_supported = True
                 break
Esempio n. 10
0
 def __init__(self):
     self.os_util = get_osutil()
     self.protocol_util = get_protocol_util()
     self.protocol = None
     self.cryptUtil = CryptUtil(conf.get_openssl_cmd())
     self.remote_access = None
     self.incarnation = 0
Esempio n. 11
0
 def __init__(self):
     self.osutil = get_osutil()
     self.endpoint = None
     self.gateway = None
     self.routes = None
     self._request_broadcast = False
     self.skip_cache = False
Esempio n. 12
0
 def __init__(self):
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
     self.stopped = True
     self.hostname = None
     self.dhcpid = None
     self.server_thread=None
Esempio n. 13
0
 def run(self):
     _install.run(self)
     if self.register_service:
         osutil = get_osutil()
         osutil.register_agent_service()
         osutil.stop_agent_service()
         osutil.start_agent_service()
Esempio n. 14
0
 def __init__(self, protocol):
     self._os_util = get_osutil()
     self._protocol = protocol
     self._cryptUtil = CryptUtil(conf.get_openssl_cmd())
     self._remote_access = None
     self._incarnation = 0
     self._check_existing_jit_users = True
Esempio n. 15
0
 def __init__(self):
     self.osutil = get_osutil()
     self.endpoint = None
     self.gateway = None
     self.routes = None
     self._request_broadcast = False
     self.skip_cache = False
Esempio n. 16
0
 def __init__(self):
     self._lock = threading.RLock(
     )  # protects the files on disk created during protocol detection
     self._protocol = None
     self.endpoint = None
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
        def __init__(self):
            """
            Ensures the cgroups file system is mounted and selects the correct API to interact with it
            """
            osutil = get_osutil()

            self._cgroups_supported = osutil.is_cgroups_supported()

            if self._cgroups_supported:
                self._enabled = True
                try:
                    osutil.mount_cgroups()
                    self._cgroups_api = CGroupsApi.create()
                    status = "The cgroup filesystem is ready to use"
                except Exception as e:
                    status = ustr(e)
                    self._enabled = False
            else:
                self._enabled = False
                self._cgroups_api = None
                status = "Cgroups are not supported by the platform"

            logger.info("CGroups Status: {0}".format(status))

            add_event(AGENT_NAME,
                      version=CURRENT_VERSION,
                      op=WALAEventOperation.InitializeCGroups,
                      is_success=self._enabled,
                      message=status,
                      log_event=False)
Esempio n. 18
0
    def __init__(self, verbose, conf_file_path=None):
        """
        Initialize agent running environment.
        """
        self.conf_file_path = conf_file_path
        self.osutil = get_osutil()

        #Init stdout log
        level = logger.LogLevel.VERBOSE if verbose else logger.LogLevel.INFO
        logger.add_logger_appender(logger.AppenderType.STDOUT, level)

        #Init config
        conf_file_path = self.conf_file_path \
                if self.conf_file_path is not None \
                    else self.osutil.get_agent_conf_file_path()
        conf.load_conf_from_file(conf_file_path)

        #Init log
        verbose = verbose or conf.get_logs_verbose()
        level = logger.LogLevel.VERBOSE if verbose else logger.LogLevel.INFO
        logger.add_logger_appender(logger.AppenderType.FILE,
                                   level,
                                   path="/var/log/waagent.log")
        logger.add_logger_appender(logger.AppenderType.CONSOLE,
                                   level,
                                   path="/dev/console")

        #Init event reporter
        event_dir = os.path.join(conf.get_lib_dir(), "events")
        event.init_event_logger(event_dir)
        event.enable_unhandled_err_dump("WALA")
Esempio n. 19
0
    def __init__(self):
        self.event_dir = None
        self.periodic_events = {}

        #
        # All events should have these parameters.
        #
        # The first set comes from the current OS and is initialized here. These values don't change during
        # the agent's lifetime.
        #
        # The next two sets come from the goal state and IMDS and must be explicitly initialized using
        # initialize_vminfo_common_parameters() once a protocol for communication with the host has been
        # created. Their values  don't change during the agent's lifetime. Note that we initialize these
        # parameters here using dummy values (*_UNINITIALIZED) since events sent to the host should always
        # match the schema defined for them in the telemetry pipeline.
        #
        # There is another set of common parameters that must be computed at the time the event is created
        # (e.g. the timestamp and the container ID); those are added to events (along with the parameters
        # below) in _add_common_event_parameters()
        #
        # Note that different kinds of events may also include other parameters; those are added by the
        # corresponding add_* method (e.g. add_metric for performance metrics).
        #
        self._common_parameters = []

        # Parameters from OS
        osutil = get_osutil()
        self._common_parameters.append(
            TelemetryEventParam("OSVersion", EventLogger._get_os_version()))
        self._common_parameters.append(
            TelemetryEventParam("ExecutionMode", AGENT_EXECUTION_MODE))
        self._common_parameters.append(
            TelemetryEventParam("RAM", int(EventLogger._get_ram(osutil))))
        self._common_parameters.append(
            TelemetryEventParam("Processors",
                                int(EventLogger._get_processors(osutil))))

        # Parameters from goal state
        self._common_parameters.append(
            TelemetryEventParam("VMName", "VMName_UNINITIALIZED"))
        self._common_parameters.append(
            TelemetryEventParam("TenantName", "TenantName_UNINITIALIZED"))
        self._common_parameters.append(
            TelemetryEventParam("RoleName", "RoleName_UNINITIALIZED"))
        self._common_parameters.append(
            TelemetryEventParam("RoleInstanceName",
                                "RoleInstanceName_UNINITIALIZED"))
        #
        # # Parameters from IMDS
        self._common_parameters.append(
            TelemetryEventParam('Location', "Location_UNINITIALIZED"))
        self._common_parameters.append(
            TelemetryEventParam('SubscriptionId',
                                "SubscriptionId_UNINITIALIZED"))
        self._common_parameters.append(
            TelemetryEventParam('ResourceGroupName',
                                "ResourceGroupName_UNINITIALIZED"))
        self._common_parameters.append(
            TelemetryEventParam('VMId', "VMId_UNINITIALIZED"))
        self._common_parameters.append(TelemetryEventParam('ImageOrigin', 0))
Esempio n. 20
0
    def __init__(self):
        self.osutil = get_osutil()
        self.imds_client = None

        self.event_thread = None
        self._periodic_operations = [
            ResetPeriodicLogMessagesOperation(),
            PeriodicOperation("collect_and_send_events",
                              self.collect_and_send_events,
                              self.EVENT_COLLECTION_PERIOD),
            ReportNetworkErrorsOperation(),
            PollResourceUsageOperation(),
            PeriodicOperation("send_host_plugin_heartbeat",
                              self.send_host_plugin_heartbeat,
                              self.HOST_PLUGIN_HEARTBEAT_PERIOD),
            PeriodicOperation("send_imds_heartbeat", self.send_imds_heartbeat,
                              self.IMDS_HEARTBEAT_PERIOD),
            ReportNetworkConfigurationChangesOperation(),
        ]
        self.protocol = None
        self.protocol_util = None
        self.health_service = None

        self.should_run = True
        self.heartbeat_id = str(uuid.uuid4()).upper()
        self.host_plugin_errorstate = ErrorState(
            min_timedelta=MonitorHandler.HOST_PLUGIN_HEALTH_PERIOD)
        self.imds_errorstate = ErrorState(
            min_timedelta=MonitorHandler.IMDS_HEALTH_PERIOD)
Esempio n. 21
0
    def __init__(self, verbose):
        """
        Initialize agent running environment.
        """
        self.osutil = get_osutil()
        #Init stdout log
        level = logger.LogLevel.VERBOSE if verbose else logger.LogLevel.INFO
        logger.add_logger_appender(logger.AppenderType.STDOUT, level)

        #Init config
        conf_file_path = self.osutil.get_agent_conf_file_path()
        conf.load_conf_from_file(conf_file_path)

        #Init log
        verbose = verbose or conf.get_logs_verbose()
        level = logger.LogLevel.VERBOSE if verbose else logger.LogLevel.INFO
        logger.add_logger_appender(logger.AppenderType.FILE, level,
                                 path="/var/log/waagent.log")
        logger.add_logger_appender(logger.AppenderType.CONSOLE, level,
                                 path="/dev/console")

        #Init event reporter
        event_dir = os.path.join(conf.get_lib_dir(), "events")
        event.init_event_logger(event_dir)
        event.enable_unhandled_err_dump("WALA")
Esempio n. 22
0
 def __init__(self):
     self.os_util = get_osutil()
     self.protocol_util = get_protocol_util()
     self.protocol = None
     self.cryptUtil = CryptUtil(conf.get_openssl_cmd())
     self.remote_access = None
     self.incarnation = 0
Esempio n. 23
0
 def __init__(self):
     super(ReportNetworkConfigurationChangesOperation,
           self).__init__(name="report network configuration changes",
                          operation=self._operation_impl,
                          period=datetime.timedelta(minutes=1))
     self.osutil = get_osutil()
     self.last_route_table_hash = b''
     self.last_nic_state = {}
Esempio n. 24
0
    def __init__(self, name, cgroup_path):
        super(CpuCgroup, self).__init__(name, cgroup_path,
                                        CGroupContollers.CPU)

        self._osutil = get_osutil()
        self._previous_cgroup_cpu = None
        self._previous_system_cpu = None
        self._current_cgroup_cpu = None
        self._current_system_cpu = None
Esempio n. 25
0
 def __init__(self):
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
     self.protocol_util = get_protocol_util()
     self.stopped = True
     self.hostname = None
     self.dhcpid = None
     self.server_thread = None
     self.dhcp_warning_enabled = True
Esempio n. 26
0
    def setUp(self):
        AgentTestCase.setUp(self)

        self.event_dir = os.path.join(self.tmp_dir, EVENTS_DIRECTORY)
        EventLoggerTools.initialize_event_logger(self.event_dir)
        threading.current_thread().setName("TestEventThread")
        osutil = get_osutil()

        self.expected_common_parameters = {
            # common parameters computed at event creation; the timestamp (stored as the opcode name) is not included
            # here and is checked separately from these parameters
            CommonTelemetryEventSchema.GAVersion:
            CURRENT_AGENT,
            CommonTelemetryEventSchema.ContainerId:
            AgentGlobals.get_container_id(),
            CommonTelemetryEventSchema.EventTid:
            threading.current_thread().ident,
            CommonTelemetryEventSchema.EventPid:
            os.getpid(),
            CommonTelemetryEventSchema.TaskName:
            threading.current_thread().getName(),
            CommonTelemetryEventSchema.KeywordName:
            '',
            # common parameters computed from the OS platform
            CommonTelemetryEventSchema.OSVersion:
            EventLoggerTools.get_expected_os_version(),
            CommonTelemetryEventSchema.ExecutionMode:
            AGENT_EXECUTION_MODE,
            CommonTelemetryEventSchema.RAM:
            int(osutil.get_total_mem()),
            CommonTelemetryEventSchema.Processors:
            osutil.get_processor_cores(),
            # common parameters from the goal state
            CommonTelemetryEventSchema.TenantName:
            'db00a7755a5e4e8a8fe4b19bc3b330c3',
            CommonTelemetryEventSchema.RoleName:
            'MachineRole',
            CommonTelemetryEventSchema.RoleInstanceName:
            'b61f93d0-e1ed-40b2-b067-22c243233448.MachineRole_IN_0',
            # common parameters
            CommonTelemetryEventSchema.Location:
            EventLoggerTools.mock_imds_data['location'],
            CommonTelemetryEventSchema.SubscriptionId:
            EventLoggerTools.mock_imds_data['subscriptionId'],
            CommonTelemetryEventSchema.ResourceGroupName:
            EventLoggerTools.mock_imds_data['resourceGroupName'],
            CommonTelemetryEventSchema.VMId:
            EventLoggerTools.mock_imds_data['vmId'],
            CommonTelemetryEventSchema.ImageOrigin:
            EventLoggerTools.mock_imds_data['image_origin'],
        }

        self.expected_extension_events_params = {
            GuestAgentExtensionEventsSchema.IsInternal: False,
            GuestAgentExtensionEventsSchema.ExtensionType: ""
        }
Esempio n. 27
0
    def get_default_memory_limits(cgroup_name):
        os_util = get_osutil()

        # default values
        mem_limit = max(DEFAULT_MEM_LIMIT_MIN_MB, round(os_util.get_total_mem() * DEFAULT_MEM_LIMIT_PCT / 100, 0))

        # agent values
        if AGENT_CGROUP_NAME.lower() in cgroup_name.lower():
            mem_limit = min(DEFAULT_MEM_LIMIT_MAX_MB, mem_limit)
        return mem_limit
Esempio n. 28
0
 def test_get_processor_cores(self):
     """
     Validate the returned value matches to the one retrieved by invoking shell command
     """
     cmd = "grep 'processor.*:' /proc/cpuinfo |wc -l"
     ret = shellutil.run_get_output(cmd)
     if ret[0] == 0:
         self.assertEqual(int(ret[1]), get_osutil().get_processor_cores())
     else:
         self.fail("Cannot retrieve number of process cores using shell command.")
Esempio n. 29
0
    def __init__(self, name, cgroup_path):
        super(CpuCgroup, self).__init__(name, cgroup_path)

        self._osutil = get_osutil()
        self._previous_cgroup_cpu = None
        self._previous_system_cpu = None
        self._current_cgroup_cpu = None
        self._current_system_cpu = None
        self._previous_throttled_time = None
        self._current_throttled_time = None
Esempio n. 30
0
 def test_dhcp_lease_custom_dns(self):
     """
     Validate that the wireserver address is coming from option 245
     (on default configurations the address is also available in the domain-name-servers option, but users
      may set up a custom dns server on their vnet)
     """
     with patch.object(glob, "glob", return_value=['/var/lib/dhcp/dhclient.eth0.leases']):
         with patch(open_patch(), mock_open(read_data=load_data("dhcp.leases.custom.dns"))):
             endpoint = get_osutil(distro_name='ubuntu', distro_version='14.04').get_dhcp_lease_endpoint()
             self.assertEqual(endpoint, "168.63.129.16")
Esempio n. 31
0
 def test_get_total_mem(self):
     """
     Validate the returned value matches to the one retrieved by invoking shell command
     """
     cmd = "grep MemTotal /proc/meminfo |awk '{print $2}'"
     ret = shellutil.run_get_output(cmd)
     if ret[0] == 0:
         self.assertEqual(int(ret[1]) / 1024, get_osutil().get_total_mem())
     else:
         self.fail("Cannot retrieve total memory using shell command.")
Esempio n. 32
0
 def test_get_processor_cores(self):
     """
     Validate the returned value matches to the one retrieved by invoking shell command
     """
     cmd = "grep 'processor.*:' /proc/cpuinfo |wc -l"
     ret = shellutil.run_get_output(cmd)
     if ret[0] == 0:
         self.assertEqual(int(ret[1]), get_osutil().get_processor_cores())
     else:
         self.fail("Cannot retrieve number of process cores using shell command.")
Esempio n. 33
0
 def test_get_total_mem(self):
     """
     Validate the returned value matches to the one retrieved by invoking shell command
     """
     cmd = "grep MemTotal /proc/meminfo |awk '{print $2}'"
     ret = shellutil.run_get_output(cmd)
     if ret[0] == 0:
         self.assertEqual(int(ret[1]) / 1024, get_osutil().get_total_mem())
     else:
         self.fail("Cannot retrieve total memory using shell command.")
Esempio n. 34
0
 def test_dhcp_lease_custom_dns(self):
     """
     Validate that the wireserver address is coming from option 245
     (on default configurations the address is also available in the domain-name-servers option, but users
      may set up a custom dns server on their vnet)
     """
     with patch.object(glob, "glob", return_value=['/var/lib/dhcp/dhclient.eth0.leases']):
         with patch(open_patch(), mock.mock_open(read_data=load_data("dhcp.leases.custom.dns"))):
             endpoint = get_osutil(distro_name='ubuntu', distro_version='14.04').get_dhcp_lease_endpoint()  # pylint: disable=assignment-from-none
             self.assertEqual(endpoint, "168.63.129.16")
Esempio n. 35
0
    def setUp(self):
        AgentTestCase.setUp(self)

        self.event_dir = os.path.join(self.tmp_dir, EVENTS_DIRECTORY)
        EventLoggerTools.initialize_event_logger(self.event_dir)
        threading.current_thread().setName("TestEventThread")
        osutil = get_osutil()

        self.expected_common_parameters = {
            # common parameters computed at event creation; the timestamp (stored as the opcode name) is not included here and
            # is checked separately from these parameters
            'GAVersion':
            CURRENT_AGENT,
            'ContainerId':
            GoalState.ContainerID,
            'EventTid':
            threading.current_thread().ident,
            'EventPid':
            os.getpid(),
            'TaskName':
            threading.current_thread().getName(),
            'KeywordName':
            '',
            'IsInternal':
            False,
            # common parameters computed from the OS platform
            'OSVersion':
            EventLoggerTools.get_expected_os_version(),
            'ExecutionMode':
            AGENT_EXECUTION_MODE,
            'RAM':
            int(osutil.get_total_mem()),
            'Processors':
            osutil.get_processor_cores(),
            # common parameters from the goal state
            'VMName':
            'MachineRole_IN_0',
            'TenantName':
            'db00a7755a5e4e8a8fe4b19bc3b330c3',
            'RoleName':
            'MachineRole',
            'RoleInstanceName':
            'MachineRole_IN_0',
            # common parameters
            'Location':
            EventLoggerTools.mock_imds_data['location'],
            'SubscriptionId':
            EventLoggerTools.mock_imds_data['subscriptionId'],
            'ResourceGroupName':
            EventLoggerTools.mock_imds_data['resourceGroupName'],
            'VMId':
            EventLoggerTools.mock_imds_data['vmId'],
            'ImageOrigin':
            EventLoggerTools.mock_imds_data['image_origin'],
        }
 def __init__(self):
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
     self.protocol_util = get_protocol_util()
     self.stopped = True
     self.hostname = None
     self.dhcp_id_list = []
     self.server_thread = None
     self.dhcp_warning_enabled = True
     self.last_archive = None
     self.archiver = StateArchiver(conf.get_lib_dir())
Esempio n. 37
0
    def mount_cgroups():
        def cgroup_path(tail=""):
            return os.path.join(CGROUPS_FILE_SYSTEM_ROOT,
                                tail).rstrip(os.path.sep)

        try:
            osutil = get_osutil()
            path = cgroup_path()
            if not os.path.exists(path):
                fileutil.mkdir(path)
                osutil.mount(device='cgroup_root',
                             mount_point=path,
                             option="-t tmpfs",
                             chk_err=False)
            elif not os.path.isdir(cgroup_path()):
                logger.error("Could not mount cgroups: ordinary file at {0}",
                             path)
                return

            controllers_to_mount = ['cpu,cpuacct', 'memory']
            errors = 0
            cpu_mounted = False
            for controller in controllers_to_mount:
                try:
                    target_path = cgroup_path(controller)
                    if not os.path.exists(target_path):
                        fileutil.mkdir(target_path)
                        osutil.mount(
                            device=controller,
                            mount_point=target_path,
                            option="-t cgroup -o {0}".format(controller),
                            chk_err=False)
                        if controller == 'cpu,cpuacct':
                            cpu_mounted = True
                except Exception as exception:
                    errors += 1
                    if errors == len(controllers_to_mount):
                        raise
                    logger.warn("Could not mount cgroup controller {0}: {1}",
                                controller, ustr(exception))

            if cpu_mounted:
                for controller in ['cpu', 'cpuacct']:
                    target_path = cgroup_path(controller)
                    if not os.path.exists(target_path):
                        os.symlink(cgroup_path('cpu,cpuacct'), target_path)

        except OSError as oe:  # pylint: disable=C0103
            # log a warning for read-only file systems
            logger.warn("Could not mount cgroups: {0}", ustr(oe))
            raise
        except Exception as e:  # pylint: disable=C0103
            logger.error("Could not mount cgroups: {0}", ustr(e))
            raise
Esempio n. 38
0
 def __init__(self):
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
     self.protocol_util = get_protocol_util()
     self.stopped = True
     self.hostname = None
     self.dhcp_id = None
     self.server_thread = None
     self.dhcp_warning_enabled = True
     self.last_archive = None
     self.archiver = StateArchiver(conf.get_lib_dir())
Esempio n. 39
0
    def __init__(self, verbose, conf_file_path=None):
        """
        Initialize agent running environment.
        """
        self.conf_file_path = conf_file_path
        self.osutil = get_osutil()

        # Init stdout log
        level = logger.LogLevel.VERBOSE if verbose else logger.LogLevel.INFO
        logger.add_logger_appender(logger.AppenderType.STDOUT, level)

        # Init config
        conf_file_path = self.conf_file_path \
                if self.conf_file_path is not None \
                    else self.osutil.get_agent_conf_file_path()
        conf.load_conf_from_file(conf_file_path)

        # Init log
        verbose = verbose or conf.get_logs_verbose()
        level = logger.LogLevel.VERBOSE if verbose else logger.LogLevel.INFO
        logger.add_logger_appender(logger.AppenderType.FILE,
                                   level,
                                   path=conf.get_agent_log_file())

        # echo the log to /dev/console if the machine will be provisioned
        if conf.get_logs_console() and not ProvisionHandler.is_provisioned():
            self.__add_console_appender(level)

        if event.send_logs_to_telemetry():
            logger.add_logger_appender(logger.AppenderType.TELEMETRY,
                                       logger.LogLevel.WARNING,
                                       path=event.add_log_event)

        ext_log_dir = conf.get_ext_log_dir()
        try:
            if os.path.isfile(ext_log_dir):
                raise Exception("{0} is a file".format(ext_log_dir))
            if not os.path.isdir(ext_log_dir):
                fileutil.mkdir(ext_log_dir, mode=0o755, owner="root")
        except Exception as e:
            logger.error("Exception occurred while creating extension "
                         "log directory {0}: {1}".format(ext_log_dir, e))

        # Init event reporter
        # Note that the reporter is not fully initialized here yet. Some telemetry fields are filled with data
        # originating from the goal state or IMDS, which requires a WireProtocol instance. Once a protocol
        # has been established, those fields must be explicitly initialized using
        # initialize_event_logger_vminfo_common_parameters(). Any events created before that initialization
        # will contain dummy values on those fields.
        event.init_event_status(conf.get_lib_dir())
        event_dir = os.path.join(conf.get_lib_dir(), event.EVENTS_DIRECTORY)
        event.init_event_logger(event_dir)
        event.enable_unhandled_err_dump("WALA")
Esempio n. 40
0
    def get_default_memory_limits(cgroup_name):
        os_util = get_osutil()

        # default values
        mem_limit = max(
            DEFAULT_MEM_LIMIT_MIN_MB,
            round(os_util.get_total_mem() * DEFAULT_MEM_LIMIT_PCT / 100, 0))

        # agent values
        if AGENT_CGROUP_NAME.lower() in cgroup_name.lower():
            mem_limit = min(DEFAULT_MEM_LIMIT_MAX_MB, mem_limit)
        return mem_limit
Esempio n. 41
0
    def __init__(self, cgt):
        """
        Initialize data collection for the Cpu hierarchy. User must call update() before attempting to get
        any useful metrics.

        :param cgt: CGroupsTelemetry
        :return:
        """
        self.cgt = cgt
        self.osutil = get_osutil()
        self.current_cpu_total = self.get_current_cpu_total()
        self.previous_cpu_total = 0
        self.current_system_cpu = self.osutil.get_total_cpu_ticks_since_boot()
        self.previous_system_cpu = 0
Esempio n. 42
0
    def __init__(self, cgt):
        """
        Initialize data collection for the Cpu hierarchy. User must call update() before attempting to get
        any useful metrics.

        :param cgt: CGroupsTelemetry
        :return:
        """
        self.cgt = cgt
        self.osutil = get_osutil()
        self.current_cpu_total = self.get_current_cpu_total()
        self.previous_cpu_total = 0
        self.current_system_cpu = self.osutil.get_total_cpu_ticks_since_boot()
        self.previous_system_cpu = 0
Esempio n. 43
0
    def __init__(self):
        self.osutil = get_osutil()
        self.protocol_util = get_protocol_util()

        self.running = True
        self.last_attempt_time = None

        self.agents = []

        self.child_agent = None
        self.child_launch_time = None
        self.child_launch_attempts = 0
        self.child_process = None

        self.signal_handler = None
Esempio n. 44
0
    def __init__(self, verbose, conf_file_path=None):
        """
        Initialize agent running environment.
        """
        self.conf_file_path = conf_file_path
        self.osutil = get_osutil()

        #Init stdout log
        level = logger.LogLevel.VERBOSE if verbose else logger.LogLevel.INFO
        logger.add_logger_appender(logger.AppenderType.STDOUT, level)

        #Init config
        conf_file_path = self.conf_file_path \
                if self.conf_file_path is not None \
                    else self.osutil.get_agent_conf_file_path()
        conf.load_conf_from_file(conf_file_path)

        #Init log
        verbose = verbose or conf.get_logs_verbose()
        level = logger.LogLevel.VERBOSE if verbose else logger.LogLevel.INFO
        logger.add_logger_appender(logger.AppenderType.FILE, level,
                                 path="/var/log/waagent.log")
        if conf.get_logs_console():
            logger.add_logger_appender(logger.AppenderType.CONSOLE, level,
                    path="/dev/console")
        # See issue #1035
        # logger.add_logger_appender(logger.AppenderType.TELEMETRY,
        #                            logger.LogLevel.WARNING,
        #                            path=event.add_log_event)

        ext_log_dir = conf.get_ext_log_dir()
        try:
            if os.path.isfile(ext_log_dir):
                raise Exception("{0} is a file".format(ext_log_dir))
            if not os.path.isdir(ext_log_dir):
                fileutil.mkdir(ext_log_dir, mode=0o755, owner="root")
        except Exception as e:
            logger.error(
                "Exception occurred while creating extension "
                "log directory {0}: {1}".format(ext_log_dir, e))

        #Init event reporter
        event.init_event_status(conf.get_lib_dir())
        event_dir = os.path.join(conf.get_lib_dir(), "events")
        event.init_event_logger(event_dir)
        event.enable_unhandled_err_dump("WALA")
Esempio n. 45
0
    def __init__(self):
        self.osutil = get_osutil()
        self.protocol_util = get_protocol_util()
        self.imds_client = get_imds_client()

        self.event_thread = None
        self.last_event_collection = None
        self.last_telemetry_heartbeat = None
        self.last_cgroup_telemetry = None
        self.last_host_plugin_heartbeat = None
        self.last_imds_heartbeat = None
        self.protocol = None
        self.health_service = None
        self.last_route_table_hash = b''

        self.counter = 0
        self.sysinfo = []
        self.should_run = True
        self.heartbeat_id = str(uuid.uuid4()).upper()
        self.host_plugin_errorstate = ErrorState(min_timedelta=MonitorHandler.HOST_PLUGIN_HEALTH_PERIOD)
        self.imds_errorstate = ErrorState(min_timedelta=MonitorHandler.IMDS_HEALTH_PERIOD)
Esempio n. 46
0
 def __init__(self):
     self.osutil = get_osutil()
     self.fs = conf.get_resourcedisk_filesystem()
Esempio n. 47
0
 def __init__(self):
     self.osutil = get_osutil()
     self.protocol_util = get_protocol_util()
     signal.signal(signal.SIGINT, self.handle_interrupt_signal)
Esempio n. 48
0
 def __init__(self):
     self.running = True
     self.osutil = get_osutil()
Esempio n. 49
0
 def __init__(self):
     self.osutil = get_osutil()
     self.protocol_util = get_protocol_util()
     self.sysinfo = []
Esempio n. 50
0
 def __init__(self):
     self.osutil = get_osutil()
     self.protocol_util = get_protocol_util()
     self.actions_running = False
     signal.signal(signal.SIGINT, self.handle_interrupt_signal)
Esempio n. 51
0
 def __init__(self):
     self.lock = threading.Lock()
     self.protocol = None
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
Esempio n. 52
0
 def write_provisioned(self):
     fileutil.write_file(
         self.provisioned_file_path(),
         get_osutil().get_instance_id())
Esempio n. 53
0
 def run(self):
     _install.run(self)
     if self.register_service:
         get_osutil().register_agent_service()
Esempio n. 54
0
 def __init__(self):
     self.osutil = get_osutil()