Sfoglia il codice sorgente

VMFirewall Network ID

almahmoud 7 anni fa
parent
commit
446c356e54

+ 1 - 1
cloudbridge/cloud/providers/aws/services.py

@@ -136,7 +136,7 @@ class AWSVMFirewallService(BaseVMFirewallService):
         return self.svc.list(limit=limit, marker=marker)
         return self.svc.list(limit=limit, marker=marker)
 
 
     @cb_helpers.deprecated_alias(network_id='network')
     @cb_helpers.deprecated_alias(network_id='network')
-    def create(self, label, network=None, description=None):
+    def create(self, label, network, description=None):
         log.debug("Creating Firewall Service with the parameters "
         log.debug("Creating Firewall Service with the parameters "
                   "[label: %s id: %s description: %s]", label, network,
                   "[label: %s id: %s description: %s]", label, network,
                   description)
                   description)

+ 1 - 1
cloudbridge/cloud/providers/azure/resources.py

@@ -40,7 +40,7 @@ class AzureVMFirewall(BaseVMFirewall):
 
 
     @property
     @property
     def network_id(self):
     def network_id(self):
-        return None
+        return self._vm_firewall.tags.get('network_id', None)
 
 
     @property
     @property
     def resource_id(self):
     def resource_id(self):

+ 5 - 3
cloudbridge/cloud/providers/azure/services.py

@@ -67,11 +67,13 @@ class AzureVMFirewallService(BaseVMFirewallService):
         return ClientPagedResultList(self.provider, fws, limit, marker)
         return ClientPagedResultList(self.provider, fws, limit, marker)
 
 
     @cb_helpers.deprecated_alias(network_id='network')
     @cb_helpers.deprecated_alias(network_id='network')
-    def create(self, label, network=None, description=None):
+    def create(self, label, network, description=None):
         AzureVMFirewall.assert_valid_resource_label(label)
         AzureVMFirewall.assert_valid_resource_label(label)
         name = AzureVMFirewall._generate_name_from_label(label, "cb-fw")
         name = AzureVMFirewall._generate_name_from_label(label, "cb-fw")
+        net = network.id if isinstance(network, Network) else network
         parameters = {"location": self.provider.region_name,
         parameters = {"location": self.provider.region_name,
-                      "tags": {'Label': label}}
+                      "tags": {'Label': label,
+                               'network_id': net}}
 
 
         if description:
         if description:
             parameters['tags'].update(Description=description)
             parameters['tags'].update(Description=description)
@@ -256,7 +258,7 @@ class AzureVolumeService(BaseVolumeService):
         return ClientPagedResultList(self.provider, cb_vols,
         return ClientPagedResultList(self.provider, cb_vols,
                                      limit=limit, marker=marker)
                                      limit=limit, marker=marker)
 
 
-    def create(self, label, size, zone=None, description=None,
+    def create(self, label, size, zone, description=None,
                snapshot=None):
                snapshot=None):
         """
         """
         Creates a new volume.
         Creates a new volume.

+ 6 - 1
cloudbridge/cloud/providers/openstack/resources.py

@@ -1215,7 +1215,12 @@ class OpenStackVMFirewall(BaseVMFirewall):
 
 
         :return: Always return ``None``.
         :return: Always return ``None``.
         """
         """
-        return None
+        # Best way would be to use regex, but using this hacky way to avoid
+        # importing the re package
+        desc = self.description
+        net_id = desc.split("[CB-AUTO-associated-network-id: ")[-1]\
+                     .split(']')[0]
+        return net_id
 
 
     @property
     @property
     def name(self):
     def name(self):

+ 7 - 0
cloudbridge/cloud/providers/openstack/services.py

@@ -37,6 +37,7 @@ from cloudbridge.cloud.interfaces.exceptions \
     import DuplicateResourceException
     import DuplicateResourceException
 from cloudbridge.cloud.interfaces.resources import KeyPair
 from cloudbridge.cloud.interfaces.resources import KeyPair
 from cloudbridge.cloud.interfaces.resources import MachineImage
 from cloudbridge.cloud.interfaces.resources import MachineImage
+from cloudbridge.cloud.interfaces.resources import Network
 from cloudbridge.cloud.interfaces.resources import PlacementZone
 from cloudbridge.cloud.interfaces.resources import PlacementZone
 from cloudbridge.cloud.interfaces.resources import Snapshot
 from cloudbridge.cloud.interfaces.resources import Snapshot
 from cloudbridge.cloud.interfaces.resources import Subnet
 from cloudbridge.cloud.interfaces.resources import Subnet
@@ -216,6 +217,12 @@ class OpenStackVMFirewallService(BaseVMFirewallService):
         log.debug("Creating OpenStack VM Firewall with the params: "
         log.debug("Creating OpenStack VM Firewall with the params: "
                   "[label: %s network id: %s description: %s]", label,
                   "[label: %s network id: %s description: %s]", label,
                   network, description)
                   network, description)
+        net = network.id if isinstance(network, Network) else network
+        if not description:
+            description = ""
+        else:
+            description += "   "
+        description += "[CB-AUTO-associated-network-id: {}]".format(net)
         sg = self.provider.os_conn.network.create_security_group(
         sg = self.provider.os_conn.network.create_security_group(
             name=label, description=description or label)
             name=label, description=description or label)
         if sg:
         if sg:

+ 5 - 0
docs/topics/azure_mapping.rst

@@ -30,6 +30,11 @@ remain unchanged, as it is part of the ID. Finally, labeled resources support
 a `label` parameter for the `find` method in their corresponding services.
 a `label` parameter for the `find` method in their corresponding services.
 The below screenshots will help map these properties to Azure objects in the
 The below screenshots will help map these properties to Azure objects in the
 web portal.
 web portal.
+Additionally, although Azure Security Groups are not associated with a
+specific network, such an association is done in CloudBridge, due to its
+necessity in AWS. As such, the VMFirewall creation method requires a
+`network` parameter and the association is accomplished in OpenStack through
+a tag with the key `network_id`.
 
 
 .. figure:: captures/az-label-dash.png
 .. figure:: captures/az-label-dash.png
    :scale: 50 %
    :scale: 50 %

+ 6 - 0
docs/topics/os_mapping.rst

@@ -30,6 +30,12 @@ identifier even though not easily readable in this context. Finally, labeled res
 support a `label` parameter for the `find` method in their corresponding services.
 support a `label` parameter for the `find` method in their corresponding services.
 The below screenshots will help map these properties to OpenStack objects in the
 The below screenshots will help map these properties to OpenStack objects in the
 web portal.
 web portal.
+Additionally, although OpenStack Security Groups are not associated with a
+specific network, such an association is done in CloudBridge, due to its
+necessity in AWS. As such, the VMFirewall creation method requires a
+`network` parameter and the association is accomplished in OpenStack through
+the description, by appending the following string to the user-provided description
+(if any) at creation: "[CB-AUTO-associated-network-id: associated_net_id]"
 
 
 .. figure:: captures/os-instance-dash.png
 .. figure:: captures/os-instance-dash.png
    :scale: 50 %
    :scale: 50 %

+ 7 - 2
test/test_security_service.py

@@ -66,14 +66,19 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
 
 
         def create_fw(label):
         def create_fw(label):
             return self.provider.security.vm_firewalls.create(
             return self.provider.security.vm_firewalls.create(
-                label=label, description=label, network_id=net.id)
+                label=label, description=label, network=net.id)
 
 
         def cleanup_fw(fw):
         def cleanup_fw(fw):
             if fw:
             if fw:
                 fw.delete()
                 fw.delete()
 
 
+        def network_id_test(fw):
+            # Checking that the network ID is returned correctly
+            self.assertEqual(fw.network_id, net.id)
+
         sit.check_crud(self, self.provider.security.vm_firewalls,
         sit.check_crud(self, self.provider.security.vm_firewalls,
-                       VMFirewall, "cb-crudfw", create_fw, cleanup_fw)
+                       VMFirewall, "cb-crudfw", create_fw, cleanup_fw,
+                       extra_test_func=network_id_test)
 
 
     @helpers.skipIfNoService(['security.vm_firewalls'])
     @helpers.skipIfNoService(['security.vm_firewalls'])
     def test_vm_firewall_properties(self):
     def test_vm_firewall_properties(self):