Browse Source

Introduce OpenStack API-based function example

Denis Makogon 2 years ago
parent
commit
f84fa55460

+ 12
- 0
examples/openstack-app/Dockerfile View File

@@ -0,0 +1,12 @@
1
+FROM python:3.5
2
+
3
+ENV PYTHONUNBUFFERED 1
4
+
5
+RUN mkdir /code
6
+WORKDIR /code
7
+ADD . /code/
8
+
9
+
10
+RUN pip3 install -r /code/requirements.txt
11
+
12
+ENTRYPOINT ["python3", "/code/list_servers.py"]

+ 44
- 0
examples/openstack-app/list_servers.py View File

@@ -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
+
15
+import json
16
+import os
17
+import sys
18
+
19
+from keystoneauth1 import identity
20
+from keystoneauth1 import session
21
+from keystoneclient import client as keystone
22
+
23
+from novaclient import client as nova
24
+
25
+
26
+num_servers = 0
27
+
28
+if 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
+
44
+print("You have", num_servers, "servers.")

+ 3
- 0
examples/openstack-app/requirements.txt View File

@@ -0,0 +1,3 @@
1
+keystoneauth1==2.15.0 # Apache-2.0
2
+python-novaclient==6.0.0
3
+python-keystoneclient==3.6.0 # Apache-2.0

+ 1
- 2
picasso/api/views/app.py View File

@@ -57,7 +57,6 @@ class AppRouteView(object):
57 57
             if hasattr(route, "timeout"):
58 58
                 one.update(timeout=route.timeout)
59 59
             if hasattr(route, "max_concurrency"):
60
-                one.update(max_concurrency=
61
-                           route.max_concurrency)
60
+                one.update(max_concurrency=route.max_concurrency)
62 61
             view.append(one)
63 62
         return view

Loading…
Cancel
Save