Skip to content

Commit

Permalink
Add the pyVmomi version in the user-agent request header
Browse files Browse the repository at this point in the history
This change adds a project wide variable to hold the current pyVmomi version - version_info. Based of https://docs.python.org/3/library/sys.html#sys.version_info
Another variable holds a text version of version_info and extends the User-Agent header - version_info_str.
  • Loading branch information
ddraganov committed Jan 29, 2024
1 parent 4bc1f52 commit 5ad215f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pyVmomi/SoapAdapter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# **********************************************************
# Copyright (c) 2005-2023 VMware, Inc.
# Copyright (c) 2005-2024 VMware, Inc. All rights reserved.
# **********************************************************

import base64
Expand Down Expand Up @@ -35,6 +35,7 @@
IsChildVersion, ManagedMethod, UnknownManagedMethod, ManagedObject,
Object, PropertyPath, Type, binary, versionIdMap, versionMap)
from .Security import VerifyCertThumbprint
from . import version_info_str
from . import _legacyThumbprintException
if _legacyThumbprintException:
from .Security import ThumbprintMismatchException # noqa: F401
Expand Down Expand Up @@ -1518,8 +1519,12 @@ def InvokeMethod(self, mo, info, args, outerStub=None):
'Content-Type':
'text/xml; charset={0}'.format(XML_ENCODING),
'User-Agent':
'pyvmomi Python/{0} ({1}; {2}; {3})'.format(
PYTHON_VERSION, OS_NAME, OS_VERSION, OS_ARCH)
'pyvmomi {0} Python/{1} ({2}; {3}; {4})'.format(
version_info_str,
PYTHON_VERSION,
OS_NAME,
OS_VERSION,
OS_ARCH)
}
if self._customHeaders:
headers.update(self._customHeaders)
Expand Down
12 changes: 11 additions & 1 deletion pyVmomi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# **********************************************************
# Copyright (c) 2005-2023 VMware, Inc.
# Copyright (c) 2005-2024 VMware, Inc.
# **********************************************************

import sys
import importlib

version_info = (
8,
0,
2,
0,
1,
)

version_info_str = ".".join(str(v) for v in version_info)

if sys.version_info < (2, 7, 9):
sys.stderr.write("pyVmomi requires Python 2.7.9 or newer")
sys.exit(1)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os

from setuptools import setup
from pyVmomi import version_info_str


def read(fname):
Expand All @@ -30,7 +31,7 @@ def read(fname):

setup(
name='pyvmomi',
version='8.0.2.0.1',
version=version_info_str,
description='VMware vSphere Python SDK',
# NOTE: pypi prefers the use of RST to render docs
long_description=read('README.rst'),
Expand Down

0 comments on commit 5ad215f

Please sign in to comment.