From f84fa55460b662f58bfe634e251c0b2208e3031f Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Fri, 9 Dec 2016 14:48:39 +0200 Subject: [PATCH] Introduce OpenStack API-based function example --- examples/openstack-app/Dockerfile | 12 +++++++ examples/openstack-app/list_servers.py | 44 +++++++++++++++++++++++++ examples/openstack-app/requirements.txt | 3 ++ picasso/api/views/app.py | 3 +- 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 examples/openstack-app/Dockerfile create mode 100644 examples/openstack-app/list_servers.py create mode 100644 examples/openstack-app/requirements.txt diff --git a/examples/openstack-app/Dockerfile b/examples/openstack-app/Dockerfile new file mode 100644 index 0000000..ea098b9 --- /dev/null +++ b/examples/openstack-app/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.5 + +ENV PYTHONUNBUFFERED 1 + +RUN mkdir /code +WORKDIR /code +ADD . /code/ + + +RUN pip3 install -r /code/requirements.txt + +ENTRYPOINT ["python3", "/code/list_servers.py"] diff --git a/examples/openstack-app/list_servers.py b/examples/openstack-app/list_servers.py new file mode 100644 index 0000000..49346af --- /dev/null +++ b/examples/openstack-app/list_servers.py @@ -0,0 +1,44 @@ +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import json +import os +import sys + +from keystoneauth1 import identity +from keystoneauth1 import session +from keystoneclient import client as keystone + +from novaclient import client as nova + + +num_servers = 0 + +if not os.isatty(sys.stdin.fileno()): + obj = json.loads(sys.stdin.read()) + auth_url = obj.get("OS_AUTH_URL") + x_auth_token = obj.get("OS_TOKEN") + project_id = obj.get("OS_PROJECT_ID") + auth = identity.Token(auth_url, + token=x_auth_token, + project_id=project_id) + sess = session.Session(auth=auth) + ks = keystone.Client(session=sess, + project_id=project_id) + ks.authenticate(token=x_auth_token) + + nc = nova.Client('2', session=sess) + num_servers = len(nc.servers.list()) + +print("You have", num_servers, "servers.") diff --git a/examples/openstack-app/requirements.txt b/examples/openstack-app/requirements.txt new file mode 100644 index 0000000..7233f60 --- /dev/null +++ b/examples/openstack-app/requirements.txt @@ -0,0 +1,3 @@ +keystoneauth1==2.15.0 # Apache-2.0 +python-novaclient==6.0.0 +python-keystoneclient==3.6.0 # Apache-2.0 diff --git a/picasso/api/views/app.py b/picasso/api/views/app.py index 9f5fca7..c3f8fe4 100644 --- a/picasso/api/views/app.py +++ b/picasso/api/views/app.py @@ -57,7 +57,6 @@ class AppRouteView(object): if hasattr(route, "timeout"): one.update(timeout=route.timeout) if hasattr(route, "max_concurrency"): - one.update(max_concurrency= - route.max_concurrency) + one.update(max_concurrency=route.max_concurrency) view.append(one) return view