Parcourir la source

Fixed landscape code warnings

Nuwan Goonasekera il y a 8 ans
Parent
commit
3860caed15

+ 1 - 1
cloudbridge/cloud/interfaces/exceptions.py

@@ -65,6 +65,6 @@ class InvalidValueException(CloudBridgeBaseException):
     TrafficDirection.OUTBOUND.
     TrafficDirection.OUTBOUND.
     """
     """
     def __init__(self, param, value):
     def __init__(self, param, value):
-        super(InvalidNameException, self).__init__(
+        super(InvalidValueException, self).__init__(
             "Param %s has been given an unrecognised value %s" %
             "Param %s has been given an unrecognised value %s" %
             (param, value))
             (param, value))

+ 13 - 6
cloudbridge/cloud/interfaces/resources.py

@@ -860,18 +860,18 @@ class Network(ObjectLifeCycleMixin, CloudResource):
         pass
         pass
 
 
     @abstractmethod
     @abstractmethod
-    def create_subnet(self, cidr_block, name=None, zone=None):
+    def create_subnet(self, name, cidr_block, zone=None):
         """
         """
         Create a new network subnet and associate it with this Network.
         Create a new network subnet and associate it with this Network.
 
 
+        :type name: ``str``
+        :param name: The subnet name. The name will be set if the
+                     provider supports it.
+
         :type cidr_block: ``str``
         :type cidr_block: ``str``
         :param cidr_block: CIDR block within this Network to assign to the
         :param cidr_block: CIDR block within this Network to assign to the
                            subnet.
                            subnet.
 
 
-        :type name: ``str``
-        :param name: An optional subnet name. The name will be set if the
-                     provider supports it.
-
         :type zone: ``str``
         :type zone: ``str``
         :param zone: Placement zone where to create the subnet. Some providers
         :param zone: Placement zone where to create the subnet. Some providers
                      may not support subnet zones, in which case the value is
                      may not support subnet zones, in which case the value is
@@ -2115,6 +2115,7 @@ class BucketContainer(PageableObjectMixin):
         pass
         pass
 
 
     @abstractmethod
     @abstractmethod
+    # pylint:disable=arguments-differ
     def list(self, limit=None, marker=None, prefix=None):
     def list(self, limit=None, marker=None, prefix=None):
         """
         """
         List objects in this bucket.
         List objects in this bucket.
@@ -2134,12 +2135,18 @@ class BucketContainer(PageableObjectMixin):
         pass
         pass
 
 
     @abstractmethod
     @abstractmethod
-    def find(self, name):
+    def find(self, name, limit=None, marker=None):
         """
         """
         Searches for an object by a given name
         Searches for an object by a given name
 
 
         :rtype: List of ``objects`` of :class:`.BucketObject`
         :rtype: List of ``objects`` of :class:`.BucketObject`
         :return: A list of BucketObjects matching the supplied attributes.
         :return: A list of BucketObjects matching the supplied attributes.
+
+        :type limit: ``int``
+        :param limit: Maximum number of elements to return.
+
+        :type marker: ``int``
+        :param marker: Fetch results after this offset.
         """
         """
         pass
         pass
 
 

+ 34 - 7
cloudbridge/cloud/interfaces/services.py

@@ -160,10 +160,26 @@ class InstanceService(PageableObjectMixin, CloudService):
         pass
         pass
 
 
     @abstractmethod
     @abstractmethod
-    def find(self, name):
+    def find(self, name, limit=None, marker=None):
         """
         """
         Searches for an instance by a given list of attributes.
         Searches for an instance by a given list of attributes.
 
 
+        :type  name: ``str``
+        :param name: The name to search for
+
+        :type  limit: ``int``
+        :param limit: The maximum number of objects to return. Note that the
+                      maximum is not guaranteed to be honoured, and a lower
+                      maximum may be enforced depending on the provider. In
+                      such a case, the returned ResultList's is_truncated
+                      property can be used to determine whether more records
+                      are available.
+
+        :type  marker: ``str``
+        :param marker: The marker is an opaque identifier used to assist
+                       in paging through very long lists of objects. It is
+                       returned on each invocation of the list method.
+
         :rtype: List of ``object`` of :class:`.Instance`
         :rtype: List of ``object`` of :class:`.Instance`
         :return: A list of Instance objects matching the supplied attributes.
         :return: A list of Instance objects matching the supplied attributes.
         """
         """
@@ -606,7 +622,7 @@ class NetworkService(PageableObjectMixin, CloudService):
         pass
         pass
 
 
     @abstractmethod
     @abstractmethod
-    def find(self, name):
+    def find(self, name, limit=None, marker=None):
         """
         """
         Searches for a network by a given list of attributes.
         Searches for a network by a given list of attributes.
 
 
@@ -693,6 +709,7 @@ class SubnetService(PageableObjectMixin, CloudService):
         pass
         pass
 
 
     @abstractmethod
     @abstractmethod
+    # pylint:disable=arguments-differ
     def list(self, network=None, limit=None, marker=None):
     def list(self, network=None, limit=None, marker=None):
         """
         """
         List all subnets or filter them by the supplied network ID.
         List all subnets or filter them by the supplied network ID.
@@ -705,6 +722,16 @@ class SubnetService(PageableObjectMixin, CloudService):
         """
         """
         pass
         pass
 
 
+    @abstractmethod
+    def find(self, name, limit=None, marker=None):
+        """
+        Searches for a subnet by a given list of attributes.
+
+        :rtype: List of ``object`` of :class:`.Subnet`
+        :return: A list of Subnet objects matching the supplied attributes.
+        """
+        pass
+
     @abstractmethod
     @abstractmethod
     def create(self, name, network_id, cidr_block, zone=None):
     def create(self, name, network_id, cidr_block, zone=None):
         """
         """
@@ -865,17 +892,17 @@ class RouterService(PageableObjectMixin, CloudService):
         pass
         pass
 
 
     @abstractmethod
     @abstractmethod
-    def create(self, network, name=None):
+    def create(self, name, network):
         """
         """
         Create a new router.
         Create a new router.
 
 
-        :type network: :class:`.Network` object or ``str``
-        :param network: Network object or ID under which to create the router.
-
         :type name: ``str``
         :type name: ``str``
         :param name: A router name. The name will be set if the provider
         :param name: A router name. The name will be set if the provider
                      supports it.
                      supports it.
 
 
+        :type network: :class:`.Network` object or ``str``
+        :param network: Network object or ID under which to create the router.
+
         :rtype: ``object`` of :class:`.Router`
         :rtype: ``object`` of :class:`.Router`
         :return:  A Router object
         :return:  A Router object
         """
         """
@@ -961,7 +988,7 @@ class BucketService(PageableObjectMixin, CloudService):
         pass
         pass
 
 
     @abstractmethod
     @abstractmethod
-    def find(self, name):
+    def find(self, name, limit=None, marker=None):
         """
         """
         Searches for a bucket by a given list of attributes.
         Searches for a bucket by a given list of attributes.
 
 

+ 5 - 2
cloudbridge/cloud/providers/aws/helpers.py

@@ -79,12 +79,12 @@ class BotoGenericService(object):
             boto_conn, self.boto_collection_model)
             boto_conn, self.boto_collection_model)
 
 
     def _infer_collection_model(self, conn, collection_name):
     def _infer_collection_model(self, conn, collection_name):
-        log.debug("Retrieving boto model for collection: %s" % collection_name)
+        log.debug("Retrieving boto model for collection: %s", collection_name)
         return next(col for col in conn.meta.resource_model.collections
         return next(col for col in conn.meta.resource_model.collections
                     if col.name == collection_name)
                     if col.name == collection_name)
 
 
     def _infer_boto_resource(self, conn, collection_model):
     def _infer_boto_resource(self, conn, collection_model):
-        log.debug("Retrieving resource model for collection: %s" %
+        log.debug("Retrieving resource model for collection: %s",
                   collection_model.name)
                   collection_model.name)
         resource_model = next(
         resource_model = next(
             sr for sr in conn.meta.resource_model.subresources
             sr for sr in conn.meta.resource_model.subresources
@@ -130,6 +130,7 @@ class BotoGenericService(object):
         because paginators() return json responses, and there's no direct way
         because paginators() return json responses, and there's no direct way
         to convert a paginated json response to a Boto Resource.
         to convert a paginated json response to a Boto Resource.
         """
         """
+        # pylint:disable=protected-access
         return collection._handler(collection._parent, params, page)
         return collection._handler(collection._parent, params, page)
 
 
     def _resource_iterator(self, collection, params, pages, limit):
     def _resource_iterator(self, collection, params, pages, limit):
@@ -154,9 +155,11 @@ class BotoGenericService(object):
         protected members of ResourceCollection. This logic can be removed
         protected members of ResourceCollection. This logic can be removed
         depending on issue: https://github.com/boto/boto3/issues/1268.
         depending on issue: https://github.com/boto/boto3/issues/1268.
         """
         """
+        # pylint:disable=protected-access
         cleaned_params = collection._params.copy()
         cleaned_params = collection._params.copy()
         cleaned_params.pop('limit', None)
         cleaned_params.pop('limit', None)
         cleaned_params.pop('page_size', None)
         cleaned_params.pop('page_size', None)
+        # pylint:disable=protected-access
         params = create_request_parameters(
         params = create_request_parameters(
             collection._parent, collection._model.request)
             collection._parent, collection._model.request)
         merge_dicts(params, cleaned_params, append_lists=True)
         merge_dicts(params, cleaned_params, append_lists=True)

+ 12 - 0
cloudbridge/cloud/providers/aws/resources.py

@@ -215,6 +215,7 @@ class AWSInstance(BaseInstance):
         return self._ec2_instance.id
         return self._ec2_instance.id
 
 
     @property
     @property
+    # pylint:disable=arguments-differ
     def name(self):
     def name(self):
         """
         """
         .. note:: an instance must have a (case sensitive) tag ``Name``
         .. note:: an instance must have a (case sensitive) tag ``Name``
@@ -295,6 +296,7 @@ class AWSInstance(BaseInstance):
         params = trim_empty_params({
         params = trim_empty_params({
             'InstanceId': self.id,
             'InstanceId': self.id,
             'PublicIp': None if self._ec2_instance.vpc_id else fip.public_ip,
             'PublicIp': None if self._ec2_instance.vpc_id else fip.public_ip,
+            # pylint:disable=protected-access
             'AllocationId': fip._ip.allocation_id})
             'AllocationId': fip._ip.allocation_id})
         self._provider.ec2_conn.meta.client.associate_address(**params)
         self._provider.ec2_conn.meta.client.associate_address(**params)
         self.refresh()
         self.refresh()
@@ -305,6 +307,7 @@ class AWSInstance(BaseInstance):
             self._provider.networking.floating_ips.get(floating_ip))
             self._provider.networking.floating_ips.get(floating_ip))
         params = trim_empty_params({
         params = trim_empty_params({
             'PublicIp': None if self._ec2_instance.vpc_id else fip.public_ip,
             'PublicIp': None if self._ec2_instance.vpc_id else fip.public_ip,
+            # pylint:disable=protected-access
             'AssociationId': fip._ip.association_id})
             'AssociationId': fip._ip.association_id})
         self._provider.ec2_conn.meta.client.disassociate_address(**params)
         self._provider.ec2_conn.meta.client.disassociate_address(**params)
         self.refresh()
         self.refresh()
@@ -335,6 +338,7 @@ class AWSInstance(BaseInstance):
             # set the state to unknown
             # set the state to unknown
             self._ec2_instance.state = {'Name': InstanceState.UNKNOWN}
             self._ec2_instance.state = {'Name': InstanceState.UNKNOWN}
 
 
+    # pylint:disable=unused-argument
     def _wait_till_exists(self, timeout=None, interval=None):
     def _wait_till_exists(self, timeout=None, interval=None):
         self._ec2_instance.wait_until_exists()
         self._ec2_instance.wait_until_exists()
 
 
@@ -362,6 +366,7 @@ class AWSVolume(BaseVolume):
         return self._volume.id
         return self._volume.id
 
 
     @property
     @property
+    # pylint:disable=arguments-differ
     def name(self):
     def name(self):
         return find_tag_value(self._volume.tags, 'Name')
         return find_tag_value(self._volume.tags, 'Name')
 
 
@@ -471,6 +476,7 @@ class AWSSnapshot(BaseSnapshot):
         return self._snapshot.id
         return self._snapshot.id
 
 
     @property
     @property
+    # pylint:disable=arguments-differ
     def name(self):
     def name(self):
         return find_tag_value(self._snapshot.tags, 'Name')
         return find_tag_value(self._snapshot.tags, 'Name')
 
 
@@ -600,6 +606,7 @@ class AWSVMFirewallRuleContainer(BaseVMFirewallRuleContainer):
             src_dest_fw.id if isinstance(src_dest_fw, AWSVMFirewall)
             src_dest_fw.id if isinstance(src_dest_fw, AWSVMFirewall)
             else src_dest_fw)
             else src_dest_fw)
 
 
+        # pylint:disable=protected-access
         ip_perm_entry = AWSVMFirewallRule._construct_ip_perms(
         ip_perm_entry = AWSVMFirewallRule._construct_ip_perms(
             protocol, from_port, to_port, cidr, src_dest_fw_id)
             protocol, from_port, to_port, cidr, src_dest_fw_id)
         # Filter out empty values to please Boto
         # Filter out empty values to please Boto
@@ -801,6 +808,7 @@ class AWSBucketContainer(BaseBucketContainer):
 
 
     def get(self, name):
     def get(self, name):
         try:
         try:
+            # pylint:disable=protected-access
             obj = self.bucket._bucket.Object(name)
             obj = self.bucket._bucket.Object(name)
             # load() throws an error if object does not exist
             # load() throws an error if object does not exist
             obj.load()
             obj.load()
@@ -810,8 +818,10 @@ class AWSBucketContainer(BaseBucketContainer):
 
 
     def list(self, limit=None, marker=None, prefix=None):
     def list(self, limit=None, marker=None, prefix=None):
         if prefix:
         if prefix:
+            # pylint:disable=protected-access
             boto_objs = self.bucket._bucket.objects.filter(Prefix=prefix)
             boto_objs = self.bucket._bucket.objects.filter(Prefix=prefix)
         else:
         else:
+            # pylint:disable=protected-access
             boto_objs = self.bucket._bucket.objects.all()
             boto_objs = self.bucket._bucket.objects.all()
         objects = [AWSBucketObject(self._provider, obj)
         objects = [AWSBucketObject(self._provider, obj)
                    for obj in boto_objs]
                    for obj in boto_objs]
@@ -826,6 +836,7 @@ class AWSBucketContainer(BaseBucketContainer):
                                      limit=limit, marker=marker)
                                      limit=limit, marker=marker)
 
 
     def create(self, name):
     def create(self, name):
+        # pylint:disable=protected-access
         obj = self.bucket._bucket.Object(name)
         obj = self.bucket._bucket.Object(name)
         return AWSBucketObject(self._provider, obj)
         return AWSBucketObject(self._provider, obj)
 
 
@@ -849,6 +860,7 @@ class AWSRegion(BaseRegion):
         if self.id == self._provider.region_name:  # optimisation
         if self.id == self._provider.region_name:  # optimisation
             conn = self._provider.ec2_conn
             conn = self._provider.ec2_conn
         else:
         else:
+            # pylint:disable=protected-access
             conn = self._provider._conect_ec2_region(region_name=self.id)
             conn = self._provider._conect_ec2_region(region_name=self.id)
 
 
         zones = (conn.meta.client.describe_availability_zones()
         zones = (conn.meta.client.describe_availability_zones()

+ 3 - 2
cloudbridge/cloud/providers/aws/services.py

@@ -346,7 +346,7 @@ class AWSInstanceService(BaseInstanceService):
             key_pair,
             key_pair,
             KeyPair) else key_pair
             KeyPair) else key_pair
         if launch_config:
         if launch_config:
-            bdm = self._process_block_device_mappings(launch_config, zone_id)
+            bdm = self._process_block_device_mappings(launch_config)
         else:
         else:
             bdm = None
             bdm = None
 
 
@@ -368,6 +368,7 @@ class AWSInstanceService(BaseInstanceService):
                                )
                                )
         if inst and len(inst) == 1:
         if inst and len(inst) == 1:
             # Wait until the resource exists
             # Wait until the resource exists
+            # pylint:disable=protected-access
             inst[0]._wait_till_exists()
             inst[0]._wait_till_exists()
             # Tag the instance w/ the name
             # Tag the instance w/ the name
             inst[0].name = name
             inst[0].name = name
@@ -407,7 +408,7 @@ class AWSInstanceService(BaseInstanceService):
             vm_firewall_ids = vm_firewalls
             vm_firewall_ids = vm_firewalls
         return subnet.id, zone_id, vm_firewall_ids
         return subnet.id, zone_id, vm_firewall_ids
 
 
-    def _process_block_device_mappings(self, launch_config, zone=None):
+    def _process_block_device_mappings(self, launch_config):
         """
         """
         Processes block device mapping information
         Processes block device mapping information
         and returns a Boto BlockDeviceMapping object. If new volumes
         and returns a Boto BlockDeviceMapping object. If new volumes

+ 14 - 3
cloudbridge/cloud/providers/openstack/resources.py

@@ -139,7 +139,9 @@ class OpenStackPlacementZone(BasePlacementZone):
     def __init__(self, provider, zone, region):
     def __init__(self, provider, zone, region):
         super(OpenStackPlacementZone, self).__init__(provider)
         super(OpenStackPlacementZone, self).__init__(provider)
         if isinstance(zone, OpenStackPlacementZone):
         if isinstance(zone, OpenStackPlacementZone):
-            self._os_zone = zone._os_zone  # pylint:disable=protected-access
+            # pylint:disable=protected-access
+            self._os_zone = zone._os_zone
+            # pylint:disable=protected-access
             self._os_region = zone._os_region
             self._os_region = zone._os_region
         else:
         else:
             self._os_zone = zone
             self._os_zone = zone
@@ -265,6 +267,7 @@ class OpenStackInstance(BaseInstance):
         return self._os_instance.id
         return self._os_instance.id
 
 
     @property
     @property
+    # pylint:disable=arguments-differ
     def name(self):
     def name(self):
         """
         """
         Get the instance name.
         Get the instance name.
@@ -457,6 +460,7 @@ class OpenStackRegion(BaseRegion):
             zones = self._provider.nova.availability_zones.list(detailed=False)
             zones = self._provider.nova.availability_zones.list(detailed=False)
         else:
         else:
             try:
             try:
+                # pylint:disable=protected-access
                 region_nova = self._provider._connect_nova_region(self.name)
                 region_nova = self._provider._connect_nova_region(self.name)
                 zones = region_nova.availability_zones.list(detailed=False)
                 zones = region_nova.availability_zones.list(detailed=False)
             except novaex.EndpointNotFound:
             except novaex.EndpointNotFound:
@@ -494,6 +498,7 @@ class OpenStackVolume(BaseVolume):
         return self._volume.id
         return self._volume.id
 
 
     @property
     @property
+    # pylint:disable=arguments-differ
     def name(self):
     def name(self):
         """
         """
         Get the volume name.
         Get the volume name.
@@ -501,7 +506,8 @@ class OpenStackVolume(BaseVolume):
         return self._volume.name
         return self._volume.name
 
 
     @name.setter
     @name.setter
-    def name(self, value):  # pylint:disable=arguments-differ
+    # pylint:disable=arguments-differ
+    def name(self, value):
         """
         """
         Set the volume name.
         Set the volume name.
         """
         """
@@ -615,6 +621,7 @@ class OpenStackSnapshot(BaseSnapshot):
         return self._snapshot.id
         return self._snapshot.id
 
 
     @property
     @property
+    # pylint:disable=arguments-differ
     def name(self):
     def name(self):
         """
         """
         Get the snapshot name.
         Get the snapshot name.
@@ -622,7 +629,8 @@ class OpenStackSnapshot(BaseSnapshot):
         return self._snapshot.name
         return self._snapshot.name
 
 
     @name.setter
     @name.setter
-    def name(self, value):  # pylint:disable=arguments-differ
+    # pylint:disable=arguments-differ
+    def name(self, value):
         """
         """
         Set the snapshot name.
         Set the snapshot name.
         """
         """
@@ -943,6 +951,7 @@ class OpenStackInternetGateway(BaseInternetGateway):
     def __init__(self, provider, gateway_net):
     def __init__(self, provider, gateway_net):
         super(OpenStackInternetGateway, self).__init__(provider)
         super(OpenStackInternetGateway, self).__init__(provider)
         if isinstance(gateway_net, OpenStackNetwork):
         if isinstance(gateway_net, OpenStackNetwork):
+            # pylint:disable=protected-access
             gateway_net = gateway_net._network
             gateway_net = gateway_net._network
         self._gateway_net = gateway_net
         self._gateway_net = gateway_net
 
 
@@ -1205,6 +1214,7 @@ class OpenStackBucketObject(BaseBucketObject):
                 upload_options['segment_size'] = FIVE_GIG
                 upload_options['segment_size'] = FIVE_GIG
 
 
         # remap the swift service's connection factory method
         # remap the swift service's connection factory method
+        # pylint:disable=protected-access
         swiftclient.service.get_conn = self._provider._connect_swift
         swiftclient.service.get_conn = self._provider._connect_swift
 
 
         result = True
         result = True
@@ -1229,6 +1239,7 @@ class OpenStackBucketObject(BaseBucketObject):
         """
         """
 
 
         # remap the swift service's connection factory method
         # remap the swift service's connection factory method
+        # pylint:disable=protected-access
         swiftclient.service.get_conn = self._provider._connect_swift
         swiftclient.service.get_conn = self._provider._connect_swift
 
 
         result = True
         result = True

+ 3 - 3
cloudbridge/cloud/providers/openstack/services.py

@@ -572,8 +572,8 @@ class OpenStackInstanceService(BaseInstanceService):
         sg_name_list = []
         sg_name_list = []
         nics = None
         nics = None
         if subnet_id:
         if subnet_id:
-            log.debug("Creating network port for %s in subnet: %s" %
-                      (name, subnet_id))
+            log.debug("Creating network port for %s in subnet: %s",
+                      name, subnet_id)
             sg_list = []
             sg_list = []
             if vm_firewalls:
             if vm_firewalls:
                 if isinstance(vm_firewalls, list) and \
                 if isinstance(vm_firewalls, list) and \
@@ -603,7 +603,7 @@ class OpenStackInstanceService(BaseInstanceService):
                 else:
                 else:
                     sg_name_list = vm_firewalls
                     sg_name_list = vm_firewalls
 
 
-        log.debug("Launching in subnet %s" % subnet_id)
+        log.debug("Launching in subnet %s", subnet_id)
         os_instance = self.provider.nova.servers.create(
         os_instance = self.provider.nova.servers.create(
             name,
             name,
             None if self._has_root_device(launch_config) else image_id,
             None if self._has_root_device(launch_config) else image_id,