Ehsan Chiniforooshan пре 8 година
родитељ
комит
c4732a557e

+ 38 - 0
cloudbridge/cloud/providers/gce/resources.py

@@ -15,6 +15,7 @@ from cloudbridge.cloud.base.resources import BaseBucket
 from cloudbridge.cloud.base.resources import BaseBucketObject
 from cloudbridge.cloud.base.resources import BaseFloatingIP
 from cloudbridge.cloud.base.resources import BaseInstance
+from cloudbridge.cloud.base.resources import BaseInternetGateway
 from cloudbridge.cloud.base.resources import BaseKeyPair
 from cloudbridge.cloud.base.resources import BaseMachineImage
 from cloudbridge.cloud.base.resources import BaseNetwork
@@ -28,6 +29,7 @@ from cloudbridge.cloud.base.resources import BaseVMFirewallRule
 from cloudbridge.cloud.base.resources import BaseVMType
 from cloudbridge.cloud.base.resources import BaseVolume
 from cloudbridge.cloud.base.resources import ServerPagedResultList
+from cloudbridge.cloud.interfaces.resources import GatewayState
 from cloudbridge.cloud.interfaces.resources import InstanceState
 from cloudbridge.cloud.interfaces.resources import MachineImageState
 from cloudbridge.cloud.interfaces.resources import NetworkState
@@ -1397,6 +1399,42 @@ class GCERouter(BaseRouter):
         cb.log.warning('Not implemented')
 
 
+class GCEInternetGateway(BaseInternetGateway):
+
+    def __init__(self, provider, gateway):
+        super(GCEInternetGateway, self).__init__(provider)
+        self._gateway = gateway
+
+    @property
+    def id(self):
+        return self._gateway['id']
+
+    @property
+    def name(self):
+        return self._gateway['name']
+
+    @name.setter
+    def name(self, value):
+        raise NotImplementedError('Not supported by this provider.')
+
+    def refresh(self):
+        pass
+
+    @property
+    def state(self):
+        return GatewayState.AVAILABLE
+
+    @property
+    def network_id(self):
+        """
+        GCE internet gateways are not attached to a network.
+        """
+        return None
+
+    def delete(self):
+        pass
+
+
 class GCESubnet(BaseSubnet):
 
     def __init__(self, provider, subnet):

+ 26 - 0
cloudbridge/cloud/providers/gce/services.py

@@ -7,6 +7,7 @@ from cloudbridge.cloud.base.resources import ClientPagedResultList
 from cloudbridge.cloud.base.resources import ServerPagedResultList
 from cloudbridge.cloud.base.services import BaseBucketService
 from cloudbridge.cloud.base.services import BaseComputeService
+from cloudbridge.cloud.base.services import BaseGatewayService
 from cloudbridge.cloud.base.services import BaseImageService
 from cloudbridge.cloud.base.services import BaseInstanceService
 from cloudbridge.cloud.base.services import BaseKeyPairService
@@ -32,6 +33,7 @@ from retrying import retry
 from .resources import GCEFirewallsDelegate
 from .resources import GCEFloatingIP
 from .resources import GCEInstance
+from .resources import GCEInternetGateway
 from .resources import GCEKeyPair
 from .resources import GCEMachineImage
 from .resources import GCENetwork
@@ -596,6 +598,7 @@ class GCENetworkingService(BaseNetworkingService):
         self._network_service = GCENetworkService(self.provider)
         self._subnet_service = GCESubnetService(self.provider)
         self._router_service = GCERouterService(self.provider)
+        self._gateway_service = GCEGatewayService(self.provider)
 
     @property
     def networks(self):
@@ -609,6 +612,10 @@ class GCENetworkingService(BaseNetworkingService):
     def routers(self):
         return self._router_service
 
+    @property
+    def gateways(self):
+        return self._gateway_servcie
+
 
 class GCENetworkService(BaseNetworkService):
 
@@ -815,6 +822,25 @@ class GCERouterService(BaseRouterService):
         self._provider.wait_for_operation(response, region=region)
 
 
+class GCEGatewayService(BaseGatewayService):
+    _DEFAULT_GATEWAY_NAME = 'default-internet-gateway'
+    _GATEWAY_URL_PREFIX = 'global/gateways/'
+
+    def __init__(self, provider):
+        super(GCEGatewayService, self).__init__(provider)
+        self._default_internet_gateway = GCEInternetGateway(
+            provider,
+            {'id': (GCEGatewayService._GATEWAY_URL_PREFIX +
+                    GCEGatewayService._DEFAULT_GATEWAY_NAME),
+             'name': GCEGatewayService._DEFAULT_GATEWAY_NAME})
+
+    def get_or_create_inet_gateway(self, name):
+        return self._default_internet_gateway
+
+    def delete(self, gateway):
+        pass
+
+
 class GCESubnetService(BaseSubnetService):
 
     def __init__(self, provider):