Skip to content

Commit

Permalink
custom user-agent header
Browse files Browse the repository at this point in the history
  • Loading branch information
erjohnso committed Oct 8, 2013
1 parent 9ca824c commit cfc2499
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions library/cloud/gce
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions library/cloud/gce_lb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions library/cloud/gce_net
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions library/cloud/gce_pd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 8 additions & 2 deletions plugins/inventory/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
Version: 0.0.1
'''

USER_AGENT_PRODUCT="Ansible-gce_inventory_plugin"
USER_AGENT_VERSION="v1beta15"

import sys
import os
import argparse
Expand Down Expand Up @@ -146,8 +149,11 @@ def get_gce_driver(self):
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):
Expand Down

0 comments on commit cfc2499

Please sign in to comment.