Vinzenz Feenstra has uploaded a new change for review.

Change subject: agent: Implement basics for API Versioning
......................................................................

agent: Implement basics for API Versioning

This commit introduces the basics needed to support API versioning between
the ovirt-guest-agent and VDSM.
The version information will be submitted during the refresh command.
If the version is not part of the refresh message, the API version is
considered as version 0. If the version is higher than known, the highest
supported version is used.
If the versioning is supported, VDSM will retrieve a message with the version
of the API protocol used and it can handle future messages appropriately.

By default both the guest agent and VDSM shall assume a version 0 until
told explicitely otherwise based on a message exchange.

The inital MAX_SUPPORTED_API_VERSION remains 0, since there's no change of API
in this commit.

Change-Id: I754d52009538914dd0143894b24ad48fbf13cb38
Signed-off-by: Vinzenz Feenstra <[email protected]>
---
M ovirt-guest-agent/OVirtAgentLogic.py
1 file changed, 50 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-guest-agent 
refs/changes/95/16995/1

diff --git a/ovirt-guest-agent/OVirtAgentLogic.py 
b/ovirt-guest-agent/OVirtAgentLogic.py
index 43c9635..cb13383 100644
--- a/ovirt-guest-agent/OVirtAgentLogic.py
+++ b/ovirt-guest-agent/OVirtAgentLogic.py
@@ -23,6 +23,8 @@
 from threading import Event
 from VirtIoChannel import VirtIoChannel
 
+_MAX_SUPPORTED_API_VERSION = 0
+
 
 # Return a safe (password masked) repr of the credentials block.
 def safe_creds_repr(creds):
@@ -35,6 +37,7 @@
 
 class DataRetriverBase:
     def __init__(self):
+        self.apiVersion = 0
         self.memStats = {
             'mem_total': 0,
             'mem_free': 0,
@@ -43,6 +46,39 @@
             'swap_out': 0,
             'pageflt': 0,
             'majflt': 0}
+
+    def onAPIVersionUpdated(self, oldVersion, newVersion):
+        pass
+
+    def getAPIVersion(self):
+        return self.apiVersion
+
+    def setAPIVersion(self, version):
+        oldVersion = self.apiVersion
+        try:
+            version = int(version)
+        except Exception:
+            logging.info("Invalid api version value '%s' set. Version value "
+                         "not changed.", version)
+            return
+
+        if _MAX_SUPPORTED_API_VERSION < version:
+            logging.debug("API version requested (%d) higher than known (%d). "
+                          "Using max known version.", version,
+                          _MAX_SUPPORTED_API_VERSION)
+            version = _MAX_SUPPORTED_API_VERSION
+
+        if version == self.apiVersion:
+            logging.debug("API version %d already set, no update necessary",
+                          version)
+            return
+        self.apiVersion = version
+
+        logging.info("API Version updated from %d to %d", oldVersion, version)
+        try:
+            self.onAPIVersionUpdated(oldVersion, version)
+        except Exception:
+            logging.exception("onAPIVersionUpdated failed")
 
     def getMachineName(self):
         pass
@@ -188,6 +224,11 @@
                           % (safe_creds_repr(credentials)))
             self.commandHandler.login(credentials)
         elif command == 'refresh':
+            apiVersion = 0
+            if 'apiVersion' in args:
+                apiVersion = args['apiVersion']
+            self.dr.setAPIVersion(apiVersion)
+            self.sendUsedAPIVersion()
             self.sendUserInfo(True)
             self.sendAppList()
             self.sendInfo()
@@ -202,6 +243,15 @@
             logging.error("Unknown external command: %s (%s)"
                           % (command, args))
 
+    def sendUsedAPIVersion(self):
+        apiVersion = self.dr.getAPIVersion()
+        if apiVersion > 0:
+            logging.debug("Sending API version %d", apiVersion)
+            self.vio.write('api-version', {'version': apiVersion})
+        else:
+            logging.debug("Not sending API version. "
+                          "API versioning not supported by other end.")
+
     def sendUserInfo(self, force=False):
         cur_user = str(self.dr.getActiveUser())
         logging.debug("AgentLogicBase::sendUserInfo - cur_user = '%s'" %


-- 
To view, visit http://gerrit.ovirt.org/16995
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I754d52009538914dd0143894b24ad48fbf13cb38
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-guest-agent
Gerrit-Branch: master
Gerrit-Owner: Vinzenz Feenstra <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to