2013-07-03 18:12:58 -05:00
|
|
|
# Copyright 2012-2013 OpenStack Foundation
|
2012-05-14 17:43:30 -05:00
|
|
|
#
|
2013-01-24 12:00:30 -06:00
|
|
|
# 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
|
2012-05-14 17:43:30 -05:00
|
|
|
#
|
2013-01-24 12:00:30 -06:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2012-05-14 17:43:30 -05:00
|
|
|
#
|
2013-01-24 12:00:30 -06:00
|
|
|
# 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.
|
2012-05-14 17:43:30 -05:00
|
|
|
#
|
|
|
|
|
2013-01-31 13:31:41 -06:00
|
|
|
"""Endpoint action implementations"""
|
2012-05-14 17:43:30 -05:00
|
|
|
|
2013-07-03 18:12:58 -05:00
|
|
|
import six
|
2012-05-14 17:43:30 -05:00
|
|
|
|
2016-01-10 21:54:53 +09:00
|
|
|
from openstackclient.common import command
|
2012-05-14 17:43:30 -05:00
|
|
|
from openstackclient.common import utils
|
2016-05-13 13:14:02 -07:00
|
|
|
from openstackclient.i18n import _
|
2014-03-12 11:51:17 -06:00
|
|
|
from openstackclient.identity import common
|
2012-05-14 17:43:30 -05:00
|
|
|
|
|
|
|
|
2016-01-10 21:54:53 +09:00
|
|
|
class CreateEndpoint(command.ShowOne):
|
2014-12-30 17:46:02 -06:00
|
|
|
"""Create new endpoint"""
|
2012-05-14 17:43:30 -05:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(CreateEndpoint, self).get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
|
|
|
'service',
|
2014-12-30 17:46:02 -06:00
|
|
|
metavar='<service>',
|
|
|
|
help=_('New endpoint service (name or ID)'),
|
|
|
|
)
|
2012-05-14 17:43:30 -05:00
|
|
|
parser.add_argument(
|
|
|
|
'--publicurl',
|
2014-12-30 17:46:02 -06:00
|
|
|
metavar='<url>',
|
2014-03-12 11:51:17 -06:00
|
|
|
required=True,
|
2014-12-30 17:46:02 -06:00
|
|
|
help=_('New endpoint public URL (required)'),
|
|
|
|
)
|
2012-05-14 17:43:30 -05:00
|
|
|
parser.add_argument(
|
|
|
|
'--adminurl',
|
2014-12-30 17:46:02 -06:00
|
|
|
metavar='<url>',
|
|
|
|
help=_('New endpoint admin URL'),
|
|
|
|
)
|
2012-05-14 17:43:30 -05:00
|
|
|
parser.add_argument(
|
|
|
|
'--internalurl',
|
2014-12-30 17:46:02 -06:00
|
|
|
metavar='<url>',
|
|
|
|
help=_('New endpoint internal URL'),
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--region',
|
|
|
|
metavar='<region-id>',
|
|
|
|
help=_('New endpoint region ID'),
|
|
|
|
)
|
2012-05-14 17:43:30 -05:00
|
|
|
return parser
|
|
|
|
|
2012-06-01 11:17:30 -05:00
|
|
|
def take_action(self, parsed_args):
|
2012-05-14 17:43:30 -05:00
|
|
|
identity_client = self.app.client_manager.identity
|
2014-03-12 11:51:17 -06:00
|
|
|
service = common.find_service(identity_client, parsed_args.service)
|
2012-05-14 17:43:30 -05:00
|
|
|
endpoint = identity_client.endpoints.create(
|
|
|
|
parsed_args.region,
|
|
|
|
service.id,
|
|
|
|
parsed_args.publicurl,
|
|
|
|
parsed_args.adminurl,
|
2013-01-31 13:31:41 -06:00
|
|
|
parsed_args.internalurl,)
|
2012-05-14 17:43:30 -05:00
|
|
|
|
|
|
|
info = {}
|
|
|
|
info.update(endpoint._info)
|
|
|
|
info['service_name'] = service.name
|
|
|
|
info['service_type'] = service.type
|
2013-07-03 18:12:58 -05:00
|
|
|
return zip(*sorted(six.iteritems(info)))
|
2012-05-14 17:43:30 -05:00
|
|
|
|
|
|
|
|
2012-06-01 11:17:30 -05:00
|
|
|
class DeleteEndpoint(command.Command):
|
2014-12-30 17:46:02 -06:00
|
|
|
"""Delete endpoint"""
|
2012-05-14 17:43:30 -05:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(DeleteEndpoint, self).get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
|
|
|
'endpoint',
|
|
|
|
metavar='<endpoint-id>',
|
2016-06-05 10:58:48 +08:00
|
|
|
help=_('Endpoint ID to delete'),
|
|
|
|
)
|
2012-05-14 17:43:30 -05:00
|
|
|
return parser
|
|
|
|
|
2012-06-01 11:17:30 -05:00
|
|
|
def take_action(self, parsed_args):
|
2012-05-14 17:43:30 -05:00
|
|
|
identity_client = self.app.client_manager.identity
|
|
|
|
identity_client.endpoints.delete(parsed_args.endpoint)
|
|
|
|
|
|
|
|
|
2016-01-10 21:54:53 +09:00
|
|
|
class ListEndpoint(command.Lister):
|
2014-12-30 17:46:02 -06:00
|
|
|
"""List endpoints"""
|
2012-05-14 17:43:30 -05:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(ListEndpoint, self).get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
|
|
|
'--long',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2014-12-30 17:46:02 -06:00
|
|
|
help=_('List additional fields in output'),
|
|
|
|
)
|
2012-05-14 17:43:30 -05:00
|
|
|
return parser
|
|
|
|
|
2012-06-01 11:17:30 -05:00
|
|
|
def take_action(self, parsed_args):
|
2012-05-14 17:43:30 -05:00
|
|
|
identity_client = self.app.client_manager.identity
|
|
|
|
if parsed_args.long:
|
|
|
|
columns = ('ID', 'Region', 'Service Name', 'Service Type',
|
2013-01-31 13:31:41 -06:00
|
|
|
'PublicURL', 'AdminURL', 'InternalURL')
|
2012-05-14 17:43:30 -05:00
|
|
|
else:
|
|
|
|
columns = ('ID', 'Region', 'Service Name', 'Service Type')
|
|
|
|
data = identity_client.endpoints.list()
|
|
|
|
|
|
|
|
for ep in data:
|
2014-03-12 11:51:17 -06:00
|
|
|
service = common.find_service(identity_client, ep.service_id)
|
2012-05-14 17:43:30 -05:00
|
|
|
ep.service_name = service.name
|
|
|
|
ep.service_type = service.type
|
|
|
|
return (columns,
|
|
|
|
(utils.get_item_properties(
|
|
|
|
s, columns,
|
|
|
|
formatters={},
|
2013-01-31 13:31:41 -06:00
|
|
|
) for s in data))
|
2012-05-14 17:43:30 -05:00
|
|
|
|
|
|
|
|
2016-01-10 21:54:53 +09:00
|
|
|
class ShowEndpoint(command.ShowOne):
|
2014-12-30 17:46:02 -06:00
|
|
|
"""Display endpoint details"""
|
2012-05-14 17:43:30 -05:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(ShowEndpoint, self).get_parser(prog_name)
|
|
|
|
parser.add_argument(
|
2014-03-12 11:51:17 -06:00
|
|
|
'endpoint_or_service',
|
2016-05-26 16:52:54 +08:00
|
|
|
metavar='<endpoint>',
|
|
|
|
help=_('Endpoint to display (endpoint ID, service ID,'
|
|
|
|
' service name, service type)'),
|
2014-12-30 17:46:02 -06:00
|
|
|
)
|
2012-05-14 17:43:30 -05:00
|
|
|
return parser
|
|
|
|
|
2012-06-01 11:17:30 -05:00
|
|
|
def take_action(self, parsed_args):
|
2012-05-14 17:43:30 -05:00
|
|
|
identity_client = self.app.client_manager.identity
|
2014-03-12 11:51:17 -06:00
|
|
|
data = identity_client.endpoints.list()
|
|
|
|
match = None
|
|
|
|
for ep in data:
|
|
|
|
if ep.id == parsed_args.endpoint_or_service:
|
|
|
|
match = ep
|
|
|
|
service = common.find_service(identity_client, ep.service_id)
|
|
|
|
if match is None:
|
|
|
|
service = common.find_service(identity_client,
|
|
|
|
parsed_args.endpoint_or_service)
|
2012-05-14 17:43:30 -05:00
|
|
|
for ep in data:
|
|
|
|
if ep.service_id == service.id:
|
2014-03-12 11:51:17 -06:00
|
|
|
match = ep
|
|
|
|
if match is None:
|
|
|
|
return None
|
|
|
|
info = {}
|
|
|
|
info.update(match._info)
|
|
|
|
info['service_name'] = service.name
|
|
|
|
info['service_type'] = service.type
|
|
|
|
return zip(*sorted(six.iteritems(info)))
|