summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Schultz <schultz.derek@gmail.com>2016-12-09 10:11:32 -0700
committerGitHub <noreply@github.com>2016-12-09 10:11:32 -0700
commitb9e265533626501b2dac99419c8d8534bf24e2da (patch)
treee08dc674fe7f2c5a029081429adb96a293edc83c
parenta5d0bb734b6d731c3cd11c13a1519da3507c3b1d (diff)
parentf84fa55460b662f58bfe634e251c0b2208e3031f (diff)
Merge pull request #19 from denismakogon/openstack-app-sample
Introduce OpenStack API-based function example
-rw-r--r--examples/openstack-app/Dockerfile12
-rw-r--r--examples/openstack-app/list_servers.py44
-rw-r--r--examples/openstack-app/requirements.txt3
-rw-r--r--picasso/api/views/app.py3
4 files changed, 60 insertions, 2 deletions
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 @@
1FROM python:3.5
2
3ENV PYTHONUNBUFFERED 1
4
5RUN mkdir /code
6WORKDIR /code
7ADD . /code/
8
9
10RUN pip3 install -r /code/requirements.txt
11
12ENTRYPOINT ["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 @@
1# All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import json
16import os
17import sys
18
19from keystoneauth1 import identity
20from keystoneauth1 import session
21from keystoneclient import client as keystone
22
23from novaclient import client as nova
24
25
26num_servers = 0
27
28if not os.isatty(sys.stdin.fileno()):
29 obj = json.loads(sys.stdin.read())
30 auth_url = obj.get("OS_AUTH_URL")
31 x_auth_token = obj.get("OS_TOKEN")
32 project_id = obj.get("OS_PROJECT_ID")
33 auth = identity.Token(auth_url,
34 token=x_auth_token,
35 project_id=project_id)
36 sess = session.Session(auth=auth)
37 ks = keystone.Client(session=sess,
38 project_id=project_id)
39 ks.authenticate(token=x_auth_token)
40
41 nc = nova.Client('2', session=sess)
42 num_servers = len(nc.servers.list())
43
44print("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 @@
1keystoneauth1==2.15.0 # Apache-2.0
2python-novaclient==6.0.0
3python-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):
57 if hasattr(route, "timeout"): 57 if hasattr(route, "timeout"):
58 one.update(timeout=route.timeout) 58 one.update(timeout=route.timeout)
59 if hasattr(route, "max_concurrency"): 59 if hasattr(route, "max_concurrency"):
60 one.update(max_concurrency= 60 one.update(max_concurrency=route.max_concurrency)
61 route.max_concurrency)
62 view.append(one) 61 view.append(one)
63 return view 62 return view