From cfc249931af37e70f1246fa75ab907507a30208f Mon Sep 17 00:00:00 2001 From: Eric Johnson Date: Tue, 8 Oct 2013 16:36:35 +0000 Subject: [PATCH] custom user-agent header --- library/cloud/gce | 5 +++++ library/cloud/gce_lb | 7 +++++++ library/cloud/gce_net | 5 +++++ library/cloud/gce_pd | 5 +++++ plugins/inventory/gce.py | 10 ++++++++-- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/library/cloud/gce b/library/cloud/gce index e9d6b28ac9a..7f13751f813 100644 --- a/library/cloud/gce +++ b/library/cloud/gce @@ -150,6 +150,9 @@ EXAMPLES = ''' import sys +USER_AGENT_PRODUCT="Ansible-gce" +USER_AGENT_VERSION="v1beta15" + try: from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver @@ -367,6 +370,8 @@ def main(): try: gce = get_driver(Provider.GCE)(*ARGS, datacenter=zone, **KWARGS) + gce.connection.user_agent_append("%s/%s" % ( + USER_AGENT_PRODUCT, USER_AGENT_VERSION)) except Exception as e: module.fail_json(msg=unexpected_error_msg(e), changed=False) diff --git a/library/cloud/gce_lb b/library/cloud/gce_lb index fbead066f4f..d5205ff30ed 100644 --- a/library/cloud/gce_lb +++ b/library/cloud/gce_lb @@ -128,6 +128,9 @@ EXAMPLES = ''' import sys +USER_AGENT_PRODUCT="Ansible-gce_lb" +USER_AGENT_VERSION="v1beta15" + try: from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver @@ -202,7 +205,11 @@ def main(): try: gce = get_driver(Provider.GCE)(*ARGS, **KWARGS) + gce.connection.user_agent_append("%s/%s" % ( + USER_AGENT_PRODUCT, USER_AGENT_VERSION)) gcelb = get_driver_lb(Provider_lb.GCE)(gce_driver=gce) + gcelb.connection.user_agent_append("%s/%s" % ( + USER_AGENT_PRODUCT, USER_AGENT_VERSION)) except Exception as e: module.fail_json(msg=unexpected_error_msg(e), changed=False) diff --git a/library/cloud/gce_net b/library/cloud/gce_net index 903d2b23e6a..65f2d022a92 100644 --- a/library/cloud/gce_net +++ b/library/cloud/gce_net @@ -95,6 +95,9 @@ EXAMPLES = ''' import sys +USER_AGENT_PRODUCT="Ansible-gce_net" +USER_AGENT_VERSION="v1beta15" + try: from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver @@ -168,6 +171,8 @@ def main(): try: gce = get_driver(Provider.GCE)(*ARGS, **KWARGS) + gce.connection.user_agent_append("%s/%s" % ( + USER_AGENT_PRODUCT, USER_AGENT_VERSION)) except Exception as e: module.fail_json(msg=unexpected_error_msg(e), changed=False) diff --git a/library/cloud/gce_pd b/library/cloud/gce_pd index 36d4750a5d5..b60d4fe9bb5 100644 --- a/library/cloud/gce_pd +++ b/library/cloud/gce_pd @@ -90,6 +90,9 @@ EXAMPLES = ''' import sys +USER_AGENT_PRODUCT="Ansible-gce_pd" +USER_AGENT_VERSION="v1beta15" + try: from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver @@ -149,6 +152,8 @@ def main(): try: gce = get_driver(Provider.GCE)(*ARGS, datacenter=zone, **KWARGS) + gce.connection.user_agent_append("%s/%s" % ( + USER_AGENT_PRODUCT, USER_AGENT_VERSION)) except Exception as e: module.fail_json(msg=unexpected_error_msg(e), changed=False) diff --git a/plugins/inventory/gce.py b/plugins/inventory/gce.py index 150cab0fe05..c16527ec757 100755 --- a/plugins/inventory/gce.py +++ b/plugins/inventory/gce.py @@ -72,6 +72,9 @@ Author: Eric Johnson Version: 0.0.1 ''' +USER_AGENT_PRODUCT="Ansible-gce_inventory_plugin" +USER_AGENT_VERSION="v1beta15" + import sys import os import argparse @@ -146,8 +149,11 @@ class GceInventory(object): config.get('gce','gce_service_account_pem_file_path') ) kwargs = {'project': config.get('gce','gce_project_id')} - - return get_driver(Provider.GCE)(*args, **kwargs) + + gce = get_driver(Provider.GCE)(*args, **kwargs) + gce.connection.user_agent_append("%s/%s" % ( + USER_AGENT_PRODUCT, USER_AGENT_VERSION)) + return gce def parse_cli_args(self):