diff options
Diffstat (limited to 'azurelinuxagent/pa')
-rw-r--r-- | azurelinuxagent/pa/deprovision/default.py | 1 | ||||
-rw-r--r-- | azurelinuxagent/pa/provision/cloudinit.py | 11 | ||||
-rw-r--r-- | azurelinuxagent/pa/provision/default.py | 58 | ||||
-rw-r--r-- | azurelinuxagent/pa/provision/factory.py | 2 | ||||
-rw-r--r-- | azurelinuxagent/pa/rdma/suse.py | 29 |
5 files changed, 86 insertions, 15 deletions
diff --git a/azurelinuxagent/pa/deprovision/default.py b/azurelinuxagent/pa/deprovision/default.py index e2c5613..895264a 100644 --- a/azurelinuxagent/pa/deprovision/default.py +++ b/azurelinuxagent/pa/deprovision/default.py @@ -123,6 +123,7 @@ class DeprovisionHandler(object): known_files = [ 'HostingEnvironmentConfig.xml', 'Incarnation', + 'partition', 'Protocol', 'SharedConfig.xml', 'WireServerEndpoint' diff --git a/azurelinuxagent/pa/provision/cloudinit.py b/azurelinuxagent/pa/provision/cloudinit.py index 5789e9a..fa47799 100644 --- a/azurelinuxagent/pa/provision/cloudinit.py +++ b/azurelinuxagent/pa/provision/cloudinit.py @@ -26,9 +26,9 @@ from datetime import datetime import azurelinuxagent.common.conf as conf import azurelinuxagent.common.logger as logger import azurelinuxagent.common.utils.fileutil as fileutil -import azurelinuxagent.common.utils.shellutil as shellutil -from azurelinuxagent.common.event import elapsed_milliseconds +from azurelinuxagent.common.event import elapsed_milliseconds, \ + WALAEventOperation from azurelinuxagent.common.exception import ProvisionError, ProtocolError from azurelinuxagent.common.future import ustr from azurelinuxagent.common.protocol import OVF_FILE_NAME @@ -64,9 +64,12 @@ class CloudInitProvisionHandler(ProvisionHandler): logger.info("Finished provisioning") self.report_ready(thumbprint) - self.report_event("Provision succeed", + self.report_event("Provisioning with cloud-init succeeded", is_success=True, duration=elapsed_milliseconds(utc_start)) + self.report_event(self.create_guest_state_telemetry_messsage(), + is_success=True, + operation=WALAEventOperation.GuestState) except ProvisionError as e: logger.error("Provisioning failed: {0}", ustr(e)) @@ -103,7 +106,7 @@ class CloudInitProvisionHandler(ProvisionHandler): "after {1}s".format(ovf_file_path, max_retry * sleep_time)) - def wait_for_ssh_host_key(self, max_retry=360, sleep_time=5): + def wait_for_ssh_host_key(self, max_retry=1800, sleep_time=1): """ Wait for cloud-init to generate ssh host key """ diff --git a/azurelinuxagent/pa/provision/default.py b/azurelinuxagent/pa/provision/default.py index 2f7ec18..44e171b 100644 --- a/azurelinuxagent/pa/provision/default.py +++ b/azurelinuxagent/pa/provision/default.py @@ -22,6 +22,8 @@ Provision handler import os import os.path import re +import socket +import time from datetime import datetime @@ -87,10 +89,14 @@ class ProvisionHandler(object): self.write_provisioned() - self.report_event("Provision succeed", + self.report_event("Provisioning succeeded", is_success=True, duration=elapsed_milliseconds(utc_start)) + self.report_event(self.create_guest_state_telemetry_messsage(), + is_success=True, + operation=WALAEventOperation.GuestState) + self.report_ready(thumbprint) logger.info("Provisioning complete") @@ -244,9 +250,14 @@ class ProvisionHandler(object): fileutil.write_file(customdata_file, customdata) if conf.get_execute_customdata(): + start = time.time() logger.info("Execute custom data") os.chmod(customdata_file, 0o700) shellutil.run(customdata_file) + add_event(name=AGENT_NAME, + duration=int(time.time() - start), + is_success=True, + op=WALAEventOperation.CustomData) def deploy_ssh_pubkeys(self, ovfenv): for pubkey in ovfenv.ssh_pubkeys: @@ -258,12 +269,53 @@ class ProvisionHandler(object): logger.info("Deploy ssh key pairs.") self.osutil.deploy_ssh_keypair(ovfenv.username, keypair) - def report_event(self, message, is_success=False, duration=0): + def report_event(self, message, is_success=False, duration=0, + operation=WALAEventOperation.Provision): add_event(name=AGENT_NAME, message=message, duration=duration, is_success=is_success, - op=WALAEventOperation.Provision) + op=operation) + + def get_cpu_count(self): + try: + count = len([x for x in open('/proc/cpuinfo').readlines() + if x.startswith("processor")]) + return count + except Exception as e: + logger.verbose(u"Failed to determine the CPU count: {0}.", ustr(e)) + pass + return -1 + + def get_mem_size_mb(self): + try: + for line in open('/proc/meminfo').readlines(): + m = re.match('^MemTotal:\s*(\d+) kB$', line) + if m is not None: + return int(int(m.group(1)) / 1024) + except Exception as e: + logger.verbose(u"Failed to determine the memory size: {0}..", ustr(e)) + pass + return -1 + + def create_guest_state_telemetry_messsage(self): + """ + Create a GuestState JSON message that contains the current CPU, Memory + (MB), and hostname of the guest. + + e.g. + + { + "cpu": 1, + "mem": 1024, + "hostname": "server1234" + } + """ + cpu = self.get_cpu_count() + mem = self.get_mem_size_mb() + + return """{{"cpu": {0}, "mem": {1}, "hostname": "{2}"}}"""\ + .format(cpu, mem, socket.gethostname()) def report_not_ready(self, sub_status, description): status = ProvisionStatus(status="NotReady", subStatus=sub_status, diff --git a/azurelinuxagent/pa/provision/factory.py b/azurelinuxagent/pa/provision/factory.py index d87765f..9e88618 100644 --- a/azurelinuxagent/pa/provision/factory.py +++ b/azurelinuxagent/pa/provision/factory.py @@ -16,9 +16,7 @@ # import azurelinuxagent.common.conf as conf -import azurelinuxagent.common.logger as logger -from azurelinuxagent.common.utils.textutil import Version from azurelinuxagent.common.version import DISTRO_NAME, DISTRO_VERSION, \ DISTRO_FULL_NAME diff --git a/azurelinuxagent/pa/rdma/suse.py b/azurelinuxagent/pa/rdma/suse.py index 20f06cd..2b6ae29 100644 --- a/azurelinuxagent/pa/rdma/suse.py +++ b/azurelinuxagent/pa/rdma/suse.py @@ -1,6 +1,6 @@ # Microsoft Azure Linux Agent # -# Copyright 2014 Microsoft Corporation +# Copyright 2017 Microsoft Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ # import glob -import os import azurelinuxagent.common.logger as logger import azurelinuxagent.common.utils.shellutil as shellutil from azurelinuxagent.common.rdma import RDMAHandler @@ -37,8 +36,10 @@ class SUSERDMAHandler(RDMAHandler): return zypper_install = 'zypper -n in %s' zypper_install_noref = 'zypper -n --no-refresh in %s' + zypper_lock = 'zypper addlock %s' zypper_remove = 'zypper -n rm %s' zypper_search = 'zypper -n se -s %s' + zypper_unlock = 'zypper removelock %s' package_name = 'msft-rdma-kmp-default' cmd = zypper_search % package_name status, repo_package_info = shellutil.run_get_output(cmd) @@ -54,13 +55,19 @@ class SUSERDMAHandler(RDMAHandler): installed = sections[0].strip() version = sections[3].strip() driver_package_versions.append(version) - if fw_version in version and installed == 'i': + if fw_version in version and installed.startswith('i'): info_msg = 'RDMA: Matching driver package "%s-%s" ' info_msg += 'is already installed, nothing to do.' logger.info(info_msg % (package_name, version)) return True - if installed == 'i': + if installed.startswith('i'): + # A driver with a different version is installed driver_package_installed = True + cmd = zypper_unlock % package_name + result = shellutil.run(cmd) + info_msg = 'Driver with different version installed ' + info_msg += 'unlocked package "%s".' + logger.info(info_msg % (package_name)) # If we get here the driver package is installed but the # version doesn't match or no package is installed @@ -80,11 +87,11 @@ class SUSERDMAHandler(RDMAHandler): logger.info("RDMA: looking for fw version %s in packages" % fw_version) for entry in driver_package_versions: - if not fw_version in version: + if fw_version not in entry: logger.info("Package '%s' is not a match." % entry) else: logger.info("Package '%s' is a match. Installing." % entry) - complete_name = '%s-%s' % (package_name, version) + complete_name = '%s-%s' % (package_name, entry) cmd = zypper_install % complete_name result = shellutil.run(cmd) if result: @@ -94,6 +101,11 @@ class SUSERDMAHandler(RDMAHandler): msg = 'RDMA: Successfully installed "%s" from ' msg += 'configured repositories' logger.info(msg % complete_name) + # Lock the package so it does not accidentally get updated + cmd = zypper_lock % package_name + result = shellutil.run(cmd) + info_msg = 'Applied lock to "%s"' % package_name + logger.info(info_msg) if not self.load_driver_module() or requires_reboot: self.reboot_system() return True @@ -119,6 +131,11 @@ class SUSERDMAHandler(RDMAHandler): msg = 'RDMA: Successfully installed "%s" from ' msg += 'local package cache' logger.info(msg % (local_package)) + # Lock the package so it does not accidentally get updated + cmd = zypper_lock % package_name + result = shellutil.run(cmd) + info_msg = 'Applied lock to "%s"' % package_name + logger.info(info_msg) if not self.load_driver_module() or requires_reboot: self.reboot_system() return True |