keystone  18.0.0
About: OpenStack Keystone (Core Service: Identity) provides an authentication and authorization service for other OpenStack services. Provides a catalog of endpoints for all OpenStack services.
The "Victoria" series (maintained release).
  Fossies Dox: keystone-18.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

regions.py
Go to the documentation of this file.
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 
13 # This file handles all flask-restful resources for /v3/regions
14 
15 import http.client
16 
17 from keystone.catalog import schema
18 from keystone.common import provider_api
19 from keystone.common import rbac_enforcer
20 from keystone.common import validation
21 from keystone import exception
22 from keystone.i18n import _
23 from keystone.server import flask as ks_flask
24 
25 
26 ENFORCER = rbac_enforcer.RBACEnforcer
27 PROVIDERS = provider_api.ProviderAPIs
28 
29 
30 class RegionResource(ks_flask.ResourceBase):
31  collection_key = 'regions'
32  member_key = 'region'
33 
34  def _get_region(self, region_id):
35  ENFORCER.enforce_call(action='identity:get_region')
36  return self.wrap_member(PROVIDERS.catalog_api.get_region(region_id))
37 
38  def _list_regions(self):
39  filters = ['parent_region_id']
40  ENFORCER.enforce_call(action='identity:list_regions', filters=filters)
41  hints = self.build_driver_hints(filters)
42  refs = PROVIDERS.catalog_api.list_regions(hints)
43  return self.wrap_collection(refs, hints=hints)
44 
45  def get(self, region_id=None):
46  if region_id is not None:
47  return self._get_region(region_id)
48  return self._list_regions()
49 
50  def post(self):
51  ENFORCER.enforce_call(action='identity:create_region')
52  region = self.request_body_json.get('region')
53  validation.lazy_validate(schema.region_create, region)
54  region = self._normalize_dict(region)
55  if not region.get('id'):
56  # NOTE(morgan): even though we officially only support 'id' setting
57  # via the PUT mechanism, this is historical and we need to support
58  # both ways.
59  region = self._assign_unique_id(region)
60  ref = PROVIDERS.catalog_api.create_region(
61  region, initiator=self.audit_initiator)
62  return self.wrap_member(ref), http.client.CREATED
63 
64  def put(self, region_id):
65  ENFORCER.enforce_call(action='identity:create_region')
66  region = self.request_body_json.get('region')
67  validation.lazy_validate(schema.region_create, region)
68  region = self._normalize_dict(region)
69  if 'id' not in region:
70  region['id'] = region_id
71  elif region_id != region.get('id'):
73  _('Conflicting region IDs specified: '
74  '"%(url_id)s" != "%(ref_id)s"') % {
75  'url_id': region_id,
76  'ref_id': region['id']})
77 
78  ref = PROVIDERS.catalog_api.create_region(
79  region, initiator=self.audit_initiator)
80  return self.wrap_member(ref), http.client.CREATED
81 
82  def patch(self, region_id):
83  ENFORCER.enforce_call(action='identity:update_region')
84  region = self.request_body_json.get('region')
85  validation.lazy_validate(schema.region_update, region)
86  self._require_matching_id(region)
87  return self.wrap_member(PROVIDERS.catalog_api.update_region(
88  region_id, region, initiator=self.audit_initiator))
89 
90  def delete(self, region_id):
91  ENFORCER.enforce_call(action='identity:delete_region')
92  return PROVIDERS.catalog_api.delete_region(
93  region_id, initiator=self.audit_initiator), http.client.NO_CONTENT
94 
95 
96 class RegionAPI(ks_flask.APIBase):
97  _name = 'regions'
98  _import_name = __name__
99  resources = [RegionResource]
100  resource_mapping = []
101 
102 
103 APIs = (RegionAPI,)
keystone.api.regions.RegionResource.put
def put(self, region_id)
Definition: regions.py:64
keystone.api.regions.RegionResource
Definition: regions.py:30
keystone.api.regions.RegionResource.get
def get(self, region_id=None)
Definition: regions.py:45
keystone.api.regions.RegionResource.delete
def delete(self, region_id)
Definition: regions.py:90
keystone.exception.ValidationError
Definition: exception.py:98
keystone.catalog
Definition: __init__.py:1
keystone.api.regions.RegionResource.patch
def patch(self, region_id)
Definition: regions.py:82
keystone.api.regions.RegionResource._list_regions
def _list_regions(self)
Definition: regions.py:38
keystone.api.regions.RegionAPI
Definition: regions.py:96
keystone.server
Definition: __init__.py:1
keystone.api.regions.RegionResource._get_region
def _get_region(self, region_id)
Definition: regions.py:34
keystone.api.regions.RegionResource.post
def post(self)
Definition: regions.py:50
keystone.i18n._
_
Definition: i18n.py:29
keystone.common
Definition: __init__.py:1
keystone.i18n
Definition: i18n.py:1