libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [libcloud] Kami commented on a change in pull request #1281: Add router management functions in OpenStack
Date Sun, 26 May 2019 15:20:55 GMT
Kami commented on a change in pull request #1281: Add router management functions in OpenStack
URL: https://github.com/apache/libcloud/pull/1281#discussion_r287602611
 
 

 ##########
 File path: libcloud/compute/drivers/openstack.py
 ##########
 @@ -3416,6 +3486,148 @@ def ex_list_floating_ip_pools(self):
                                             '=True&fields=id&fields='
                                             'name').object)
 
+    def _to_routers(self, obj):
+        routers = obj['routers']
+        return [self._to_router(router) for router in routers]
+
+    def _to_router(self, obj):
+        extra = {}
+        extra['external_gateway_info'] = obj['external_gateway_info']
+        extra['routes'] = obj['routes']
+        return OpenStack_2_Router(id=obj['id'],
+                                  name=obj['name'],
+                                  status=obj['status'],
+                                  driver=self,
+                                  extra=extra)
+
+    def ex_list_routers(self):
+        """
+        Get a list of Routers that are available.
+
+        :rtype: ``list`` of :class:`OpenStack_2_Router`
+        """
+        response = self.network_connection.request(
+            '/v2.0/routers').object
+        return self._to_routers(response)
+
+    def ex_create_router(self, name, **kwargs):
+        """
+        Create a new Router
+
+        :param name: Name of router which should be used
+        :type name: ``str``
+
+        :rtype: :class:`OpenStack_2_Router`
+        """
+        data = {'router': {'name': name}}
+        # Add optional values
+        for key, value in kwargs.items():
+            data['router'][key] = value
+        response = self.network_connection.request(
+            '/v2.0/routers', method='POST', data=data).object
+        return self._to_router(response['router'])
+
+    def ex_delete_router(self, router):
+        """
+        Delete a Router
+
+        :param router: Router which should be deleted
+        :type router: :class:`OpenStack_2_Router`
+
+        :rtype: ``bool``
+        """
+        resp = self.network_connection.request('%s/%s' % (
+            '/v2.0/routers', router.id), method='DELETE')
+        return resp.status in (httplib.NO_CONTENT, httplib.ACCEPTED)
+
+    def _manage_router_interface(self, router, op, subnet=None, port=None):
+        """
+        Add/Remove interface to router
+
+        :param router: Router to add/remove the interface
+        :type router: :class:`OpenStack_2_Router`
+
+        :param      op: Operation to perform: 'add' or 'remove'
+        :type       op: ``str``
+
+        :param subnet: Subnet object to be added to the router
+        :type subnet: :class:`OpenStack_2_SubNet`
+
+        :param port: Port object to be added to the router
+        :type port: :class:`OpenStack_2_PortInterface`
+
+        :rtype: ``bool``
+        """
+        data = {}
+        if subnet:
+            data['subnet_id'] = subnet.id
+        elif port:
+            data['port_id'] = port.id
+        else:
+            raise OpenStackException("Error in router interface: "
+                                     "port or subnet are None.", 500,
+                                     self)
+
+        resp = self.network_connection.request('%s/%s/%s_router_interface' % (
+            '/v2.0/routers', router.id, op), method='PUT', data=data)
+        return resp.status == httplib.OK
+
+    def ex_add_router_port(self, router, port):
+        """
+        Add port to a router
+
+        :param router: Router to add the port
+        :type router: :class:`OpenStack_2_Router`
+
+        :param port: Port object to be added to the router
+        :type port: :class:`OpenStack_2_PortInterface`
+
+        :rtype: ``bool``
+        """
+        return self._manage_router_interface(router, 'add', port=port)
+
+    def ex_del_router_port(self, router, port):
+        """
+        Remove port to a router
 
 Review comment:
   to a -> from a :)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message