From c57d51d0f77b7143806045be889aa823858cde3c Mon Sep 17 00:00:00 2001 From: Claudio Benfatto Date: Mon, 20 Mar 2017 11:22:51 +0000 Subject: [PATCH 1/4] space user role 'user' does not exist: use correct name 'developer' instead --- CHANGELOG.md | 3 +++ cfconfigurator/cf.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c34cc51 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +- version 0.24 + +Fixed bug with user creation in the context of a space. Adding users with role developer to a space now works. diff --git a/cfconfigurator/cf.py b/cfconfigurator/cf.py index 2cf7936..04c14e3 100644 --- a/cfconfigurator/cf.py +++ b/cfconfigurator/cf.py @@ -658,14 +658,14 @@ def manage_organization_users(self, orguid, userid, role='user', add=True): def manage_space_users(self, spuid, userid, role='user', add=True): url = self.api_url - if role == 'user': + if role == 'developer': url += self.users_spaces_url elif role == 'manager': url += self.users_managed_spaces_url elif role == 'auditor': url += self.users_audited_spaces_url else: - raise ValueError("Invalid role, options: user, manager, auditor") + raise ValueError("Invalid role, options: developer, manager, auditor") url = url % userid found = False resp = self._get(url) From de31957d1ce85d7cac70a5c5876c73b1be969598 Mon Sep 17 00:00:00 2001 From: Claudio Benfatto Date: Mon, 20 Mar 2017 11:26:33 +0000 Subject: [PATCH 2/4] update version number to 0.24 --- cfconfigurator/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfconfigurator/__init__.py b/cfconfigurator/__init__.py index eaee902..3bd519f 100644 --- a/cfconfigurator/__init__.py +++ b/cfconfigurator/__init__.py @@ -5,7 +5,7 @@ """ __program__ = "cfconfigurator" -__version__ = "0.2.3" +__version__ = "0.2.4" __author__ = "Jose Riguera" __year__ = "2017" __email__ = "" From b4a908fb3a4922a42ba171fce21376c812d8a6af Mon Sep 17 00:00:00 2001 From: Jose Riguera Date: Tue, 9 May 2017 18:04:28 +0200 Subject: [PATCH 3/4] added cf-apps example application --- cf-apps.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 cf-apps.py diff --git a/cf-apps.py b/cf-apps.py new file mode 100755 index 0000000..173abef --- /dev/null +++ b/cf-apps.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Program to query CF apps status based on filters +""" +# Python 2 and 3 compatibility +from __future__ import unicode_literals, print_function + +__program__ = "cf-apps" +__version__ = "0.1" +__author__ = "Jose Riguera" +__year__ = "2017" +__email__ = "" +__license__ = "MIT" +__purpose__ = """ +List information about applications available in Cloud Foundry using `GET /v2/apps` endpoint + +You can define lambda filters with the variable `x` which represents the CF API output, like this: +* "int(x['entity']['instances']) <= 1": will list all apps with 1 or less instances +* "int(x['entity']['instances']) <= 1 and x['entity']['state'] == 'STARTED'": same as before but only the started ones +* "x['entity']['state'] == 'STOPPED'": all apps stopped + +For more information about the filter parameters and fields, see https://apidocs.cloudfoundry.org/ +""" + +from cfconfigurator.cf import CF +import argparse + + + +def run(user, password, api, entity_filter, entity_fields=['name']): + cf = CF(api) + cf.login(user, password) + result = cf.request('GET', "/v2/apps", {"results-per-page": 100}) + apps = result[0] + print("* Total results: %s" % apps['total_results']) + data = apps['resources'] + fun = "filter(lambda x: %s, data)" % entity_filter + filtered = list(eval(fun)) + for entity in filtered: + app = entity['entity'] + fields = [str(app[x]) if x in app else x for x in entity_fields] + #print(app) + print(" ".join(fields)) + print("* Apps: %d" % len(filtered)) + + +def main(): + # Argument parsing + epilog = __purpose__ + '\n' + epilog += __version__ + ', ' + __year__ + ' ' + epilog += __author__ + ' ' + __email__ + parser = argparse.ArgumentParser( + formatter_class=argparse.RawTextHelpFormatter, + description=__doc__, epilog=epilog) + parser.add_argument('filter', default="True", nargs='?', help='Entity filter definition for each item') + parser.add_argument('-u', '--user', default="admin", type=str, help='User to query the CF API') + parser.add_argument('-p', '--password', default="admin", type=str, help='Password for the user') + parser.add_argument('-a', '--api', type=str, help='CF API url') + parser.add_argument('-f', '--fields', default="name,is,state,with,instances,instances.", help='Fields and words to show in the output') + + args = parser.parse_args() + fields = args.fields.split(',') + print(fields) + run(args.user, args.password, args.api, args.filter, fields) + + +if __name__ == "__main__": + main() From 198b4e00cd9e362abee726c0242c1d5f986eb073 Mon Sep 17 00:00:00 2001 From: Jose Riguera Date: Thu, 11 Oct 2018 16:33:25 +0200 Subject: [PATCH 4/4] Fix requirements and setup.py --- cfconfigurator/__init__.py | 2 +- requirements.txt | 2 +- setup.py | 22 ++++++++-------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/cfconfigurator/__init__.py b/cfconfigurator/__init__.py index 3bd519f..79f65bf 100644 --- a/cfconfigurator/__init__.py +++ b/cfconfigurator/__init__.py @@ -5,7 +5,7 @@ """ __program__ = "cfconfigurator" -__version__ = "0.2.4" +__version__ = "0.2.5" __author__ = "Jose Riguera" __year__ = "2017" __email__ = "" diff --git a/requirements.txt b/requirements.txt index d373a14..9c558e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -requests>=2.10.0 +. diff --git a/setup.py b/setup.py index bbf6e52..a3e4256 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ """ Setuptools module for python-cfconfigurator See: - https://packaging.python.org/en/latest/distributing.html + https://packaging.python.org/en/latest/distributing.html """ # Always prefer setuptools over distutils @@ -11,10 +11,12 @@ # To use a consistent encoding from codecs import open from os import path -from pip.download import PipSession -from pip.req import parse_requirements import re +requirements=[ + "requests>=2.10.0", +] + def find_version(*file_paths): # Open in Latin-1 so that we avoid encoding errors. @@ -24,8 +26,7 @@ def find_version(*file_paths): version_file = f.read() # The version line must have the form # __version__ = 'ver - version_match = re.search( - r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) if version_match: return version_match.group(1) raise RuntimeError("Unable to find version string.") @@ -36,17 +37,10 @@ def find_readme(f="README.md"): # Get the long description from the README file long_description = None with open(path.join(here, f), encoding='utf-8') as f: - long_description = f.read() + long_description = f.read() return long_description -def find_requirements(f='requirements.txt'): - # parse_requirements() returns generator of pip.req.InstallRequirement objects - reqs = parse_requirements("requirements.txt", session=PipSession()) - install_reqs = [str(ir.req) for ir in reqs] - return install_reqs - - setup( name="cfconfigurator", url="https://github.com/SpringerPE/python-cfconfigurator", @@ -85,5 +79,5 @@ def find_requirements(f='requirements.txt'): ], # Dependent packages (distributions) - install_requires=find_requirements(), + install_requires=requirements, )