summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhenguo Niu <Niu.ZGlinux@gmail.com>2017-04-18 16:47:20 +0800
committerZhenguo Niu <Niu.ZGlinux@gmail.com>2017-04-18 19:17:08 +0800
commit08bf0b6d852b58a0e72e785f4e49917d5f3cd5a7 (patch)
treea5f5aab1b62d8b1c7192668c8ecb17cda5b1c081
parentde8575d0d77c0bec33a579029c4fdb8e0f844244 (diff)
Add servers list API
Notes
Notes (review): Code-Review+2: Zhenguo Niu <Niu.ZGlinux@gmail.com> Workflow+1: Zhenguo Niu <Niu.ZGlinux@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 18 Apr 2017 11:30:31 +0000 Reviewed-on: https://review.openstack.org/457526 Project: openstack/mogan-ui Branch: refs/heads/master
-rw-r--r--mogan_ui/api/__init__.py0
-rw-r--r--mogan_ui/api/client.py45
-rw-r--r--mogan_ui/api/rest_api.py34
-rw-r--r--test-requirements.txt1
4 files changed, 80 insertions, 0 deletions
diff --git a/mogan_ui/api/__init__.py b/mogan_ui/api/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mogan_ui/api/__init__.py
diff --git a/mogan_ui/api/client.py b/mogan_ui/api/client.py
new file mode 100644
index 0000000..e9d48cb
--- /dev/null
+++ b/mogan_ui/api/client.py
@@ -0,0 +1,45 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from django.conf import settings
14
15from horizon.utils.memoized import memoized
16from moganclient.v1 import client as mogan_client
17from openstack_dashboard.api import base
18
19
20@memoized
21def moganclient(request):
22 """Returns a client connected to the Mogan backend.
23
24 :param request: HTTP request.
25 :return: Mogan client.
26 """
27 insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
28 cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
29 mogan_url = base.url_for(request, 'baremetal_compute')
30
31 return mogan_client.Client(mogan_url,
32 project_id=request.user.project_id,
33 token=request.user.token.id,
34 insecure=insecure,
35 cacert=cacert)
36
37
38def server_list(request):
39 """Retrieve a list of servers.
40
41 :param request: HTTP request.
42 :return: A list of servers.
43 """
44 server_manager = moganclient(request).server
45 return server_manager.list(detailed=True, all_projects=False)
diff --git a/mogan_ui/api/rest_api.py b/mogan_ui/api/rest_api.py
new file mode 100644
index 0000000..b28a1ff
--- /dev/null
+++ b/mogan_ui/api/rest_api.py
@@ -0,0 +1,34 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from django.views import generic
14
15from mogan_ui.api import client
16
17from openstack_dashboard.api.rest import urls
18from openstack_dashboard.api.rest import utils as rest_utils
19
20
21@urls.register
22class Servers(generic.View):
23 """API for Mogan Servers"""
24 url_regex = r'mogan/servers/$'
25
26 @rest_utils.ajax()
27 def get(self, request):
28 """Get a list of the servers.
29
30 :param request: HTTP request.
31 :return: servers.
32 """
33 servers = client.server_list(request)
34 return {'servers': [s.to_dict() for s in servers]}
diff --git a/test-requirements.txt b/test-requirements.txt
index c73097c..dafc211 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -4,6 +4,7 @@
4 4
5# Require Horizon 5# Require Horizon
6-e git://github.com/openstack/horizon.git#egg=horizon 6-e git://github.com/openstack/horizon.git#egg=horizon
7-e git://github.com/openstack/python-moganclient.git#egg=python-moganclient
7 8
8hacking>=0.12.0,!=0.13.0,<0.14 # Apache-2.0 9hacking>=0.12.0,!=0.13.0,<0.14 # Apache-2.0
9 10