Example #1
0
    def get_vmagent_manifests(self):
        self.update_goal_state()

        headers = None if self.agent_etag is None else {IF_NONE_MATCH_HEADER: self.agent_etag}

        data, etag = self._get_data(self.vmagent_uri, headers=headers)
        if self.agent_etag is None or self.agent_etag != etag:
            self.agent_etag = etag

            # Create a list with a single manifest
            # -- The protocol lacks "family," use the configured family
            self.agent_manifests = VMAgentManifestList()

            manifest = VMAgentManifest()
            manifest.family = family=conf.get_autoupdate_gafamily()
            
            if not KEY_AGENT_VERSION_URIS in data:
                raise ProtocolError(
                    "Agent versions missing '{0}': {1}".format(
                        KEY_AGENT_VERSION_URIS, data))

            for version in data[KEY_AGENT_VERSION_URIS]:
                if not KEY_URI in version:
                    raise ProtocolError(
                        "Agent versions missing '{0': {1}".format(
                            KEY_URI, data))
                manifest_uri = VMAgentManifestUri(uri=version[KEY_URI])
                manifest.versionsManifestUris.append(manifest_uri)
        
            self.agent_manifests.vmAgentManifests.append(manifest)
        
        return self.agent_manifests, self.agent_etag
Example #2
0
    def get_vmagent_manifests(self):
        self.update_goal_state()

        data, etag = self._get_data(self.vmagent_uri)
        if self.agent_etag is None or self.agent_etag < etag:
            self.agent_etag = etag

            # Create a list with a single manifest
            # -- The protocol lacks "family," use the configured family
            self.agent_manifests = VMAgentManifestList()

            manifest = VMAgentManifest()
            manifest.family = family = conf.get_autoupdate_gafamily()

            if not KEY_AGENT_VERSION_URIS in data:
                raise ProtocolError("Agent versions missing '{0}': {1}".format(
                    KEY_AGENT_VERSION_URIS, data))

            for version in data[KEY_AGENT_VERSION_URIS]:
                if not KEY_URI in version:
                    raise ProtocolError(
                        "Agent versions missing '{0': {1}".format(
                            KEY_URI, data))
                manifest_uri = VMAgentManifestUri(uri=version[KEY_URI])
                manifest.versionsManifestUris.append(manifest_uri)

            self.agent_manifests.vmAgentManifests.append(manifest)

        return self.agent_manifests, self.agent_etag
Example #3
0
    def _upgrade_available(self, protocol, base_version=CURRENT_VERSION):
        # Ignore new agents if updating is disabled
        if not conf.get_autoupdate_enabled():
            return False

        now = time.time()
        if self.last_attempt_time is not None:
            next_attempt_time = self.last_attempt_time + \
                                    conf.get_autoupdate_frequency()
        else:
            next_attempt_time = now
        if next_attempt_time > now:
            return False

        family = conf.get_autoupdate_gafamily()
        logger.info("Checking for agent updates (family: {0})", family)

        self.last_attempt_time = now

        try:
            manifest_list, etag = protocol.get_vmagent_manifests()

            manifests = [m for m in manifest_list.vmAgentManifests \
                            if m.family == family and len(m.versionsManifestUris) > 0]
            if len(manifests) == 0:
                logger.verbose(u"Incarnation {0} has no {1} agent updates",
                               etag, family)
                return False

            pkg_list = protocol.get_vmagent_pkgs(manifests[0])

            # Set the agents to those available for download at least as
            # current as the existing agent and remove from disk any agent
            # no longer reported to the VM.
            # Note:
            #  The code leaves on disk available, but blacklisted, agents
            #  so as to preserve the state. Otherwise, those agents could be
            #  again downloaded and inappropriately retried.
            host = self._get_host_plugin(protocol=protocol)
            self._set_agents(
                [GuestAgent(pkg=pkg, host=host) for pkg in pkg_list.versions])

            self._purge_agents()
            self._filter_blacklisted_agents()

            # Return True if current agent is no longer available or an
            # agent with a higher version number is available
            return not self._is_version_eligible(base_version) \
                or (len(self.agents) > 0 and self.agents[0].version > base_version)

        except Exception as e:
            msg = u"Exception retrieving agent manifests: {0}".format(
                ustr(traceback.format_exc()))
            add_event(AGENT_NAME,
                      op=WALAEventOperation.Download,
                      version=CURRENT_VERSION,
                      is_success=False,
                      message=msg)
            return False
Example #4
0
    def _upgrade_available(self, base_version=CURRENT_VERSION):
        # Ignore new agents if updating is disabled
        if not conf.get_autoupdate_enabled():
            return False

        now = time.time()
        if self.last_attempt_time is not None:
            next_attempt_time = self.last_attempt_time + conf.get_autoupdate_frequency()
        else:
            next_attempt_time = now
        if next_attempt_time > now:
            return False

        family = conf.get_autoupdate_gafamily()
        logger.verbose("Checking for agent family {0} updates", family)

        self.last_attempt_time = now
        try:
            protocol = self.protocol_util.get_protocol()
            manifest_list, etag = protocol.get_vmagent_manifests()
        except Exception as e:
            msg = u"Exception retrieving agent manifests: {0}".format(ustr(e))
            logger.warn(msg)
            add_event(
                AGENT_NAME,
                op=WALAEventOperation.Download,
                version=CURRENT_VERSION,
                is_success=False,
                message=msg)
            return False

        manifests = [m for m in manifest_list.vmAgentManifests \
                        if m.family == family and len(m.versionsManifestUris) > 0]
        if len(manifests) == 0:
            logger.verbose(u"Incarnation {0} has no agent family {1} updates", etag, family)
            return False

        try:
            pkg_list = protocol.get_vmagent_pkgs(manifests[0])
        except ProtocolError as e:
            msg = u"Incarnation {0} failed to get {1} package list: " \
                  u"{2}".format(
                etag,
                family,
                ustr(e))
            logger.warn(msg)
            add_event(
                AGENT_NAME,
                op=WALAEventOperation.Download,
                version=CURRENT_VERSION,
                is_success=False,
                message=msg)
            return False

        # Set the agents to those available for download at least as current
        # as the existing agent and remove from disk any agent no longer
        # reported to the VM.
        # Note:
        #  The code leaves on disk available, but blacklisted, agents so as to
        #  preserve the state. Otherwise, those agents could be again
        #  downloaded and inappropriately retried.
        host = None
        if protocol and protocol.client:
            host = protocol.client.get_host_plugin()
        self._set_agents([GuestAgent(pkg=pkg, host=host) for pkg in pkg_list.versions])
        self._purge_agents()
        self._filter_blacklisted_agents()

        # Return True if agents more recent than the current are available
        return len(self.agents) > 0 and self.agents[0].version > base_version
Example #5
0
    def _upgrade_available(self, base_version=CURRENT_VERSION):
        # Ignore new agents if updating is disabled
        if not conf.get_autoupdate_enabled():
            return False

        now = time.time()
        if self.last_attempt_time is not None:
            next_attempt_time = self.last_attempt_time + conf.get_autoupdate_frequency(
            )
        else:
            next_attempt_time = now
        if next_attempt_time > now:
            return False

        family = conf.get_autoupdate_gafamily()
        logger.info("Checking for agent family {0} updates", family)

        self.last_attempt_time = now
        try:
            protocol = self.protocol_util.get_protocol()
            manifest_list, etag = protocol.get_vmagent_manifests()
        except Exception as e:
            msg = u"Exception retrieving agent manifests: {0}".format(ustr(e))
            logger.warn(msg)
            add_event(AGENT_NAME,
                      op=WALAEventOperation.Download,
                      version=CURRENT_VERSION,
                      is_success=False,
                      message=msg)
            return False

        manifests = [m for m in manifest_list.vmAgentManifests \
                        if m.family == family and len(m.versionsManifestUris) > 0]
        if len(manifests) == 0:
            logger.info(u"Incarnation {0} has no agent family {1} updates",
                        etag, family)
            return False

        try:
            pkg_list = protocol.get_vmagent_pkgs(manifests[0])
        except ProtocolError as e:
            msg = u"Incarnation {0} failed to get {1} package list: " \
                  u"{2}".format(
                etag,
                family,
                ustr(e))
            logger.warn(msg)
            add_event(AGENT_NAME,
                      op=WALAEventOperation.Download,
                      version=CURRENT_VERSION,
                      is_success=False,
                      message=msg)
            return False

        # Set the agents to those available for download at least as current
        # as the existing agent and remove from disk any agent no longer
        # reported to the VM.
        # Note:
        #  The code leaves on disk available, but blacklisted, agents so as to
        #  preserve the state. Otherwise, those agents could be again
        #  downloaded and inappropriately retried.
        self._set_agents([GuestAgent(pkg=pkg) for pkg in pkg_list.versions])
        self._purge_agents()
        self._filter_blacklisted_agents()

        # Return True if agents more recent than the current are available
        return len(self.agents) > 0 and self.agents[0].version > base_version
Example #6
0
    def _upgrade_available(self, base_version=CURRENT_VERSION):
        # Emit an event expressing the state of AutoUpdate
        # Note:
        # - Duplicate events get suppressed; state transitions always emit
        add_event(AGENT_NAME,
                  version=CURRENT_VERSION,
                  op=WALAEventOperation.AutoUpdate,
                  is_success=conf.get_autoupdate_enabled())

        # Ignore new agents if updating is disabled
        if not conf.get_autoupdate_enabled():
            return False

        now = time.time()
        if self.last_attempt_time is not None:
            next_attempt_time = self.last_attempt_time + \
                                    conf.get_autoupdate_frequency()
        else:
            next_attempt_time = now
        if next_attempt_time > now:
            return False

        family = conf.get_autoupdate_gafamily()
        logger.verbose("Checking for agent family {0} updates", family)

        self.last_attempt_time = now
        protocol = self.protocol_util.get_protocol()

        for update_goal_state in [False, True]:
            try:
                if update_goal_state:
                    protocol.update_goal_state(forced=True)

                manifest_list, etag = protocol.get_vmagent_manifests()

                manifests = [m for m in manifest_list.vmAgentManifests \
                                if m.family == family and \
                                    len(m.versionsManifestUris) > 0]
                if len(manifests) == 0:
                    logger.verbose(u"Incarnation {0} has no {1} agent updates",
                                   etag, family)
                    return False

                pkg_list = protocol.get_vmagent_pkgs(manifests[0])

                # Set the agents to those available for download at least as
                # current as the existing agent and remove from disk any agent
                # no longer reported to the VM.
                # Note:
                #  The code leaves on disk available, but blacklisted, agents
                #  so as to preserve the state. Otherwise, those agents could be
                #  again downloaded and inappropriately retried.
                host = self._get_host_plugin(protocol=protocol)
                self._set_agents([GuestAgent(pkg=pkg, host=host) \
                                     for pkg in pkg_list.versions])

                self._purge_agents()
                self._evaluate_deployments()
                self._filter_blacklisted_agents()

                # Return True if current agent is no longer available or an
                # agent with a higher version number is available
                return not self._is_version_eligible(base_version) \
                    or (len(self.agents) > 0 \
                        and self.agents[0].version > base_version)

            except Exception as e:
                if isinstance(e, ResourceGoneError):
                    continue

                msg = u"Exception retrieving agent manifests: {0}".format(
                    ustr(e))
                logger.warn(msg)
                add_event(AGENT_NAME,
                          op=WALAEventOperation.Download,
                          version=CURRENT_VERSION,
                          is_success=False,
                          message=msg)
                return False
Example #7
0
    def _upgrade_available(self, base_version=CURRENT_VERSION):
        # Emit an event expressing the state of AutoUpdate
        # Note:
        # - Duplicate events get suppressed; state transitions always emit
        add_event(
            AGENT_NAME,
            version=CURRENT_VERSION,
            op=WALAEventOperation.AutoUpdate,
            is_success=conf.get_autoupdate_enabled())

        # Ignore new agents if updating is disabled
        if not conf.get_autoupdate_enabled():
            return False

        now = time.time()
        if self.last_attempt_time is not None:
            next_attempt_time = self.last_attempt_time + \
                                    conf.get_autoupdate_frequency()
        else:
            next_attempt_time = now
        if next_attempt_time > now:
            return False

        family = conf.get_autoupdate_gafamily()
        logger.verbose("Checking for agent family {0} updates", family)

        self.last_attempt_time = now
        protocol = self.protocol_util.get_protocol()

        for update_goal_state in [False, True]:
            try:
                if update_goal_state:
                    protocol.update_goal_state(forced=True)

                manifest_list, etag = protocol.get_vmagent_manifests()

                manifests = [m for m in manifest_list.vmAgentManifests \
                                if m.family == family and \
                                    len(m.versionsManifestUris) > 0]
                if len(manifests) == 0:
                    logger.verbose(u"Incarnation {0} has no {1} agent updates",
                                    etag, family)
                    return False

                pkg_list = protocol.get_vmagent_pkgs(manifests[0])

                # Set the agents to those available for download at least as
                # current as the existing agent and remove from disk any agent
                # no longer reported to the VM.
                # Note:
                #  The code leaves on disk available, but blacklisted, agents
                #  so as to preserve the state. Otherwise, those agents could be
                #  again downloaded and inappropriately retried.
                host = self._get_host_plugin(protocol=protocol)
                self._set_agents([GuestAgent(pkg=pkg, host=host) \
                                     for pkg in pkg_list.versions])

                self._purge_agents()
                self._filter_blacklisted_agents()

                # Return True if current agent is no longer available or an
                # agent with a higher version number is available
                return not self._is_version_eligible(base_version) \
                    or (len(self.agents) > 0 \
                        and self.agents[0].version > base_version)

            except Exception as e:
                if isinstance(e, ResourceGoneError):
                    continue

                msg = u"Exception retrieving agent manifests: {0}".format(
                            ustr(traceback.format_exc()))
                logger.warn(msg)
                add_event(
                    AGENT_NAME,
                    op=WALAEventOperation.Download,
                    version=CURRENT_VERSION,
                    is_success=False,
                    message=msg)
                return False