diff options
-rw-r--r-- | azure/multicloud_azure/pub/msapi/extsys.py | 32 | ||||
-rw-r--r-- | azure/multicloud_azure/swagger/urls.py | 12 | ||||
-rw-r--r-- | azure/multicloud_azure/swagger/views/registry/views.py | 14 |
3 files changed, 57 insertions, 1 deletions
diff --git a/azure/multicloud_azure/pub/msapi/extsys.py b/azure/multicloud_azure/pub/msapi/extsys.py index 4d78337..af8275c 100644 --- a/azure/multicloud_azure/pub/msapi/extsys.py +++ b/azure/multicloud_azure/pub/msapi/extsys.py @@ -17,6 +17,38 @@ from multicloud_azure.pub.utils.restcall import AAIClient logger = logging.getLogger(__name__) +def encode_vim_id(cloud_owner, cloud_region_id): + ''' + compose vim_id by cloud_owner and cloud_region, make sure the vimid can be + converted back when talking to AAI,etc. + This is a backward compatibility design to reuse the existing + implementation code + :param cloud_owner: + :param cloud_region: + :return: + ''' + + # since the {cloud_owner}/{cloud_region_id"} is globally unique, the + # concatenated one as below will be unique as well. + + vim_id = cloud_owner + "_" + cloud_region_id + + # other options: + # 1, store it into cache so the decode and just look up the cache for + # decoding + # 2, use other delimiter in case that '_' was used by + # cloud owner/cloud region id, + # e.g. '.', '#', hence the decode need to try more than one time + + return vim_id + + +def decode_vim_id(vim_id): + # m = re.search(r'^([0-9a-zA-Z-]+)_([0-9a-zA-Z_-]+)$', vim_id) + # cloud_owner, cloud_region_id = m.group(1), m.group(2) + return split_vim_to_owner_region(vim_id) + + def split_vim_to_owner_region(vim_id): split_vim = vim_id.split('_') cloud_owner = split_vim[0] diff --git a/azure/multicloud_azure/swagger/urls.py b/azure/multicloud_azure/swagger/urls.py index 6acd327..a3de04a 100644 --- a/azure/multicloud_azure/swagger/urls.py +++ b/azure/multicloud_azure/swagger/urls.py @@ -20,7 +20,8 @@ from multicloud_azure.swagger.views.swagger_json import SwaggerJsonView # Registry from multicloud_azure.swagger.views.registry.views import Registry from multicloud_azure.swagger.views.registry.views import UnRegistry - +from multicloud_azure.swagger.views.registry.views import APIv1Registry +from multicloud_azure.swagger.views.registry.views import APIv1UnRegistry urlpatterns = [ # swagger @@ -29,9 +30,18 @@ urlpatterns = [ # Registry url(r'^api/multicloud-azure/v0/(?P<vimid>[0-9a-z-A-Z\-\_]+)/registry$', Registry.as_view()), + url(r'^api/multicloud-azure/v0/(?P<vimid>[0-9a-z-A-Z\-\_]+)$', UnRegistry.as_view()), + url(r'^api/multicloud-azure/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)' + r'/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/registry$', + APIv1Registry.as_view()), + + url(r'^api/multicloud-azure/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)' + r'/(?P<cloud_region_id>[0-9a-zA-Z_-]+)$', + APIv1UnRegistry.as_view()), + ] urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/azure/multicloud_azure/swagger/views/registry/views.py b/azure/multicloud_azure/swagger/views/registry/views.py index 8464ce4..c5f7ab3 100644 --- a/azure/multicloud_azure/swagger/views/registry/views.py +++ b/azure/multicloud_azure/swagger/views/registry/views.py @@ -85,3 +85,17 @@ class UnRegistry(APIView): return Response(data=e.message, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(data="", status=status.HTTP_204_NO_CONTENT) + + +class APIv1Registry(Registry): + + def post(self, request, cloud_owner, cloud_region_id): + vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) + return super(APIv1Registry, self).post(request, vimid) + + +class APIv1UnRegistry(UnRegistry): + + def delete(self, request, cloud_owner, cloud_region_id): + vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) + return super(APIv1UnRegistry, self).delete(request, vimid) |