Skip to content

Commit

Permalink
Merge branch 'release-1.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins committed Apr 19, 2016
2 parents f6d1ca3 + bb6a6e8 commit 71e2af0
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 60 deletions.
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# define project level attributes:
name = 'clc-ansible-module'
version = '1.1.5'
version = '1.1.6'
summary = "Centurylink Cloud Ansible Modules"
description = "Ansible extension modules which allow users to interact with Centurylink Cloud to define and manage cloud components."
authors = [Author ("CenturyLink Cloud", "[email protected]")]
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ctlts</groupId>
<artifactId>clc-ansible-module</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
<name>clc-ansible-module</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
1 change: 1 addition & 0 deletions src/main/python/clc_ansible_module/clc_aa_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
- python = 2.7
- requests >= 2.5.0
- clc-sdk
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand Down
1 change: 1 addition & 0 deletions src/main/python/clc_ansible_module/clc_alert_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
- python = 2.7
- requests >= 2.5.0
- clc-sdk
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
- python = 2.7
- requests >= 2.5.0
- clc-sdk
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand Down
1 change: 1 addition & 0 deletions src/main/python/clc_ansible_module/clc_firewall_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
- python = 2.7
- requests >= 2.5.0
- clc-sdk
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand Down
1 change: 1 addition & 0 deletions src/main/python/clc_ansible_module/clc_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
- python = 2.7
- requests >= 2.5.0
- clc-sdk
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand Down
44 changes: 24 additions & 20 deletions src/main/python/clc_ansible_module/clc_group_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
requirements:
- python = 2.7
- requests >= 2.5.0
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand All @@ -58,7 +59,7 @@
- name: Retrieve Group Facts
clc_group_fact:
group_id: 31d13f501459411ba59304f3d47486eb
'''

RETURN = '''
Expand Down Expand Up @@ -191,15 +192,14 @@

__version__ = '${version}'

from distutils.version import LooseVersion

try:
import requests
except ImportError:
REQUESTS_FOUND = False
else:
REQUESTS_FOUND = True


class ClcGroupFact:

def __init__(self, module):
Expand All @@ -219,19 +219,21 @@ def process_request(self):
"""
self._set_clc_credentials_from_env()
group_id = self.module.params.get('group_id')

r = requests.get(self._get_endpoint(group_id), headers={
'Authorization' : 'Bearer ' + self.v2_api_token
'Authorization': 'Bearer ' + self.v2_api_token
})

if r.status_code not in [200]:
self.module.fail_json(msg='Failed to retrieve group facts: %s' % group_id)
self.module.fail_json(
msg='Failed to retrieve group facts: %s' %
group_id)

r = r.json()
servers = r['server'] = []
servers = r['servers'] = []

for l in r['links']:
if 'servers' == l['rel']:
if 'server' == l['rel']:
servers.append(l['id'])

self.module.exit_json(changed=False, group=r)
Expand All @@ -258,31 +260,33 @@ def _set_clc_credentials_from_env(self):
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
clc_alias = env.get('CLC_ACCT_ALIAS', False)
self.api_url = env.get('CLC_V2_API_URL', 'https://api.ctl.io')

if v2_api_token and clc_alias:

self.v2_api_token = v2_api_token
self.clc_alias = clc_alias

elif v2_api_username and v2_api_passwd:

r = requests.post(self.api_url + '/v2/authentication/login', json={
'username' : v2_api_username,
'password' : v2_api_passwd
'username': v2_api_username,
'password': v2_api_passwd
})

if r.status_code not in [200]:
self.module.fail_json(msg='Failed to authenticate with clc V2 api.')

r = r.json()
self.module.fail_json(
msg='Failed to authenticate with clc V2 api.')

r = r.json()
self.v2_api_token = r['bearerToken']
self.clc_alias = r['accountAlias']

else:
return self.module.fail_json(
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
"environment variables")


def main():
"""
The main function. Instantiates the module and calls process_request.
Expand Down
29 changes: 15 additions & 14 deletions src/main/python/clc_ansible_module/clc_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@
required: False
default: present
choices: ['present', 'absent', 'port_absent', 'nodes_present', 'nodes_absent']
requirements:
- python = 2.7
- requests >= 2.5.0
- clc-sdk
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
- CLC_V2_API_USERNAME, the account login id for the centurylink cloud
- CLC_V2_API_PASSWORD, the account password for the centurylink cloud
- Alternatively, the module accepts the API token and account alias. The API token can be generated using the
CLC account login and password via the HTTP api call @ https://api.ctl.io/v2/authentication/login
- CLC_V2_API_TOKEN, the API token generated from https://api.ctl.io/v2/authentication/login
- CLC_ACCT_ALIAS, the account alias associated with the centurylink cloud
- Users can set CLC_V2_API_URL to specify an endpoint for pointing to a different CLC environment.
'''

EXAMPLES = '''
Expand Down Expand Up @@ -163,20 +178,6 @@
nodes:
- { 'ipAddress': '10.11.22.123', 'privatePort': 80 }
state: absent
requirements:
- python = 2.7
- requests >= 2.5.0
- clc-sdk
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
- CLC_V2_API_USERNAME, the account login id for the centurylink cloud
- CLC_V2_API_PASSWORD, the account password for the centurylink cloud
- Alternatively, the module accepts the API token and account alias. The API token can be generated using the
CLC account login and password via the HTTP api call @ https://api.ctl.io/v2/authentication/login
- CLC_V2_API_TOKEN, the API token generated from https://api.ctl.io/v2/authentication/login
- CLC_ACCT_ALIAS, the account alias associated with the centurylink cloud
- Users can set CLC_V2_API_URL to specify an endpoint for pointing to a different CLC environment.
'''

RETURN = '''
Expand Down
1 change: 1 addition & 0 deletions src/main/python/clc_ansible_module/clc_modify_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
- python = 2.7
- requests >= 2.5.0
- clc-sdk
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand Down
1 change: 1 addition & 0 deletions src/main/python/clc_ansible_module/clc_publicip.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- python = 2.7
- requests >= 2.5.0
- clc-sdk
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand Down
1 change: 1 addition & 0 deletions src/main/python/clc_ansible_module/clc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
- python = 2.7
- requests >= 2.5.0
- clc-sdk
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand Down
54 changes: 30 additions & 24 deletions src/main/python/clc_ansible_module/clc_server_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
requirements:
- python = 2.7
- requests >= 2.5.0
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand All @@ -64,12 +65,12 @@
- name: Retrieve Server Facts
clc_server_fact:
server_id: UC1WFADWRDPRS10
- name: Retrieve Server Facts With Credentials
clc_server_fact:
server_id: UC1WFADWRDPRS10
credentials: true
'''

RETURN = '''
Expand Down Expand Up @@ -236,15 +237,14 @@

__version__ = '${version}'

from distutils.version import LooseVersion

try:
import requests
except ImportError:
REQUESTS_FOUND = False
else:
REQUESTS_FOUND = True


class ClcServerFact:

def __init__(self, module):
Expand All @@ -264,13 +264,15 @@ def process_request(self):
"""
self._set_clc_credentials_from_env()
server_id = self.module.params.get('server_id')

r = requests.get(self._get_endpoint(server_id), headers={
'Authorization' : 'Bearer ' + self.v2_api_token
'Authorization': 'Bearer ' + self.v2_api_token
})

if r.status_code not in [200]:
self.module.fail_json(msg='Failed to retrieve server facts: %s' % server_id)
self.module.fail_json(
msg='Failed to retrieve server facts: %s' %
server_id)

r = r.json()

Expand All @@ -290,16 +292,18 @@ def _define_module_argument_spec():
credentials=dict(default=False))

return {"argument_spec": argument_spec}

def _get_server_credentials(self, server_id):

r = requests.get(self._get_endpoint(server_id) + '/credentials', headers={
'Authorization' : 'Bearer ' + self.v2_api_token
'Authorization': 'Bearer ' + self.v2_api_token
})

if r.status_code not in [200]:
self.module.fail_json(msg='Failed to retrieve server credentials: %s' % server_id)

self.module.fail_json(
msg='Failed to retrieve server credentials: %s' %
server_id)

return r.json()

def _get_endpoint(self, server_id):
Expand All @@ -316,31 +320,33 @@ def _set_clc_credentials_from_env(self):
v2_api_passwd = env.get('CLC_V2_API_PASSWD', False)
clc_alias = env.get('CLC_ACCT_ALIAS', False)
self.api_url = env.get('CLC_V2_API_URL', 'https://api.ctl.io')

if v2_api_token and clc_alias:

self.v2_api_token = v2_api_token
self.clc_alias = clc_alias

elif v2_api_username and v2_api_passwd:

r = requests.post(self.api_url + '/v2/authentication/login', json={
'username' : v2_api_username,
'password' : v2_api_passwd
'username': v2_api_username,
'password': v2_api_passwd
})

if r.status_code not in [200]:
self.module.fail_json(msg='Failed to authenticate with clc V2 api.')

r = r.json()
self.module.fail_json(
msg='Failed to authenticate with clc V2 api.')

r = r.json()
self.v2_api_token = r['bearerToken']
self.clc_alias = r['accountAlias']

else:
return self.module.fail_json(
msg="You must set the CLC_V2_API_USERNAME and CLC_V2_API_PASSWD "
"environment variables")


def main():
"""
The main function. Instantiates the module and calls process_request.
Expand Down
1 change: 1 addition & 0 deletions src/main/python/clc_ansible_module/clc_server_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
- python = 2.7
- requests >= 2.5.0
- clc-sdk
author: "CLC Runner (@clc-runner)"
notes:
- To use this module, it is required to set the below environment variables which enables access to the
Centurylink Cloud
Expand Down

0 comments on commit 71e2af0

Please sign in to comment.