Added service-list request

Manila server has support of list with services.
This commit adds possibility to use this API of Manila.

Change-Id: Ib01168941713ceb7224618def20d8115656a21cd
This commit is contained in:
vponomaryov 2014-04-17 06:45:00 -04:00 committed by Valeriy Ponomaryov
parent ac7289c1d5
commit 39e035fba1
4 changed files with 122 additions and 0 deletions

View File

@ -4,6 +4,7 @@ from manilaclient.v1 import share_networks
from manilaclient.v1 import security_services
from manilaclient.v1 import quota_classes
from manilaclient.v1 import quotas
from manilaclient.v1 import services
from manilaclient.v1 import shares
from manilaclient.v1 import share_snapshots
@ -33,6 +34,7 @@ class Client(object):
# know it's not being used as keyword argument
password = api_key
self.limits = limits.LimitsManager(self)
self.services = services.ServiceManager(self)
self.security_services = security_services.SecurityServiceManager(self)
self.share_networks = share_networks.ShareNetworkManager(self)

View File

@ -0,0 +1,47 @@
# Copyright 2014 OpenStack LLC.
# 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 urllib
from manilaclient import base
RESOURCES_PATH = '/os-services'
RESOURCES_NAME = 'services'
class Service(base.Resource):
def __repr__(self):
return "<Service: %s>" % self.id
class ServiceManager(base.Manager):
"""Manage :class:`Service` resources."""
resource_class = Service
def list(self, search_opts=None):
"""Get a list of all services.
:rtype: list of :class:`Service`
"""
query_string = ''
if search_opts:
query_string = urllib.urlencode([(key, value)
for (key, value)
in search_opts.items()
if value])
if query_string:
query_string = "?%s" % query_string
return self._list(RESOURCES_PATH + query_string, RESOURCES_NAME)

View File

@ -998,3 +998,42 @@ def do_security_service_list(cs, args):
def do_security_service_delete(cs, args):
"""Delete security service"""
cs.security_services.delete(args.security_service)
@utils.arg(
'--host',
metavar='<hostname>',
default=None,
help='Name of host.')
@utils.arg(
'--binary',
metavar='<binary>',
default=None,
help='Service binary.')
@utils.arg(
'--status',
metavar='<status>',
default=None,
help='Filter results by status')
@utils.arg(
'--state',
metavar='<state>',
default=None,
help='Filter results by state')
@utils.arg(
'--zone',
metavar='<zone>',
default=None,
help='Availability zone.')
def do_service_list(cs, args):
"""List all the services."""
search_opts = {
'status': args.status,
'host': args.host,
'binary': args.binary,
'zone': args.zone,
'state': args.state,
}
fields = ["Binary", "Host", "Zone", "Status", "State", "Updated_at"]
services = cs.services.list(search_opts=search_opts)
utils.print_list(services, fields=fields)

34
tests/v1/test_services.py Normal file
View File

@ -0,0 +1,34 @@
# Copyright 2013 OpenStack LLC.
# 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 mock
import unittest
from manilaclient.v1 import services
class ServicesTest(unittest.TestCase):
def setUp(self):
super(ServicesTest, self).setUp()
self.manager = services.ServiceManager(api=None)
def test_list(self):
with mock.patch.object(self.manager, '_list',
mock.Mock(return_value=None)):
self.manager.list()
self.manager._list.assert_called_once_with(
services.RESOURCES_PATH,
services.RESOURCES_NAME)