in azurelinuxagent/common/protocol/goal_state.py [0:0]
def update(self, force_update=False, silent=False):
"""
Updates the current GoalState instance fetching values from the WireServer/HostGAPlugin as needed
"""
self.logger.silent = silent
#
# Fetch the goal state from both the HGAP and the WireServer
#
timestamp = datetime.datetime.utcnow()
if force_update:
message = "Refreshing goal state and vmSettings"
self.logger.info(message)
add_event(op=WALAEventOperation.GoalState, message=message)
incarnation, xml_text, xml_doc = GoalState._fetch_goal_state(self._wire_client)
goal_state_updated = force_update or incarnation != self._incarnation
if goal_state_updated:
message = 'Fetched a new incarnation for the WireServer goal state [incarnation {0}]'.format(incarnation)
self.logger.info(message)
add_event(op=WALAEventOperation.GoalState, message=message)
vm_settings, vm_settings_updated = None, False
if self._goal_state_properties & GoalStateProperties.ExtensionsGoalState:
try:
vm_settings, vm_settings_updated = GoalState._fetch_vm_settings(self._wire_client, force_update=force_update)
except VmSettingsSupportStopped as exception: # If the HGAP stopped supporting vmSettings, we need to use the goal state from the WireServer
self._restore_wire_server_goal_state(incarnation, xml_text, xml_doc, exception)
return
if vm_settings_updated:
self.logger.info('')
message = "Fetched new vmSettings [HostGAPlugin correlation ID: {0} eTag: {1} source: {2}]".format(vm_settings.hostga_plugin_correlation_id, vm_settings.etag, vm_settings.source)
self.logger.info(message)
add_event(op=WALAEventOperation.GoalState, message=message)
# Ignore the vmSettings if their source is Fabric (processing a Fabric goal state may require the tenant certificate and the vmSettings don't include it.)
if vm_settings is not None and vm_settings.source == GoalStateSource.Fabric:
if vm_settings_updated:
message = "The vmSettings originated via Fabric; will ignore them."
self.logger.info(message)
add_event(op=WALAEventOperation.GoalState, message=message)
vm_settings, vm_settings_updated = None, False
# If neither goal state has changed we are done with the update
if not goal_state_updated and not vm_settings_updated:
return
# Start a new history subdirectory and capture the updated goal state
tag = "{0}".format(incarnation) if vm_settings is None else "{0}-{1}".format(incarnation, vm_settings.etag)
if self._save_to_history:
self._history = GoalStateHistory(timestamp, tag)
if goal_state_updated:
self._history.save_goal_state(xml_text)
if vm_settings_updated:
self._history.save_vm_settings(vm_settings.get_redacted_text())
#
# Continue fetching the rest of the goal state
#
extensions_config = None
if goal_state_updated:
extensions_config = self._fetch_full_wire_server_goal_state(incarnation, xml_doc)
#
# Lastly, decide whether to use the vmSettings or extensionsConfig for the extensions goal state
#
if goal_state_updated:
# On rotation of the tenant certificate the vmSettings and extensionsConfig are not updated. However, the incarnation of the WS goal state is update so 'goal_state_updated' will be True.
# In this case, we should use the most recent of vmSettigns and extensionsConfig.
if vm_settings is not None:
most_recent = vm_settings if vm_settings.created_on_timestamp > extensions_config.created_on_timestamp else extensions_config
else:
most_recent = extensions_config
else: # vm_settings_updated
most_recent = vm_settings
if self._extensions_goal_state is None or most_recent.created_on_timestamp >= self._extensions_goal_state.created_on_timestamp:
self._extensions_goal_state = most_recent
#
# Ensure all certificates are downloaded on Fast Track goal states in order to maintain backwards compatibility with previous
# versions of the Agent, which used to download certificates from the WireServer on every goal state. Some customer applications
# depend on this behavior (see https://github.com/Azure/WALinuxAgent/issues/2750).
#
if self._extensions_goal_state.source == GoalStateSource.FastTrack and self._goal_state_properties & GoalStateProperties.Certificates:
self._check_and_download_missing_certs_on_disk()