diff --git a/SoftLayer/CLI/block/detail.py b/SoftLayer/CLI/block/detail.py index 6b1b7288c..2e7b115e7 100644 --- a/SoftLayer/CLI/block/detail.py +++ b/SoftLayer/CLI/block/detail.py @@ -5,6 +5,7 @@ import SoftLayer from SoftLayer.CLI import environment from SoftLayer.CLI import formatting +from SoftLayer.CLI import helpers from SoftLayer import utils @@ -14,7 +15,8 @@ def cli(env, volume_id): """Display details for a specified volume.""" block_manager = SoftLayer.BlockStorageManager(env.client) - block_volume = block_manager.get_block_volume_details(volume_id) + block_volume_id = helpers.resolve_id(block_manager.resolve_ids, volume_id, 'Block Volume') + block_volume = block_manager.get_block_volume_details(block_volume_id) block_volume = utils.NestedDict(block_volume) table = formatting.KeyValueTable(['Name', 'Value']) diff --git a/SoftLayer/CLI/file/detail.py b/SoftLayer/CLI/file/detail.py index 02bb5c17a..cea86e351 100644 --- a/SoftLayer/CLI/file/detail.py +++ b/SoftLayer/CLI/file/detail.py @@ -5,6 +5,7 @@ import SoftLayer from SoftLayer.CLI import environment from SoftLayer.CLI import formatting +from SoftLayer.CLI import helpers from SoftLayer import utils @@ -14,7 +15,8 @@ def cli(env, volume_id): """Display details for a specified volume.""" file_manager = SoftLayer.FileStorageManager(env.client) - file_volume = file_manager.get_file_volume_details(volume_id) + file_volume_id = helpers.resolve_id(file_manager.resolve_ids, volume_id, 'File Storage') + file_volume = file_manager.get_file_volume_details(file_volume_id) file_volume = utils.NestedDict(file_volume) table = formatting.KeyValueTable(['Name', 'Value']) diff --git a/SoftLayer/fixtures/SoftLayer_Location_Datacenter.py b/SoftLayer/fixtures/SoftLayer_Location_Datacenter.py new file mode 100644 index 000000000..e9aa9b48e --- /dev/null +++ b/SoftLayer/fixtures/SoftLayer_Location_Datacenter.py @@ -0,0 +1,12 @@ +getDatacenters = [ + { + "id": 1441195, + "longName": "Dallas 10", + "name": "dal10" + }, + { + "id": 449494, + "longName": "Dallas 9", + "name": "dal09" + } +] diff --git a/SoftLayer/managers/block.py b/SoftLayer/managers/block.py index 25e6839f2..4d129d07c 100644 --- a/SoftLayer/managers/block.py +++ b/SoftLayer/managers/block.py @@ -5,34 +5,27 @@ :license: MIT, see LICENSE for more details. """ -from SoftLayer import exceptions +from SoftLayer.managers.storage import StorageManager from SoftLayer.managers import storage_utils from SoftLayer import utils # pylint: disable=too-many-public-methods -class BlockStorageManager(utils.IdentifierMixin, object): +class BlockStorageManager(StorageManager): """Manages SoftLayer Block Storage volumes. See product information here: http://www.softlayer.com/block-storage - - :param SoftLayer.API.BaseClient client: the client instance """ - def __init__(self, client): - self.configuration = {} - self.client = client - def list_block_volume_limit(self): """Returns a list of block volume count limit. :return: Returns a list of block volume count limit. """ - return self.client.call('Network_Storage', 'getVolumeCountLimits') + return self.get_volume_count_limits() - def list_block_volumes(self, datacenter=None, username=None, - storage_type=None, **kwargs): + def list_block_volumes(self, datacenter=None, username=None, storage_type=None, **kwargs): """Returns a list of block volumes. :param datacenter: Datacenter short name (e.g.: dal09) @@ -84,35 +77,7 @@ def get_block_volume_details(self, volume_id, **kwargs): :param kwargs: :return: Returns details about the specified volume. """ - - if 'mask' not in kwargs: - items = [ - 'id', - 'username', - 'password', - 'capacityGb', - 'snapshotCapacityGb', - 'parentVolume.snapshotSizeBytes', - 'storageType.keyName', - 'serviceResource.datacenter[name]', - 'serviceResourceBackendIpAddress', - 'storageTierLevel', - 'provisionedIops', - 'lunId', - 'originalVolumeName', - 'originalSnapshotName', - 'originalVolumeSize', - 'activeTransactionCount', - 'activeTransactions.transactionStatus[friendlyName]', - 'replicationPartnerCount', - 'replicationStatus', - 'replicationPartners[id,username,' - 'serviceResourceBackendIpAddress,' - 'serviceResource[datacenter[name]],' - 'replicationSchedule[type[keyname]]]', - ] - kwargs['mask'] = ','.join(items) - return self.client.call('Network_Storage', 'getObject', id=volume_id, **kwargs) + return self.get_volume_details(volume_id, **kwargs) def get_block_volume_access_list(self, volume_id, **kwargs): """Returns a list of authorized hosts for a specified volume. @@ -121,17 +86,7 @@ def get_block_volume_access_list(self, volume_id, **kwargs): :param kwargs: :return: Returns a list of authorized hosts for a specified volume. """ - if 'mask' not in kwargs: - items = [ - 'id', - 'allowedVirtualGuests[allowedHost[credential, sourceSubnet]]', - 'allowedHardware[allowedHost[credential]]', - 'allowedSubnets[allowedHost[credential]]', - 'allowedIpAddresses[allowedHost[credential]]', - ] - kwargs['mask'] = ','.join(items) - return self.client.call('Network_Storage', 'getObject', - id=volume_id, **kwargs) + return self.get_volume_access_list(volume_id, **kwargs) def get_block_volume_snapshot_list(self, volume_id, **kwargs): """Returns a list of snapshots for the specified volume. @@ -140,73 +95,7 @@ def get_block_volume_snapshot_list(self, volume_id, **kwargs): :param kwargs: :return: Returns a list of snapshots for the specified volume. """ - if 'mask' not in kwargs: - items = [ - 'id', - 'notes', - 'snapshotSizeBytes', - 'storageType[keyName]', - 'snapshotCreationTimestamp', - 'intervalSchedule', - 'hourlySchedule', - 'dailySchedule', - 'weeklySchedule' - ] - - kwargs['mask'] = ','.join(items) - - return self.client.call('Network_Storage', 'getSnapshots', - id=volume_id, **kwargs) - - def authorize_host_to_volume(self, volume_id, - hardware_ids=None, - virtual_guest_ids=None, - ip_address_ids=None, - **kwargs): - """Authorizes hosts to Block Storage Volumes - - :param volume_id: The Block volume to authorize hosts to - :param hardware_ids: A List of SoftLayer_Hardware ids - :param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids - :param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids - :return: Returns an array of - SoftLayer_Network_Storage_Allowed_Host objects - which now have access to the given Block volume - """ - host_templates = [] - storage_utils.populate_host_templates(host_templates, - hardware_ids, - virtual_guest_ids, - ip_address_ids, - None) - - return self.client.call('Network_Storage', 'allowAccessFromHostList', - host_templates, id=volume_id, **kwargs) - - def deauthorize_host_to_volume(self, volume_id, - hardware_ids=None, - virtual_guest_ids=None, - ip_address_ids=None, - **kwargs): - """Revokes authorization of hosts to Block Storage Volumes - - :param volume_id: The Block volume to deauthorize hosts to - :param hardware_ids: A List of SoftLayer_Hardware ids - :param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids - :param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids - :return: Returns an array of - SoftLayer_Network_Storage_Allowed_Host objects - which have access to the given Block volume - """ - host_templates = [] - storage_utils.populate_host_templates(host_templates, - hardware_ids, - virtual_guest_ids, - ip_address_ids, - None) - - return self.client.call('Network_Storage', 'removeAccessFromHostList', - host_templates, id=volume_id, **kwargs) + return self.get_volume_snapshot_list(volume_id, **kwargs) def assign_subnets_to_acl(self, access_id, subnet_ids): """Assigns subnet records to ACL for the access host. @@ -217,10 +106,7 @@ def assign_subnets_to_acl(self, access_id, subnet_ids): :param list subnet_ids: The ids of the subnets to be assigned :return: Returns int array of assigned subnet ids """ - return self.client.call('Network_Storage_Allowed_Host', - 'assignSubnetsToAcl', - subnet_ids, - id=access_id) + return self.client.call('Network_Storage_Allowed_Host', 'assignSubnetsToAcl', subnet_ids, id=access_id) def remove_subnets_from_acl(self, access_id, subnet_ids): """Removes subnet records from ACL for the access host. @@ -231,10 +117,7 @@ def remove_subnets_from_acl(self, access_id, subnet_ids): :param list subnet_ids: The ids of the subnets to be removed :return: Returns int array of removed subnet ids """ - return self.client.call('Network_Storage_Allowed_Host', - 'removeSubnetsFromAcl', - subnet_ids, - id=access_id) + return self.client.call('Network_Storage_Allowed_Host', 'removeSubnetsFromAcl', subnet_ids, id=access_id) def get_subnets_in_acl(self, access_id): """Returns a list of subnet records for the access host. @@ -244,153 +127,7 @@ def get_subnets_in_acl(self, access_id): :param integer access_id: id of the access host :return: Returns an array of SoftLayer_Network_Subnet objects """ - return self.client.call('Network_Storage_Allowed_Host', - 'getSubnetsInAcl', - id=access_id) - - def get_replication_partners(self, volume_id): - """Acquires list of replicant volumes pertaining to the given volume. - - :param volume_id: The ID of the primary volume to be replicated - :return: Returns an array of SoftLayer_Location objects - """ - return self.client.call('Network_Storage', - 'getReplicationPartners', - id=volume_id) - - def get_replication_locations(self, volume_id): - """Acquires list of the datacenters to which a volume can be replicated. - - :param volume_id: The ID of the primary volume to be replicated - :return: Returns an array of SoftLayer_Network_Storage objects - """ - return self.client.call('Network_Storage', - 'getValidReplicationTargetDatacenterLocations', - id=volume_id) - - def order_replicant_volume(self, volume_id, snapshot_schedule, - location, tier=None, os_type=None): - """Places an order for a replicant block volume. - - :param volume_id: The ID of the primary volume to be replicated - :param snapshot_schedule: The primary volume's snapshot - schedule to use for replication - :param location: The location for the ordered replicant volume - :param tier: The tier (IOPS per GB) of the primary volume - :param os_type: The OS type of the primary volume - :return: Returns a SoftLayer_Container_Product_Order_Receipt - """ - - block_mask = 'billingItem[activeChildren,hourlyFlag],'\ - 'storageTierLevel,osType,staasVersion,'\ - 'hasEncryptionAtRest,snapshotCapacityGb,schedules,'\ - 'intervalSchedule,hourlySchedule,dailySchedule,'\ - 'weeklySchedule,storageType[keyName],provisionedIops' - block_volume = self.get_block_volume_details(volume_id, - mask=block_mask) - - if os_type is None: - if isinstance(utils.lookup(block_volume, 'osType', 'keyName'), - str): - os_type = block_volume['osType']['keyName'] - else: - raise exceptions.SoftLayerError( - "Cannot find primary volume's os-type " - "automatically; must specify manually") - - order = storage_utils.prepare_replicant_order_object( - self, snapshot_schedule, location, tier, block_volume, 'block' - ) - - order['osFormatType'] = {'keyName': os_type} - - return self.client.call('Product_Order', 'placeOrder', order) - - def order_duplicate_volume(self, origin_volume_id, origin_snapshot_id=None, - duplicate_size=None, duplicate_iops=None, - duplicate_tier_level=None, - duplicate_snapshot_size=None, - hourly_billing_flag=False, - dependent_duplicate=False): - """Places an order for a duplicate block volume. - - :param origin_volume_id: The ID of the origin volume to be duplicated - :param origin_snapshot_id: Origin snapshot ID to use for duplication - :param duplicate_size: Size/capacity for the duplicate volume - :param duplicate_iops: The IOPS per GB for the duplicate volume - :param duplicate_tier_level: Tier level for the duplicate volume - :param duplicate_snapshot_size: Snapshot space size for the duplicate - :param hourly_billing_flag: Billing type, monthly (False) - or hourly (True), default to monthly. - :param dependent_duplicate: Duplicate type, normal (False) or dependent duplicate (True) - :return: Returns a SoftLayer_Container_Product_Order_Receipt - """ - - block_mask = 'id,billingItem[location,hourlyFlag],snapshotCapacityGb,'\ - 'storageType[keyName],capacityGb,originalVolumeSize,'\ - 'provisionedIops,storageTierLevel,osType[keyName],'\ - 'staasVersion,hasEncryptionAtRest' - origin_volume = self.get_block_volume_details(origin_volume_id, - mask=block_mask) - - if isinstance(utils.lookup(origin_volume, 'osType', 'keyName'), str): - os_type = origin_volume['osType']['keyName'] - else: - raise exceptions.SoftLayerError( - "Cannot find origin volume's os-type") - - order = storage_utils.prepare_duplicate_order_object( - self, origin_volume, duplicate_iops, duplicate_tier_level, - duplicate_size, duplicate_snapshot_size, 'block', - hourly_billing_flag - ) - - order['osFormatType'] = {'keyName': os_type} - - if origin_snapshot_id is not None: - order['duplicateOriginSnapshotId'] = origin_snapshot_id - - if dependent_duplicate: - order['isDependentDuplicateFlag'] = 1 - - return self.client.call('Product_Order', 'placeOrder', order) - - def order_modified_volume(self, volume_id, new_size=None, new_iops=None, new_tier_level=None): - """Places an order for modifying an existing block volume. - - :param volume_id: The ID of the volume to be modified - :param new_size: The new size/capacity for the volume - :param new_iops: The new IOPS for the volume - :param new_tier_level: The new tier level for the volume - :return: Returns a SoftLayer_Container_Product_Order_Receipt - """ - - mask_items = [ - 'id', - 'billingItem', - 'storageType[keyName]', - 'capacityGb', - 'provisionedIops', - 'storageTierLevel', - 'staasVersion', - 'hasEncryptionAtRest', - ] - block_mask = ','.join(mask_items) - volume = self.get_block_volume_details(volume_id, mask=block_mask) - - order = storage_utils.prepare_modify_order_object( - self, volume, new_iops, new_tier_level, new_size - ) - - return self.client.call('Product_Order', 'placeOrder', order) - - def delete_snapshot(self, snapshot_id): - """Deletes the specified snapshot object. - - :param snapshot_id: The ID of the snapshot object to delete. - """ - return self.client.call('Network_Storage', 'deleteObject', - id=snapshot_id) + return self.client.call('Network_Storage_Allowed_Host', 'getSubnetsInAcl', id=access_id) def order_block_volume(self, storage_type, location, size, os_type, iops=None, tier_level=None, snapshot_size=None, @@ -420,182 +157,14 @@ def order_block_volume(self, storage_type, location, size, os_type, return self.client.call('Product_Order', 'placeOrder', order) - def create_snapshot(self, volume_id, notes='', **kwargs): - """Creates a snapshot on the given block volume. - - :param integer volume_id: The id of the volume - :param string notes: The notes or "name" to assign the snapshot - :return: Returns the id of the new snapshot - """ - - return self.client.call('Network_Storage', 'createSnapshot', - notes, id=volume_id, **kwargs) - - def order_snapshot_space(self, volume_id, capacity, tier, - upgrade, **kwargs): - """Orders snapshot space for the given block volume. - - :param integer volume_id: The id of the volume - :param integer capacity: The capacity to order, in GB - :param float tier: The tier level of the block volume, in IOPS per GB - :param boolean upgrade: Flag to indicate if this order is an upgrade - :return: Returns a SoftLayer_Container_Product_Order_Receipt - """ - block_mask = 'id,billingItem[location,hourlyFlag],'\ - 'storageType[keyName],storageTierLevel,provisionedIops,'\ - 'staasVersion,hasEncryptionAtRest' - block_volume = self.get_block_volume_details(volume_id, - mask=block_mask, - **kwargs) - - order = storage_utils.prepare_snapshot_order_object( - self, block_volume, capacity, tier, upgrade) - - return self.client.call('Product_Order', 'placeOrder', order) - - def cancel_snapshot_space(self, volume_id, - reason='No longer needed', - immediate=False): - """Cancels snapshot space for a given volume. - - :param integer volume_id: The volume ID - :param string reason: The reason for cancellation - :param boolean immediate_flag: Cancel immediately or on anniversary date - """ - - block_volume = self.get_block_volume_details( - volume_id, - mask='mask[id,billingItem[activeChildren,hourlyFlag]]') - - if 'activeChildren' not in block_volume['billingItem']: - raise exceptions.SoftLayerError( - 'No snapshot space found to cancel') - - children_array = block_volume['billingItem']['activeChildren'] - billing_item_id = None - - for child in children_array: - if child['categoryCode'] == 'storage_snapshot_space': - billing_item_id = child['id'] - break - - if not billing_item_id: - raise exceptions.SoftLayerError( - 'No snapshot space found to cancel') - - if utils.lookup(block_volume, 'billingItem', 'hourlyFlag'): - immediate = True - - return self.client['Billing_Item'].cancelItem( - immediate, - True, - reason, - id=billing_item_id) - - def enable_snapshots(self, volume_id, schedule_type, retention_count, - minute, hour, day_of_week, **kwargs): - """Enables snapshots for a specific block volume at a given schedule - - :param integer volume_id: The id of the volume - :param string schedule_type: 'HOURLY'|'DAILY'|'WEEKLY' - :param integer retention_count: Number of snapshots to be kept - :param integer minute: Minute when to take snapshot - :param integer hour: Hour when to take snapshot - :param string day_of_week: Day when to take snapshot - :return: Returns whether successfully scheduled or not - """ - - return self.client.call('Network_Storage', 'enableSnapshots', - schedule_type, - retention_count, - minute, - hour, - day_of_week, - id=volume_id, - **kwargs) - - def disable_snapshots(self, volume_id, schedule_type): - """Disables snapshots for a specific block volume at a given schedule - - :param integer volume_id: The id of the volume - :param string schedule_type: 'HOURLY'|'DAILY'|'WEEKLY' - :return: Returns whether successfully disabled or not - """ - - return self.client.call('Network_Storage', 'disableSnapshots', - schedule_type, id=volume_id) - - def list_volume_schedules(self, volume_id): - """Lists schedules for a given volume - - :param integer volume_id: The id of the volume - :return: Returns list of schedules assigned to a given volume - """ - volume_detail = self.client.call( - 'Network_Storage', - 'getObject', - id=volume_id, - mask='schedules[type,properties[type]]') - - return utils.lookup(volume_detail, 'schedules') - - def restore_from_snapshot(self, volume_id, snapshot_id): - """Restores a specific volume from a snapshot - - :param integer volume_id: The id of the volume - :param integer snapshot_id: The id of the restore point - :return: Returns whether succesfully restored or not - """ - - return self.client.call('Network_Storage', 'restoreFromSnapshot', - snapshot_id, id=volume_id) - - def cancel_block_volume(self, volume_id, - reason='No longer needed', - immediate=False): + def cancel_block_volume(self, volume_id, reason='No longer needed', immediate=False): """Cancels the given block storage volume. :param integer volume_id: The volume ID :param string reason: The reason for cancellation :param boolean immediate_flag: Cancel immediately or on anniversary date """ - block_volume = self.get_block_volume_details( - volume_id, - mask='mask[id,billingItem[id,hourlyFlag]]') - - if 'billingItem' not in block_volume: - raise exceptions.SoftLayerError("Block Storage was already cancelled") - - billing_item_id = block_volume['billingItem']['id'] - - if utils.lookup(block_volume, 'billingItem', 'hourlyFlag'): - immediate = True - - return self.client['Billing_Item'].cancelItem( - immediate, - True, - reason, - id=billing_item_id) - - def failover_to_replicant(self, volume_id, replicant_id): - """Failover to a volume replicant. - - :param integer volume_id: The id of the volume - :param integer replicant_id: ID of replicant to failover to - :return: Returns whether failover was successful or not - """ - - return self.client.call('Network_Storage', 'failoverToReplicant', - replicant_id, id=volume_id) - - def failback_from_replicant(self, volume_id): - """Failback from a volume replicant. - - :param integer volume_id: The id of the volume - :return: Returns whether failback was successful or not - """ - - return self.client.call('Network_Storage', 'failbackFromReplicant', id=volume_id) + return self.cancel_volume(volume_id, reason, immediate) def set_credential_password(self, access_id, password): """Sets the password for an access host @@ -614,5 +183,11 @@ def create_or_update_lun_id(self, volume_id, lun_id): :param integer lun_id: LUN ID to set on the volume :return: a SoftLayer_Network_Storage_Property object """ - return self.client.call('Network_Storage', 'createOrUpdateLunId', - lun_id, id=volume_id) + return self.client.call('Network_Storage', 'createOrUpdateLunId', lun_id, id=volume_id) + + def _get_ids_from_username(self, username): + object_mask = "mask[id]" + results = self.list_block_volumes(username=username, mask=object_mask) + if results: + return [result['id'] for result in results] + return [] diff --git a/SoftLayer/managers/file.py b/SoftLayer/managers/file.py index 0a5214e67..ce1b951c8 100644 --- a/SoftLayer/managers/file.py +++ b/SoftLayer/managers/file.py @@ -5,29 +5,24 @@ :license: MIT, see LICENSE for more details. """ -from SoftLayer import exceptions +from SoftLayer.managers.storage import StorageManager from SoftLayer.managers import storage_utils from SoftLayer import utils # pylint: disable=too-many-public-methods -class FileStorageManager(utils.IdentifierMixin, object): +class FileStorageManager(StorageManager): """Manages file Storage volumes.""" - def __init__(self, client): - self.configuration = {} - self.client = client - def list_file_volume_limit(self): - """Returns a list of file volume count limit. + """Returns a list of block volume count limit. - :return: Returns a list of file volume count limit. + :return: Returns a list of block volume count limit. """ - return self.client.call('Network_Storage', 'getVolumeCountLimits') + return self.get_volume_count_limits() - def list_file_volumes(self, datacenter=None, username=None, - storage_type=None, **kwargs): + def list_file_volumes(self, datacenter=None, username=None, storage_type=None, **kwargs): """Returns a list of file volumes. :param datacenter: Datacenter short name (e.g.: dal09) @@ -109,8 +104,7 @@ def get_file_volume_details(self, volume_id, **kwargs): 'replicationSchedule[type[keyname]]]', ] kwargs['mask'] = ','.join(items) - return self.client.call('Network_Storage', 'getObject', - id=volume_id, **kwargs) + return self.get_volume_details(volume_id, **kwargs) def get_file_volume_access_list(self, volume_id, **kwargs): """Returns a list of authorized hosts for a specified volume. @@ -119,17 +113,7 @@ def get_file_volume_access_list(self, volume_id, **kwargs): :param kwargs: :return: Returns a list of authorized hosts for a specified volume. """ - if 'mask' not in kwargs: - items = [ - 'id', - 'allowedVirtualGuests[allowedHost[credential, sourceSubnet]]', - 'allowedHardware[allowedHost[credential]]', - 'allowedSubnets[allowedHost[credential]]', - 'allowedIpAddresses[allowedHost[credential]]', - ] - kwargs['mask'] = ','.join(items) - return self.client.call('Network_Storage', 'getObject', - id=volume_id, **kwargs) + return self.get_volume_access_list(volume_id, **kwargs) def get_file_volume_snapshot_list(self, volume_id, **kwargs): """Returns a list of snapshots for the specified volume. @@ -138,200 +122,7 @@ def get_file_volume_snapshot_list(self, volume_id, **kwargs): :param kwargs: :return: Returns a list of snapshots for the specified volume. """ - if 'mask' not in kwargs: - items = [ - 'id', - 'notes', - 'snapshotSizeBytes', - 'storageType[keyName]', - 'snapshotCreationTimestamp', - 'intervalSchedule', - 'hourlySchedule', - 'dailySchedule', - 'weeklySchedule' - ] - kwargs['mask'] = ','.join(items) - - return self.client.call('Network_Storage', 'getSnapshots', - id=volume_id, **kwargs) - - def authorize_host_to_volume(self, volume_id, - hardware_ids=None, - virtual_guest_ids=None, - ip_address_ids=None, - subnet_ids=None, - **kwargs): - """Authorizes hosts to File Storage Volumes - - :param volume_id: The File volume to authorize hosts to - :param hardware_ids: A List of SoftLayer_Hardware ids - :param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids - :param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids - :param subnet_ids: A List of SoftLayer_Network_Subnet ids - :return: Returns an array of - SoftLayer_Network_Storage_Allowed_Host objects - which now have access to the given File volume - """ - host_templates = [] - storage_utils.populate_host_templates(host_templates, - hardware_ids, - virtual_guest_ids, - ip_address_ids, - subnet_ids) - - return self.client.call('Network_Storage', 'allowAccessFromHostList', - host_templates, id=volume_id, **kwargs) - - def deauthorize_host_to_volume(self, volume_id, - hardware_ids=None, - virtual_guest_ids=None, - ip_address_ids=None, - subnet_ids=None, - **kwargs): - """Revokes authorization of hosts to File Storage Volumes - - :param volume_id: The File volume to deauthorize hosts to - :param hardware_ids: A List of SoftLayer_Hardware ids - :param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids - :param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids - :param subnet_ids: A List of SoftLayer_Network_Subnet ids - :return: Returns an array of - SoftLayer_Network_Storage_Allowed_Host objects - which have access to the given File volume - """ - host_templates = [] - storage_utils.populate_host_templates(host_templates, - hardware_ids, - virtual_guest_ids, - ip_address_ids, - subnet_ids) - - return self.client.call('Network_Storage', 'removeAccessFromHostList', - host_templates, id=volume_id, **kwargs) - - def order_replicant_volume(self, volume_id, snapshot_schedule, - location, tier=None): - """Places an order for a replicant file volume. - - :param volume_id: The ID of the primary volume to be replicated - :param snapshot_schedule: The primary volume's snapshot - schedule to use for replication - :param location: The location for the ordered replicant volume - :param tier: The tier (IOPS per GB) of the primary volume - :return: Returns a SoftLayer_Container_Product_Order_Receipt - """ - - file_mask = 'billingItem[activeChildren,hourlyFlag],'\ - 'storageTierLevel,osType,staasVersion,'\ - 'hasEncryptionAtRest,snapshotCapacityGb,schedules,'\ - 'intervalSchedule,hourlySchedule,dailySchedule,'\ - 'weeklySchedule,storageType[keyName],provisionedIops' - file_volume = self.get_file_volume_details(volume_id, - mask=file_mask) - - order = storage_utils.prepare_replicant_order_object( - self, snapshot_schedule, location, tier, file_volume, 'file' - ) - - return self.client.call('Product_Order', 'placeOrder', order) - - def get_replication_partners(self, volume_id): - """Acquires list of replicant volumes pertaining to the given volume. - - :param volume_id: The ID of the primary volume to be replicated - :return: Returns an array of SoftLayer_Location objects - """ - return self.client.call('Network_Storage', - 'getReplicationPartners', - id=volume_id) - - def get_replication_locations(self, volume_id): - """Acquires list of the datacenters to which a volume can be replicated. - - :param volume_id: The ID of the primary volume to be replicated - :return: Returns an array of SoftLayer_Network_Storage objects - """ - return self.client.call('Network_Storage', - 'getValidReplicationTargetDatacenterLocations', - id=volume_id) - - def order_duplicate_volume(self, origin_volume_id, origin_snapshot_id=None, - duplicate_size=None, duplicate_iops=None, - duplicate_tier_level=None, - duplicate_snapshot_size=None, - hourly_billing_flag=False, - dependent_duplicate=False): - """Places an order for a duplicate file volume. - - :param origin_volume_id: The ID of the origin volume to be duplicated - :param origin_snapshot_id: Origin snapshot ID to use for duplication - :param duplicate_size: Size/capacity for the duplicate volume - :param duplicate_iops: The IOPS per GB for the duplicate volume - :param duplicate_tier_level: Tier level for the duplicate volume - :param duplicate_snapshot_size: Snapshot space size for the duplicate - :param hourly_billing_flag: Billing type, monthly (False) - or hourly (True), default to monthly. - :param dependent_duplicate: Duplicate type, normal (False) or dependent duplicate (True) - :return: Returns a SoftLayer_Container_Product_Order_Receipt - """ - - file_mask = 'id,billingItem[location,hourlyFlag],snapshotCapacityGb,'\ - 'storageType[keyName],capacityGb,originalVolumeSize,'\ - 'provisionedIops,storageTierLevel,'\ - 'staasVersion,hasEncryptionAtRest' - origin_volume = self.get_file_volume_details(origin_volume_id, - mask=file_mask) - - order = storage_utils.prepare_duplicate_order_object( - self, origin_volume, duplicate_iops, duplicate_tier_level, - duplicate_size, duplicate_snapshot_size, 'file', - hourly_billing_flag - ) - - if origin_snapshot_id is not None: - order['duplicateOriginSnapshotId'] = origin_snapshot_id - - if dependent_duplicate: - order['isDependentDuplicateFlag'] = 1 - - return self.client.call('Product_Order', 'placeOrder', order) - - def order_modified_volume(self, volume_id, new_size=None, new_iops=None, new_tier_level=None): - """Places an order for modifying an existing file volume. - - :param volume_id: The ID of the volume to be modified - :param new_size: The new size/capacity for the volume - :param new_iops: The new IOPS for the volume - :param new_tier_level: The new tier level for the volume - :return: Returns a SoftLayer_Container_Product_Order_Receipt - """ - - mask_items = [ - 'id', - 'billingItem', - 'storageType[keyName]', - 'capacityGb', - 'provisionedIops', - 'storageTierLevel', - 'staasVersion', - 'hasEncryptionAtRest', - ] - file_mask = ','.join(mask_items) - volume = self.get_file_volume_details(volume_id, mask=file_mask) - - order = storage_utils.prepare_modify_order_object( - self, volume, new_iops, new_tier_level, new_size - ) - - return self.client.call('Product_Order', 'placeOrder', order) - - def delete_snapshot(self, snapshot_id): - """Deletes the specified snapshot object. - - :param snapshot_id: The ID of the snapshot object to delete. - """ - return self.client.call('Network_Storage', 'deleteObject', - id=snapshot_id) + return self.get_volume_snapshot_list(volume_id, **kwargs) def order_file_volume(self, storage_type, location, size, iops=None, tier_level=None, snapshot_size=None, @@ -358,132 +149,6 @@ def order_file_volume(self, storage_type, location, size, return self.client.call('Product_Order', 'placeOrder', order) - def create_snapshot(self, volume_id, notes='', **kwargs): - """Creates a snapshot on the given file volume. - - :param integer volume_id: The id of the volume - :param string notes: The notes or "name" to assign the snapshot - :return: Returns the id of the new snapshot - """ - - return self.client.call('Network_Storage', 'createSnapshot', - notes, id=volume_id, **kwargs) - - def enable_snapshots(self, volume_id, schedule_type, retention_count, minute, hour, day_of_week, **kwargs): - """Enables snapshots for a specific file volume at a given schedule - - :param integer volume_id: The id of the volume - :param string schedule_type: 'HOURLY'|'DAILY'|'WEEKLY' - :param integer retention_count: The number of snapshots to attempt to retain in this schedule - :param integer minute: The minute of the hour at which HOURLY, DAILY, and WEEKLY snapshots should be taken - :param integer hour: The hour of the day at which DAILY and WEEKLY snapshots should be taken - :param string|integer day_of_week: The day of the week on which WEEKLY snapshots should be taken, - either as a string ('SUNDAY') or integer ('0' is Sunday) - :return: Returns whether successfully scheduled or not - """ - - return self.client.call('Network_Storage', 'enableSnapshots', - schedule_type, - retention_count, - minute, - hour, - day_of_week, - id=volume_id, - **kwargs) - - def disable_snapshots(self, volume_id, schedule_type): - """Disables snapshots for a specific file volume at a given schedule - - :param integer volume_id: The id of the volume - :param string schedule_type: 'HOURLY'|'DAILY'|'WEEKLY' - :return: Returns whether successfully disabled or not - """ - - return self.client.call('Network_Storage', 'disableSnapshots', schedule_type, id=volume_id) - - def list_volume_schedules(self, volume_id): - """Lists schedules for a given volume - - :param integer volume_id: The id of the volume - :return: Returns list of schedules assigned to a given volume - """ - volume_detail = self.client.call( - 'Network_Storage', - 'getObject', - id=volume_id, - mask='schedules[type,properties[type]]') - - return utils.lookup(volume_detail, 'schedules') - - def order_snapshot_space(self, volume_id, capacity, tier, upgrade, **kwargs): - """Orders snapshot space for the given file volume. - - :param integer volume_id: The ID of the volume - :param integer capacity: The capacity to order, in GB - :param float tier: The tier level of the file volume, in IOPS per GB - :param boolean upgrade: Flag to indicate if this order is an upgrade - :return: Returns a SoftLayer_Container_Product_Order_Receipt - """ - file_mask = 'id,billingItem[location,hourlyFlag],'\ - 'storageType[keyName],storageTierLevel,provisionedIops,'\ - 'staasVersion,hasEncryptionAtRest' - file_volume = self.get_file_volume_details(volume_id, - mask=file_mask, - **kwargs) - - order = storage_utils.prepare_snapshot_order_object( - self, file_volume, capacity, tier, upgrade) - - return self.client.call('Product_Order', 'placeOrder', order) - - def cancel_snapshot_space(self, volume_id, reason='No longer needed', immediate=False): - """Cancels snapshot space for a given volume. - - :param integer volume_id: The volume ID - :param string reason: The reason for cancellation - :param boolean immediate: Cancel immediately or on anniversary date - """ - - file_volume = self.get_file_volume_details( - volume_id, - mask='mask[id,billingItem[activeChildren,hourlyFlag]]') - - if 'activeChildren' not in file_volume['billingItem']: - raise exceptions.SoftLayerError( - 'No snapshot space found to cancel') - - children_array = file_volume['billingItem']['activeChildren'] - billing_item_id = None - - for child in children_array: - if child['categoryCode'] == 'storage_snapshot_space': - billing_item_id = child['id'] - break - - if not billing_item_id: - raise exceptions.SoftLayerError( - 'No snapshot space found to cancel') - - if utils.lookup(file_volume, 'billingItem', 'hourlyFlag'): - immediate = True - - return self.client['Billing_Item'].cancelItem( - immediate, - True, - reason, - id=billing_item_id) - - def restore_from_snapshot(self, volume_id, snapshot_id): - """Restores a specific volume from a snapshot - - :param integer volume_id: The ID of the volume - :param integer snapshot_id: The id of the restore point - :return: Returns whether successfully restored or not - """ - - return self.client.call('Network_Storage', 'restoreFromSnapshot', - snapshot_id, id=volume_id) - def cancel_file_volume(self, volume_id, reason='No longer needed', immediate=False): """Cancels the given file storage volume. @@ -491,39 +156,11 @@ def cancel_file_volume(self, volume_id, reason='No longer needed', immediate=Fal :param string reason: The reason for cancellation :param boolean immediate: Cancel immediately or on anniversary date """ - file_volume = self.get_file_volume_details( - volume_id, - mask='mask[id,billingItem[id,hourlyFlag]]') - - if 'billingItem' not in file_volume: - raise exceptions.SoftLayerError('The volume has already been canceled') - billing_item_id = file_volume['billingItem']['id'] - - if utils.lookup(file_volume, 'billingItem', 'hourlyFlag'): - immediate = True - - return self.client['Billing_Item'].cancelItem( - immediate, - True, - reason, - id=billing_item_id) - - def failover_to_replicant(self, volume_id, replicant_id): - """Failover to a volume replicant. - - :param integer volume_id: The ID of the volume - :param integer replicant_id: ID of replicant to failover to - :return: Returns whether failover was successful or not - """ - - return self.client.call('Network_Storage', 'failoverToReplicant', - replicant_id, id=volume_id) - - def failback_from_replicant(self, volume_id): - """Failback from a volume replicant. - - :param integer volume_id: The ID of the volume - :return: Returns whether failback was successful or not - """ + return self.cancel_volume(volume_id, reason, immediate) - return self.client.call('Network_Storage', 'failbackFromReplicant', id=volume_id) + def _get_ids_from_username(self, username): + object_mask = "mask[id]" + results = self.list_file_volumes(username=username, mask=object_mask) + if results: + return [result['id'] for result in results] + return [] diff --git a/SoftLayer/managers/storage.py b/SoftLayer/managers/storage.py new file mode 100644 index 000000000..2d45bd0db --- /dev/null +++ b/SoftLayer/managers/storage.py @@ -0,0 +1,416 @@ +""" + SoftLayer.storage + ~~~~~~~~~~~~~~~ + Network Storage Manager + + :license: MIT, see LICENSE for more details. +""" +from SoftLayer import exceptions +from SoftLayer.managers import storage_utils +from SoftLayer import utils + +# pylint: disable=too-many-public-methods + + +class StorageManager(utils.IdentifierMixin, object): + """"Base class for File and Block storage managers + + Any shared code between File and Block should ideally go here. + + :param SoftLayer.API.BaseClient client: the client instance + """ + + def __init__(self, client): + self.configuration = {} + self.client = client + self.resolvers = [self._get_ids_from_username] + + def get_volume_count_limits(self): + """Returns a list of block volume count limit. + + :return: Returns a list of block volume count limit. + """ + return self.client.call('Network_Storage', 'getVolumeCountLimits') + + def get_volume_details(self, volume_id, **kwargs): + """Returns details about the specified volume. + + :param volume_id: ID of volume. + :param kwargs: + :return: Returns details about the specified volume. + """ + + if 'mask' not in kwargs: + items = [ + 'id', + 'username', + 'password', + 'capacityGb', + 'snapshotCapacityGb', + 'parentVolume.snapshotSizeBytes', + 'storageType.keyName', + 'serviceResource.datacenter[name]', + 'serviceResourceBackendIpAddress', + 'storageTierLevel', + 'provisionedIops', + 'lunId', + 'originalVolumeName', + 'originalSnapshotName', + 'originalVolumeSize', + 'activeTransactionCount', + 'activeTransactions.transactionStatus[friendlyName]', + 'replicationPartnerCount', + 'replicationStatus', + 'replicationPartners[id,username,' + 'serviceResourceBackendIpAddress,' + 'serviceResource[datacenter[name]],' + 'replicationSchedule[type[keyname]]]', + ] + kwargs['mask'] = ','.join(items) + return self.client.call('Network_Storage', 'getObject', id=volume_id, **kwargs) + + def get_volume_access_list(self, volume_id, **kwargs): + """Returns a list of authorized hosts for a specified volume. + + :param volume_id: ID of volume. + :param kwargs: + :return: Returns a list of authorized hosts for a specified volume. + """ + if 'mask' not in kwargs: + items = [ + 'id', + 'allowedVirtualGuests[allowedHost[credential, sourceSubnet]]', + 'allowedHardware[allowedHost[credential]]', + 'allowedSubnets[allowedHost[credential]]', + 'allowedIpAddresses[allowedHost[credential]]', + ] + kwargs['mask'] = ','.join(items) + return self.client.call('Network_Storage', 'getObject', id=volume_id, **kwargs) + + def get_volume_snapshot_list(self, volume_id, **kwargs): + """Returns a list of snapshots for the specified volume. + + :param volume_id: ID of volume. + :param kwargs: + :return: Returns a list of snapshots for the specified volume. + """ + if 'mask' not in kwargs: + items = [ + 'id', + 'notes', + 'snapshotSizeBytes', + 'storageType[keyName]', + 'snapshotCreationTimestamp', + 'intervalSchedule', + 'hourlySchedule', + 'dailySchedule', + 'weeklySchedule' + ] + + kwargs['mask'] = ','.join(items) + + return self.client.call('Network_Storage', 'getSnapshots', id=volume_id, **kwargs) + + def authorize_host_to_volume(self, volume_id, hardware_ids=None, virtual_guest_ids=None, + ip_address_ids=None, subnet_ids=None): + """Authorizes hosts to Storage Volumes + + :param volume_id: The File volume to authorize hosts to + :param hardware_ids: A List of SoftLayer_Hardware ids + :param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids + :param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids + :param subnet_ids: A List of SoftLayer_Network_Subnet ids. Only use with File volumes. + :return: Returns an array of SoftLayer_Network_Storage_Allowed_Host objects + which now have access to the given volume + """ + host_templates = storage_utils.populate_host_templates(hardware_ids, virtual_guest_ids, + ip_address_ids, subnet_ids) + + return self.client.call('Network_Storage', 'allowAccessFromHostList', host_templates, id=volume_id) + + def deauthorize_host_to_volume(self, volume_id, hardware_ids=None, virtual_guest_ids=None, + ip_address_ids=None, subnet_ids=None): + """Revokes authorization of hosts to File Storage Volumes + + :param volume_id: The File volume to deauthorize hosts to + :param hardware_ids: A List of SoftLayer_Hardware ids + :param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids + :param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids + :param subnet_ids: A List of SoftLayer_Network_Subnet ids. Only use with File volumes + :return: Returns an array of SoftLayer_Network_Storage_Allowed_Host objects + which have access to the given File volume + """ + host_templates = storage_utils.populate_host_templates(hardware_ids, virtual_guest_ids, + ip_address_ids, subnet_ids) + + return self.client.call('Network_Storage', 'removeAccessFromHostList', host_templates, id=volume_id) + + def get_replication_partners(self, volume_id): + """Acquires list of replicant volumes pertaining to the given volume. + + :param volume_id: The ID of the primary volume to be replicated + :return: Returns an array of SoftLayer_Location objects + """ + return self.client.call('Network_Storage', 'getReplicationPartners', id=volume_id) + + def get_replication_locations(self, volume_id): + """Acquires list of the datacenters to which a volume can be replicated. + + :param volume_id: The ID of the primary volume to be replicated + :return: Returns an array of SoftLayer_Network_Storage objects + """ + return self.client.call('Network_Storage', 'getValidReplicationTargetDatacenterLocations', id=volume_id) + + def order_replicant_volume(self, volume_id, snapshot_schedule, location, tier=None, os_type=None): + """Places an order for a replicant volume. + + :param volume_id: The ID of the primary volume to be replicated + :param snapshot_schedule: The primary volume's snapshot + schedule to use for replication + :param location: The location for the ordered replicant volume + :param tier: The tier (IOPS per GB) of the primary volume + :param os_type: The OS type of the primary volume + :return: Returns a SoftLayer_Container_Product_Order_Receipt + """ + + block_mask = 'billingItem[activeChildren,hourlyFlag],'\ + 'storageTierLevel,osType,staasVersion,'\ + 'hasEncryptionAtRest,snapshotCapacityGb,schedules,'\ + 'intervalSchedule,hourlySchedule,dailySchedule,'\ + 'weeklySchedule,storageType[keyName],provisionedIops' + block_volume = self.get_volume_details(volume_id, mask=block_mask) + + storage_class = storage_utils.block_or_file(block_volume['storageType']['keyName']) + + order = storage_utils.prepare_replicant_order_object( + self, snapshot_schedule, location, tier, block_volume, storage_class + ) + + if storage_class == 'block': + if os_type is None: + if isinstance(utils.lookup(block_volume, 'osType', 'keyName'), str): + os_type = block_volume['osType']['keyName'] + else: + raise exceptions.SoftLayerError( + "Cannot find primary volume's os-type " + "automatically; must specify manually") + order['osFormatType'] = {'keyName': os_type} + + return self.client.call('Product_Order', 'placeOrder', order) + + def order_duplicate_volume(self, origin_volume_id, origin_snapshot_id=None, duplicate_size=None, + duplicate_iops=None, duplicate_tier_level=None, duplicate_snapshot_size=None, + hourly_billing_flag=False, dependent_duplicate=False): + """Places an order for a duplicate volume. + + :param origin_volume_id: The ID of the origin volume to be duplicated + :param origin_snapshot_id: Origin snapshot ID to use for duplication + :param duplicate_size: Size/capacity for the duplicate volume + :param duplicate_iops: The IOPS per GB for the duplicate volume + :param duplicate_tier_level: Tier level for the duplicate volume + :param duplicate_snapshot_size: Snapshot space size for the duplicate + :param hourly_billing_flag: Billing type, monthly (False) or hourly (True), default to monthly. + :return: Returns a SoftLayer_Container_Product_Order_Receipt + """ + + block_mask = 'id,billingItem[location,hourlyFlag],snapshotCapacityGb,'\ + 'storageType[keyName],capacityGb,originalVolumeSize,'\ + 'provisionedIops,storageTierLevel,osType[keyName],'\ + 'staasVersion,hasEncryptionAtRest' + origin_volume = self.get_volume_details(origin_volume_id, mask=block_mask) + storage_class = storage_utils.block_or_file(origin_volume['storageType']['keyName']) + + order = storage_utils.prepare_duplicate_order_object( + self, origin_volume, duplicate_iops, duplicate_tier_level, + duplicate_size, duplicate_snapshot_size, storage_class, hourly_billing_flag + ) + + if storage_class == 'block': + if isinstance(utils.lookup(origin_volume, 'osType', 'keyName'), str): + os_type = origin_volume['osType']['keyName'] + else: + raise exceptions.SoftLayerError("Cannot find origin volume's os-type") + + order['osFormatType'] = {'keyName': os_type} + + if origin_snapshot_id is not None: + order['duplicateOriginSnapshotId'] = origin_snapshot_id + if dependent_duplicate: + # if isDependentDuplicateFlag is set to ANYTHING, it is considered dependent. + order['isDependentDuplicateFlag'] = 1 + + return self.client.call('Product_Order', 'placeOrder', order) + + def order_modified_volume(self, volume_id, new_size=None, new_iops=None, new_tier_level=None): + """Places an order for modifying an existing block volume. + + :param volume_id: The ID of the volume to be modified + :param new_size: The new size/capacity for the volume + :param new_iops: The new IOPS for the volume + :param new_tier_level: The new tier level for the volume + :return: Returns a SoftLayer_Container_Product_Order_Receipt + """ + + mask_items = [ + 'id', + 'billingItem', + 'storageType[keyName]', + 'capacityGb', + 'provisionedIops', + 'storageTierLevel', + 'staasVersion', + 'hasEncryptionAtRest', + ] + block_mask = ','.join(mask_items) + volume = self.get_volume_details(volume_id, mask=block_mask) + + order = storage_utils.prepare_modify_order_object( + self, volume, new_iops, new_tier_level, new_size + ) + + return self.client.call('Product_Order', 'placeOrder', order) + + def delete_snapshot(self, snapshot_id): + """Deletes the specified snapshot object. + + :param snapshot_id: The ID of the snapshot object to delete. + """ + return self.client.call('Network_Storage', 'deleteObject', id=snapshot_id) + + def create_snapshot(self, volume_id, notes='', **kwargs): + """Creates a snapshot on the given block volume. + + :param integer volume_id: The id of the volume + :param string notes: The notes or "name" to assign the snapshot + :return: Returns the id of the new snapshot + """ + return self.client.call('Network_Storage', 'createSnapshot', notes, id=volume_id, **kwargs) + + def order_snapshot_space(self, volume_id, capacity, tier, upgrade, **kwargs): + """Orders snapshot space for the given block volume. + + :param integer volume_id: The id of the volume + :param integer capacity: The capacity to order, in GB + :param float tier: The tier level of the block volume, in IOPS per GB + :param boolean upgrade: Flag to indicate if this order is an upgrade + :return: Returns a SoftLayer_Container_Product_Order_Receipt + """ + object_mask = 'id,billingItem[location,hourlyFlag],'\ + 'storageType[keyName],storageTierLevel,provisionedIops,'\ + 'staasVersion,hasEncryptionAtRest' + volume = self.get_volume_details(volume_id, mask=object_mask, **kwargs) + + order = storage_utils.prepare_snapshot_order_object(self, volume, capacity, tier, upgrade) + + return self.client.call('Product_Order', 'placeOrder', order) + + def cancel_snapshot_space(self, volume_id, reason='No longer needed', immediate=False): + """Cancels snapshot space for a given volume. + + :param integer volume_id: The volume ID + :param string reason: The reason for cancellation + :param boolean immediate_flag: Cancel immediately or on anniversary date + """ + + object_mask = 'mask[id,billingItem[activeChildren,hourlyFlag]]' + volume = self.get_volume_details(volume_id, mask=object_mask) + + if 'activeChildren' not in volume['billingItem']: + raise exceptions.SoftLayerError('No snapshot space found to cancel') + + children_array = volume['billingItem']['activeChildren'] + billing_item_id = None + + for child in children_array: + if child['categoryCode'] == 'storage_snapshot_space': + billing_item_id = child['id'] + break + + if not billing_item_id: + raise exceptions.SoftLayerError('No snapshot space found to cancel') + + if utils.lookup(volume, 'billingItem', 'hourlyFlag'): + immediate = True + + return self.client.call('SoftLayer_Billing_Item', 'cancelItem', immediate, True, reason, id=billing_item_id) + + def enable_snapshots(self, volume_id, schedule_type, retention_count, minute, hour, day_of_week, **kwargs): + """Enables snapshots for a specific block volume at a given schedule + + :param integer volume_id: The id of the volume + :param string schedule_type: 'HOURLY'|'DAILY'|'WEEKLY' + :param integer retention_count: Number of snapshots to be kept + :param integer minute: Minute when to take snapshot + :param integer hour: Hour when to take snapshot + :param string day_of_week: Day when to take snapshot + :return: Returns whether successfully scheduled or not + """ + return self.client.call('Network_Storage', 'enableSnapshots', schedule_type, retention_count, + minute, hour, day_of_week, id=volume_id, **kwargs) + + def disable_snapshots(self, volume_id, schedule_type): + """Disables snapshots for a specific block volume at a given schedule + + :param integer volume_id: The id of the volume + :param string schedule_type: 'HOURLY'|'DAILY'|'WEEKLY' + :return: Returns whether successfully disabled or not + """ + return self.client.call('Network_Storage', 'disableSnapshots', schedule_type, id=volume_id) + + def list_volume_schedules(self, volume_id): + """Lists schedules for a given volume + + :param integer volume_id: The id of the volume + :return: Returns list of schedules assigned to a given volume + """ + object_mask = 'schedules[type,properties[type]]' + volume_detail = self.client.call('Network_Storage', 'getObject', id=volume_id, mask=object_mask) + + return utils.lookup(volume_detail, 'schedules') + + def restore_from_snapshot(self, volume_id, snapshot_id): + """Restores a specific volume from a snapshot + + :param integer volume_id: The id of the volume + :param integer snapshot_id: The id of the restore point + :return: Returns whether succesfully restored or not + """ + return self.client.call('Network_Storage', 'restoreFromSnapshot', snapshot_id, id=volume_id) + + def failover_to_replicant(self, volume_id, replicant_id): + """Failover to a volume replicant. + + :param integer volume_id: The id of the volume + :param integer replicant_id: ID of replicant to failover to + :return: Returns whether failover was successful or not + """ + return self.client.call('Network_Storage', 'failoverToReplicant', replicant_id, id=volume_id) + + def failback_from_replicant(self, volume_id): + """Failback from a volume replicant. + + :param integer volume_id: The id of the volume + :return: Returns whether failback was successful or not + """ + + return self.client.call('Network_Storage', 'failbackFromReplicant', id=volume_id) + + def cancel_volume(self, volume_id, reason='No longer needed', immediate=False): + """Cancels the given block storage volume. + + :param integer volume_id: The volume ID + :param string reason: The reason for cancellation + :param boolean immediate_flag: Cancel immediately or on anniversary date + """ + object_mask = 'mask[id,billingItem[id,hourlyFlag]]' + volume = self.get_volume_details(volume_id, mask=object_mask) + + if 'billingItem' not in volume: + raise exceptions.SoftLayerError("Block Storage was already cancelled") + + billing_item_id = volume['billingItem']['id'] + + if utils.lookup(volume, 'billingItem', 'hourlyFlag'): + immediate = True + + return self.client.call('SoftLayer_Billing_Item', 'cancelItem', immediate, True, reason, id=billing_item_id) diff --git a/SoftLayer/managers/storage_utils.py b/SoftLayer/managers/storage_utils.py index b49e0eb45..0d82d5e25 100644 --- a/SoftLayer/managers/storage_utils.py +++ b/SoftLayer/managers/storage_utils.py @@ -19,19 +19,19 @@ } -def populate_host_templates(host_templates, - hardware_ids=None, +def populate_host_templates(hardware_ids=None, virtual_guest_ids=None, ip_address_ids=None, subnet_ids=None): - """Populate the given host_templates array with the IDs provided + """Returns a populated array with the IDs provided - :param host_templates: The array to which host templates will be added :param hardware_ids: A List of SoftLayer_Hardware ids :param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids :param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids :param subnet_ids: A List of SoftLayer_Network_Subnet ids + :return: array of objects formatted for allowAccessFromHostList """ + host_templates = [] if hardware_ids is not None: for hardware_id in hardware_ids: host_templates.append({ @@ -59,6 +59,7 @@ def populate_host_templates(host_templates, 'objectType': 'SoftLayer_Network_Subnet', 'id': subnet_id }) + return host_templates def get_package(manager, category_code): @@ -991,6 +992,15 @@ def prepare_modify_order_object(manager, volume, new_iops, new_tier, new_size): return modify_order +def block_or_file(storage_type_keyname): + """returns either 'block' or 'file' + + :param storage_type_keyname: the Network_Storage['storageType']['keyName'] + :returns: 'block' or 'file' + """ + return 'block' if 'BLOCK_STORAGE' in storage_type_keyname else 'file' + + def _has_category(categories, category_code): return any( True diff --git a/tests/CLI/modules/block_tests.py b/tests/CLI/modules/block_tests.py index e59288981..0dd7eac57 100644 --- a/tests/CLI/modules/block_tests.py +++ b/tests/CLI/modules/block_tests.py @@ -60,6 +60,7 @@ def test_volume_detail(self): self.assert_no_fail(result) isinstance(json.loads(result.output)['IOPs'], float) + self.assert_called_with('SoftLayer_Network_Storage', 'getObject', identifier=1234) self.assertEqual({ 'Username': 'username', 'LUN Id': '2', @@ -98,6 +99,26 @@ def test_volume_detail(self): ] }, json.loads(result.output)) + def test_volume_detail_name_identifier(self): + result = self.run_command(['block', 'volume-detail', 'SL-12345']) + expected_filter = { + 'iscsiNetworkStorage': { + 'serviceResource': { + 'type': { + 'type': {'operation': '!~ ISCSI'} + } + }, + 'storageType': { + 'keyName': {'operation': '*= BLOCK_STORAGE'} + }, + 'username': {'operation': '_= SL-12345'} + } + } + + self.assert_called_with('SoftLayer_Account', 'getIscsiNetworkStorage', filter=expected_filter) + self.assert_called_with('SoftLayer_Network_Storage', 'getObject', identifier=100) + self.assert_no_fail(result) + def test_volume_list(self): result = self.run_command(['block', 'volume-list']) diff --git a/tests/CLI/modules/file_tests.py b/tests/CLI/modules/file_tests.py index e1d8628cb..20e065940 100644 --- a/tests/CLI/modules/file_tests.py +++ b/tests/CLI/modules/file_tests.py @@ -163,6 +163,24 @@ def test_volume_detail(self): ] }, json.loads(result.output)) + def test_volume_detail_name_identifier(self): + result = self.run_command(['file', 'volume-detail', 'SL-12345']) + expected_filter = { + 'nasNetworkStorage': { + 'serviceResource': { + 'type': { + 'type': {'operation': '!~ NAS'} + } + }, + 'storageType': { + 'keyName': {'operation': '*= FILE_STORAGE'} + }, + 'username': {'operation': '_= SL-12345'}}} + + self.assert_called_with('SoftLayer_Account', 'getNasNetworkStorage', filter=expected_filter) + self.assert_called_with('SoftLayer_Network_Storage', 'getObject', identifier=1) + self.assert_no_fail(result) + def test_volume_order_performance_iops_not_given(self): result = self.run_command(['file', 'volume-order', '--storage-type=performance', '--size=20', diff --git a/tests/managers/block_tests.py b/tests/managers/block_tests.py index e78622105..7febbfcf3 100644 --- a/tests/managers/block_tests.py +++ b/tests/managers/block_tests.py @@ -8,7 +8,11 @@ import copy import SoftLayer from SoftLayer import exceptions -from SoftLayer import fixtures +from SoftLayer.fixtures import SoftLayer_Account +from SoftLayer.fixtures import SoftLayer_Network_Storage +from SoftLayer.fixtures import SoftLayer_Network_Storage_Allowed_Host +from SoftLayer.fixtures import SoftLayer_Product_Order +from SoftLayer.fixtures import SoftLayer_Product_Package from SoftLayer import testing @@ -83,7 +87,7 @@ def test_cancel_block_volume_billing_item_found(self): def test_get_block_volume_details(self): result = self.block.get_block_volume_details(100) - self.assertEqual(fixtures.SoftLayer_Network_Storage.getObject, result) + self.assertEqual(SoftLayer_Network_Storage.getObject, result) expected_mask = 'id,' \ 'username,' \ @@ -119,7 +123,7 @@ def test_get_block_volume_details(self): def test_list_block_volumes(self): result = self.block.list_block_volumes() - self.assertEqual(fixtures.SoftLayer_Account.getIscsiNetworkStorage, + self.assertEqual(SoftLayer_Account.getIscsiNetworkStorage, result) expected_filter = { @@ -157,7 +161,7 @@ def test_list_block_volumes_with_additional_filters(self): storage_type="Endurance", username="username") - self.assertEqual(fixtures.SoftLayer_Account.getIscsiNetworkStorage, + self.assertEqual(SoftLayer_Account.getIscsiNetworkStorage, result) expected_filter = { @@ -197,7 +201,7 @@ def test_list_block_volumes_with_additional_filters(self): def test_get_block_volume_access_list(self): result = self.block.get_block_volume_access_list(100) - self.assertEqual(fixtures.SoftLayer_Network_Storage.getObject, result) + self.assertEqual(SoftLayer_Network_Storage.getObject, result) self.assert_called_with( 'SoftLayer_Network_Storage', @@ -207,7 +211,7 @@ def test_get_block_volume_access_list(self): def test_get_block_volume_snapshot_list(self): result = self.block.get_block_volume_snapshot_list(100) - self.assertEqual(fixtures.SoftLayer_Network_Storage.getSnapshots, + self.assertEqual(SoftLayer_Network_Storage.getSnapshots, result) self.assert_called_with( @@ -218,7 +222,7 @@ def test_get_block_volume_snapshot_list(self): def test_delete_snapshot(self): result = self.block.delete_snapshot(100) - self.assertEqual(fixtures.SoftLayer_Network_Storage.deleteObject, + self.assertEqual(SoftLayer_Network_Storage.deleteObject, result) self.assert_called_with( @@ -331,7 +335,7 @@ def test_replicant_failover(self): result = self.block.failover_to_replicant(1234, 5678) self.assertEqual( - fixtures.SoftLayer_Network_Storage.failoverToReplicant, result) + SoftLayer_Network_Storage.failoverToReplicant, result) self.assert_called_with( 'SoftLayer_Network_Storage', 'failoverToReplicant', @@ -343,7 +347,7 @@ def test_replicant_failback(self): result = self.block.failback_from_replicant(1234) self.assertEqual( - fixtures.SoftLayer_Network_Storage.failbackFromReplicant, result) + SoftLayer_Network_Storage.failbackFromReplicant, result) self.assert_called_with( 'SoftLayer_Network_Storage', 'failbackFromReplicant', @@ -373,9 +377,9 @@ def test_order_block_volume_performance(self): mock.return_value = [{'id': 449494, 'name': 'dal09'}] mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_BLOCK_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -389,7 +393,7 @@ def test_order_block_volume_performance(self): service_offering='storage_as_a_service' ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -418,9 +422,9 @@ def test_order_block_volume_endurance(self): mock.return_value = [{'id': 449494, 'name': 'dal09'}] mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME + mock_volume = SoftLayer_Network_Storage.STAAS_TEST_VOLUME mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -433,7 +437,7 @@ def test_order_block_volume_endurance(self): service_offering='storage_as_a_service' ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -463,7 +467,7 @@ def test_authorize_host_to_volume(self): virtual_guest_ids=[200], ip_address_ids=[300]) - self.assertEqual(fixtures.SoftLayer_Network_Storage. + self.assertEqual(SoftLayer_Network_Storage. allowAccessFromHostList, result) self.assert_called_with( @@ -478,7 +482,7 @@ def test_deauthorize_host_to_volume(self): virtual_guest_ids=[200], ip_address_ids=[300]) - self.assertEqual(fixtures.SoftLayer_Network_Storage. + self.assertEqual(SoftLayer_Network_Storage. removeAccessFromHostList, result) self.assert_called_with( @@ -491,7 +495,7 @@ def test_assign_subnets_to_acl(self): 12345, subnet_ids=[12345678]) - self.assertEqual(fixtures.SoftLayer_Network_Storage_Allowed_Host. + self.assertEqual(SoftLayer_Network_Storage_Allowed_Host. assignSubnetsToAcl, result) self.assert_called_with( @@ -504,7 +508,7 @@ def test_remove_subnets_from_acl(self): 12345, subnet_ids=[12345678]) - self.assertEqual(fixtures.SoftLayer_Network_Storage_Allowed_Host. + self.assertEqual(SoftLayer_Network_Storage_Allowed_Host. removeSubnetsFromAcl, result) self.assert_called_with( @@ -515,7 +519,7 @@ def test_remove_subnets_from_acl(self): def test_get_subnets_in_acl(self): result = self.block.get_subnets_in_acl(12345) - self.assertEqual(fixtures.SoftLayer_Network_Storage_Allowed_Host. + self.assertEqual(SoftLayer_Network_Storage_Allowed_Host. getSubnetsInAcl, result) self.assert_called_with( @@ -526,7 +530,7 @@ def test_get_subnets_in_acl(self): def test_create_snapshot(self): result = self.block.create_snapshot(123, 'hello world') - self.assertEqual(fixtures.SoftLayer_Network_Storage.createSnapshot, + self.assertEqual(SoftLayer_Network_Storage.createSnapshot, result) self.assert_called_with( @@ -538,7 +542,7 @@ def test_snapshot_restore(self): result = self.block.restore_from_snapshot(12345678, 87654321) self.assertEqual( - fixtures.SoftLayer_Network_Storage.restoreFromSnapshot, + SoftLayer_Network_Storage.restoreFromSnapshot, result) self.assert_called_with( 'SoftLayer_Network_Storage', @@ -549,7 +553,7 @@ def test_enable_snapshots(self): result = self.block.enable_snapshots(12345678, 'WEEKLY', 10, 47, 16, 'FRIDAY') - self.assertEqual(fixtures.SoftLayer_Network_Storage.enableSnapshots, + self.assertEqual(SoftLayer_Network_Storage.enableSnapshots, result) self.assert_called_with( @@ -560,7 +564,7 @@ def test_enable_snapshots(self): def test_disable_snapshots(self): result = self.block.disable_snapshots(12345678, 'HOURLY') - self.assertEqual(fixtures.SoftLayer_Network_Storage.disableSnapshots, + self.assertEqual(SoftLayer_Network_Storage.disableSnapshots, result) self.assert_called_with( 'SoftLayer_Network_Storage', @@ -571,7 +575,7 @@ def test_list_volume_schedules(self): result = self.block.list_volume_schedules(12345678) self.assertEqual( - fixtures.SoftLayer_Network_Storage.listVolumeSchedules, + SoftLayer_Network_Storage.listVolumeSchedules, result) expected_mask = 'schedules[type,properties[type]]' @@ -585,16 +589,16 @@ def test_list_volume_schedules(self): def test_order_block_snapshot_space_upgrade(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'ENDURANCE_BLOCK_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.block.order_snapshot_space(102, 20, None, True) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -615,15 +619,15 @@ def test_order_block_snapshot_space_upgrade(self): def test_order_block_snapshot_space(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME + mock_volume = SoftLayer_Network_Storage.STAAS_TEST_VOLUME mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.block.order_snapshot_space(102, 10, None, False) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -643,7 +647,10 @@ def test_order_block_snapshot_space(self): ) def test_order_block_replicant_os_type_not_found(self): - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_package = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') + mock_package.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] + + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) del mock_volume['osType'] mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -665,9 +672,9 @@ def test_order_block_replicant_performance_os_type_given(self): mock.return_value = [{'id': 449494, 'name': 'dal09'}] mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_BLOCK_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -679,7 +686,7 @@ def test_order_block_replicant_performance_os_type_given(self): os_type='XEN' ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -712,15 +719,15 @@ def test_order_block_replicant_endurance(self): mock.return_value = [{'id': 449494, 'name': 'dal09'}] mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME + mock_volume = SoftLayer_Network_Storage.STAAS_TEST_VOLUME mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.block.order_replicant_volume(102, 'WEEKLY', 'dal09') - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -749,9 +756,9 @@ def test_order_block_replicant_endurance(self): def test_order_block_duplicate_origin_os_type_not_found(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) del mock_volume['osType'] mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -767,9 +774,9 @@ def test_order_block_duplicate_origin_os_type_not_found(self): def test_order_block_duplicate_performance_no_duplicate_snapshot(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_BLOCK_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -778,7 +785,7 @@ def test_order_block_duplicate_performance_no_duplicate_snapshot(self): 102, duplicate_snapshot_size=0) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -804,9 +811,9 @@ def test_order_block_duplicate_performance_no_duplicate_snapshot(self): def test_order_block_duplicate_performance(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_BLOCK_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -820,7 +827,7 @@ def test_order_block_duplicate_performance(self): duplicate_snapshot_size=10 ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -848,9 +855,9 @@ def test_order_block_duplicate_performance(self): def test_order_block_duplicate_depdupe(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_BLOCK_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -865,7 +872,7 @@ def test_order_block_duplicate_depdupe(self): dependent_duplicate=True ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -894,9 +901,9 @@ def test_order_block_duplicate_depdupe(self): def test_order_block_duplicate_endurance_no_duplicate_snapshot(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME + mock_volume = SoftLayer_Network_Storage.STAAS_TEST_VOLUME mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -904,7 +911,7 @@ def test_order_block_duplicate_endurance_no_duplicate_snapshot(self): 102, duplicate_snapshot_size=0) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -929,9 +936,9 @@ def test_order_block_duplicate_endurance_no_duplicate_snapshot(self): def test_order_block_duplicate_endurance(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME + mock_volume = SoftLayer_Network_Storage.STAAS_TEST_VOLUME mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -944,7 +951,7 @@ def test_order_block_duplicate_endurance(self): duplicate_snapshot_size=10 ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -971,16 +978,16 @@ def test_order_block_duplicate_endurance(self): def test_order_block_modified_performance(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_BLOCK_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.block.order_modified_volume(102, new_size=1000, new_iops=2000, new_tier_level=None) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', 'placeOrder', @@ -994,15 +1001,15 @@ def test_order_block_modified_performance(self): def test_order_block_modified_endurance(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME + mock_volume = SoftLayer_Network_Storage.STAAS_TEST_VOLUME mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.block.order_modified_volume(102, new_size=1000, new_iops=None, new_tier_level=4) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', 'placeOrder', @@ -1022,4 +1029,16 @@ def test_setCredentialPassword(self): def test_list_block_volume_limit(self): result = self.block.list_block_volume_limit() - self.assertEqual(fixtures.SoftLayer_Network_Storage.getVolumeCountLimits, result) + self.assertEqual(SoftLayer_Network_Storage.getVolumeCountLimits, result) + + def test_get_ids_from_username(self): + result = self.block._get_ids_from_username("test") + self.assert_called_with('SoftLayer_Account', 'getIscsiNetworkStorage') + self.assertEqual([100], result) + + def test_get_ids_from_username_empty(self): + mock = self.set_mock('SoftLayer_Account', 'getIscsiNetworkStorage') + mock.return_value = [] + result = self.block._get_ids_from_username("test") + self.assert_called_with('SoftLayer_Account', 'getIscsiNetworkStorage') + self.assertEqual([], result) diff --git a/tests/managers/file_tests.py b/tests/managers/file_tests.py index 69c9c60ed..dbd181228 100644 --- a/tests/managers/file_tests.py +++ b/tests/managers/file_tests.py @@ -8,7 +8,10 @@ import copy import SoftLayer from SoftLayer import exceptions -from SoftLayer import fixtures +from SoftLayer.fixtures import SoftLayer_Account +from SoftLayer.fixtures import SoftLayer_Network_Storage +from SoftLayer.fixtures import SoftLayer_Product_Order +from SoftLayer.fixtures import SoftLayer_Product_Package from SoftLayer import testing @@ -49,7 +52,7 @@ def test_authorize_host_to_volume(self): ip_address_ids=[300], subnet_ids=[400]) - self.assertEqual(fixtures.SoftLayer_Network_Storage. + self.assertEqual(SoftLayer_Network_Storage. allowAccessFromHostList, result) self.assert_called_with( @@ -65,7 +68,7 @@ def test_deauthorize_host_to_volume(self): ip_address_ids=[300], subnet_ids=[400]) - self.assertEqual(fixtures.SoftLayer_Network_Storage. + self.assertEqual(SoftLayer_Network_Storage. removeAccessFromHostList, result) self.assert_called_with( @@ -84,7 +87,7 @@ def test_enable_snapshots(self): result = self.file.enable_snapshots(12345678, 'WEEKLY', 10, 47, 16, 'FRIDAY') - self.assertEqual(fixtures.SoftLayer_Network_Storage.enableSnapshots, + self.assertEqual(SoftLayer_Network_Storage.enableSnapshots, result) self.assert_called_with( @@ -95,7 +98,7 @@ def test_enable_snapshots(self): def test_disable_snapshots(self): result = self.file.disable_snapshots(12345678, 'HOURLY') - self.assertEqual(fixtures.SoftLayer_Network_Storage.disableSnapshots, + self.assertEqual(SoftLayer_Network_Storage.disableSnapshots, result) self.assert_called_with( 'SoftLayer_Network_Storage', @@ -106,7 +109,7 @@ def test_snapshot_restore(self): result = self.file.restore_from_snapshot(12345678, 87654321) self.assertEqual( - fixtures.SoftLayer_Network_Storage.restoreFromSnapshot, + SoftLayer_Network_Storage.restoreFromSnapshot, result) self.assert_called_with( 'SoftLayer_Network_Storage', @@ -116,7 +119,7 @@ def test_snapshot_restore(self): def test_get_file_volume_details(self): result = self.file.get_file_volume_details(100) - self.assertEqual(fixtures.SoftLayer_Network_Storage.getObject, result) + self.assertEqual(SoftLayer_Network_Storage.getObject, result) expected_mask = 'id,'\ 'username,'\ @@ -153,7 +156,7 @@ def test_get_file_volume_details(self): def test_get_file_volume_snapshot_list(self): result = self.file.get_file_volume_snapshot_list(100) - self.assertEqual(fixtures.SoftLayer_Network_Storage.getSnapshots, + self.assertEqual(SoftLayer_Network_Storage.getSnapshots, result) self.assert_called_with( @@ -164,7 +167,7 @@ def test_get_file_volume_snapshot_list(self): def test_create_snapshot(self): result = self.file.create_snapshot(123, 'hello world') - self.assertEqual(fixtures.SoftLayer_Network_Storage.createSnapshot, + self.assertEqual(SoftLayer_Network_Storage.createSnapshot, result) self.assert_called_with( @@ -277,7 +280,7 @@ def test_replicant_failover(self): result = self.file.failover_to_replicant(1234, 5678) self.assertEqual( - fixtures.SoftLayer_Network_Storage.failoverToReplicant, result) + SoftLayer_Network_Storage.failoverToReplicant, result) self.assert_called_with( 'SoftLayer_Network_Storage', 'failoverToReplicant', @@ -289,7 +292,7 @@ def test_replicant_failback(self): result = self.file.failback_from_replicant(1234) self.assertEqual( - fixtures.SoftLayer_Network_Storage.failbackFromReplicant, result) + SoftLayer_Network_Storage.failbackFromReplicant, result) self.assert_called_with( 'SoftLayer_Network_Storage', 'failbackFromReplicant', @@ -317,7 +320,7 @@ def test_get_replication_locations(self): def test_delete_snapshot(self): result = self.file.delete_snapshot(100) - self.assertEqual(fixtures.SoftLayer_Network_Storage.deleteObject, + self.assertEqual(SoftLayer_Network_Storage.deleteObject, result) self.assert_called_with( @@ -328,7 +331,7 @@ def test_delete_snapshot(self): def test_list_file_volumes(self): result = self.file.list_file_volumes() - self.assertEqual(fixtures.SoftLayer_Account.getNasNetworkStorage, + self.assertEqual(SoftLayer_Account.getNasNetworkStorage, result) expected_filter = { @@ -366,7 +369,7 @@ def test_list_file_volumes_with_additional_filters(self): storage_type="Endurance", username="username") - self.assertEqual(fixtures.SoftLayer_Account.getNasNetworkStorage, + self.assertEqual(SoftLayer_Account.getNasNetworkStorage, result) expected_filter = { @@ -408,9 +411,9 @@ def test_order_file_volume_performance(self): mock.return_value = [{'id': 449494, 'name': 'dal09'}] mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -423,7 +426,7 @@ def test_order_file_volume_performance(self): service_offering='storage_as_a_service' ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -451,9 +454,9 @@ def test_order_file_volume_endurance(self): mock.return_value = [{'id': 449494, 'name': 'dal09'}] mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'ENDURANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -466,7 +469,7 @@ def test_order_file_volume_endurance(self): service_offering='storage_as_a_service' ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -490,16 +493,16 @@ def test_order_file_volume_endurance(self): def test_order_file_snapshot_space_upgrade(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'ENDURANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.file.order_snapshot_space(102, 20, None, True) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -520,16 +523,16 @@ def test_order_file_snapshot_space_upgrade(self): def test_order_file_snapshot_space(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'ENDURANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.file.order_snapshot_space(102, 10, None, False) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -553,16 +556,16 @@ def test_order_file_replicant_performance(self): mock.return_value = [{'id': 449494, 'name': 'dal09'}] mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.file.order_replicant_volume(102, 'WEEKLY', 'dal09') - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -594,16 +597,16 @@ def test_order_file_replicant_endurance(self): mock.return_value = [{'id': 449494, 'name': 'dal09'}] mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'ENDURANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.file.order_replicant_volume(102, 'WEEKLY', 'dal09') - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -631,9 +634,9 @@ def test_order_file_replicant_endurance(self): def test_order_file_duplicate_performance_no_duplicate_snapshot(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -642,7 +645,7 @@ def test_order_file_duplicate_performance_no_duplicate_snapshot(self): 102, duplicate_snapshot_size=0) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -667,8 +670,8 @@ def test_order_file_duplicate_performance_no_duplicate_snapshot(self): def test_order_file_duplicate_performance(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -682,7 +685,7 @@ def test_order_file_duplicate_performance(self): duplicate_snapshot_size=10 ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -709,9 +712,9 @@ def test_order_file_duplicate_performance(self): def test_order_file_duplicate_endurance_no_duplicate_snapshot(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'ENDURANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -720,7 +723,7 @@ def test_order_file_duplicate_endurance_no_duplicate_snapshot(self): 102, duplicate_snapshot_size=0) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -744,9 +747,9 @@ def test_order_file_duplicate_endurance_no_duplicate_snapshot(self): def test_order_file_duplicate_depdupe(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'ENDURANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -761,7 +764,7 @@ def test_order_file_duplicate_depdupe(self): dependent_duplicate=True ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -788,9 +791,9 @@ def test_order_file_duplicate_depdupe(self): def test_order_file_duplicate_endurance(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'ENDURANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume @@ -804,7 +807,7 @@ def test_order_file_duplicate_endurance(self): duplicate_snapshot_size=10 ) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', @@ -830,16 +833,16 @@ def test_order_file_duplicate_endurance(self): def test_order_file_modified_performance(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'PERFORMANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.file.order_modified_volume(102, new_size=1000, new_iops=2000, new_tier_level=None) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', 'placeOrder', @@ -853,16 +856,16 @@ def test_order_file_modified_performance(self): def test_order_file_modified_endurance(self): mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE] + mock.return_value = [SoftLayer_Product_Package.SAAS_PACKAGE] - mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME) + mock_volume = copy.deepcopy(SoftLayer_Network_Storage.STAAS_TEST_VOLUME) mock_volume['storageType']['keyName'] = 'ENDURANCE_FILE_STORAGE' mock = self.set_mock('SoftLayer_Network_Storage', 'getObject') mock.return_value = mock_volume result = self.file.order_modified_volume(102, new_size=1000, new_iops=None, new_tier_level=4) - self.assertEqual(fixtures.SoftLayer_Product_Order.placeOrder, result) + self.assertEqual(SoftLayer_Product_Order.placeOrder, result) self.assert_called_with( 'SoftLayer_Product_Order', 'placeOrder', @@ -875,4 +878,16 @@ def test_order_file_modified_endurance(self): def test_list_file_volume_limit(self): result = self.file.list_file_volume_limit() - self.assertEqual(fixtures.SoftLayer_Network_Storage.getVolumeCountLimits, result) + self.assertEqual(SoftLayer_Network_Storage.getVolumeCountLimits, result) + + def test_get_ids_from_username(self): + result = self.file._get_ids_from_username("test") + self.assert_called_with('SoftLayer_Account', 'getNasNetworkStorage') + self.assertEqual([1], result) + + def test_get_ids_from_username_empty(self): + mock = self.set_mock('SoftLayer_Account', 'getNasNetworkStorage') + mock.return_value = [] + result = self.file._get_ids_from_username("test") + self.assert_called_with('SoftLayer_Account', 'getNasNetworkStorage') + self.assertEqual([], result) diff --git a/tests/managers/storage_utils_tests.py b/tests/managers/storage_utils_tests.py index f6934edaf..976f3749a 100644 --- a/tests/managers/storage_utils_tests.py +++ b/tests/managers/storage_utils_tests.py @@ -23,30 +23,20 @@ def set_up(self): # Tests for populate_host_templates() # --------------------------------------------------------------------- def test_populate_host_templates_no_ids_given(self): - host_templates = [] - - storage_utils.populate_host_templates(host_templates) - + host_templates = storage_utils.populate_host_templates() self.assertEqual([], host_templates) def test_populate_host_templates_empty_arrays_given(self): - host_templates = [] - - storage_utils.populate_host_templates( - host_templates, + host_templates = storage_utils.populate_host_templates( hardware_ids=[], virtual_guest_ids=[], ip_address_ids=[], subnet_ids=[] ) - self.assertEqual([], host_templates) def test_populate_host_templates(self): - host_templates = [] - - storage_utils.populate_host_templates( - host_templates, + host_templates = storage_utils.populate_host_templates( hardware_ids=[1111], virtual_guest_ids=[2222], ip_address_ids=[3333],