repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.order_duplicate_volume
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): """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. :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 return self.client.call('Product_Order', 'placeOrder', order)
python
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): """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. :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 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", ")", ":", "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", "return", "self", ".", "client", ".", "call", "(", "'Product_Order'", ",", "'placeOrder'", ",", "order", ")" ]
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. :return: Returns a SoftLayer_Container_Product_Order_Receipt
[ "Places", "an", "order", "for", "a", "duplicate", "block", "volume", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L262-L304
train
234,400
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.order_modified_volume
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)
python
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", "order_modified_volume", "(", "self", ",", "volume_id", ",", "new_size", "=", "None", ",", "new_iops", "=", "None", ",", "new_tier_level", "=", "None", ")", ":", "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", ")" ]
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
[ "Places", "an", "order", "for", "modifying", "an", "existing", "block", "volume", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L306-L333
train
234,401
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.order_block_volume
def order_block_volume(self, storage_type, location, size, os_type, iops=None, tier_level=None, snapshot_size=None, service_offering='storage_as_a_service', hourly_billing_flag=False): """Places an order for a block volume. :param storage_type: 'performance' or 'endurance' :param location: Datacenter in which to order iSCSI volume :param size: Size of the desired volume, in GB :param os_type: OS Type to use for volume alignment, see help for list :param iops: Number of IOPs for a "Performance" order :param tier_level: Tier level to use for an "Endurance" order :param snapshot_size: The size of optional snapshot space, if snapshot space should also be ordered (None if not ordered) :param service_offering: Requested offering package to use in the order ('storage_as_a_service', 'enterprise', or 'performance') :param hourly_billing_flag: Billing type, monthly (False) or hourly (True), default to monthly. """ order = storage_utils.prepare_volume_order_object( self, storage_type, location, size, iops, tier_level, snapshot_size, service_offering, 'block', hourly_billing_flag ) order['osFormatType'] = {'keyName': os_type} return self.client.call('Product_Order', 'placeOrder', order)
python
def order_block_volume(self, storage_type, location, size, os_type, iops=None, tier_level=None, snapshot_size=None, service_offering='storage_as_a_service', hourly_billing_flag=False): """Places an order for a block volume. :param storage_type: 'performance' or 'endurance' :param location: Datacenter in which to order iSCSI volume :param size: Size of the desired volume, in GB :param os_type: OS Type to use for volume alignment, see help for list :param iops: Number of IOPs for a "Performance" order :param tier_level: Tier level to use for an "Endurance" order :param snapshot_size: The size of optional snapshot space, if snapshot space should also be ordered (None if not ordered) :param service_offering: Requested offering package to use in the order ('storage_as_a_service', 'enterprise', or 'performance') :param hourly_billing_flag: Billing type, monthly (False) or hourly (True), default to monthly. """ order = storage_utils.prepare_volume_order_object( self, storage_type, location, size, iops, tier_level, snapshot_size, service_offering, 'block', hourly_billing_flag ) order['osFormatType'] = {'keyName': os_type} return self.client.call('Product_Order', 'placeOrder', order)
[ "def", "order_block_volume", "(", "self", ",", "storage_type", ",", "location", ",", "size", ",", "os_type", ",", "iops", "=", "None", ",", "tier_level", "=", "None", ",", "snapshot_size", "=", "None", ",", "service_offering", "=", "'storage_as_a_service'", ",", "hourly_billing_flag", "=", "False", ")", ":", "order", "=", "storage_utils", ".", "prepare_volume_order_object", "(", "self", ",", "storage_type", ",", "location", ",", "size", ",", "iops", ",", "tier_level", ",", "snapshot_size", ",", "service_offering", ",", "'block'", ",", "hourly_billing_flag", ")", "order", "[", "'osFormatType'", "]", "=", "{", "'keyName'", ":", "os_type", "}", "return", "self", ".", "client", ".", "call", "(", "'Product_Order'", ",", "'placeOrder'", ",", "order", ")" ]
Places an order for a block volume. :param storage_type: 'performance' or 'endurance' :param location: Datacenter in which to order iSCSI volume :param size: Size of the desired volume, in GB :param os_type: OS Type to use for volume alignment, see help for list :param iops: Number of IOPs for a "Performance" order :param tier_level: Tier level to use for an "Endurance" order :param snapshot_size: The size of optional snapshot space, if snapshot space should also be ordered (None if not ordered) :param service_offering: Requested offering package to use in the order ('storage_as_a_service', 'enterprise', or 'performance') :param hourly_billing_flag: Billing type, monthly (False) or hourly (True), default to monthly.
[ "Places", "an", "order", "for", "a", "block", "volume", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L343-L369
train
234,402
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.create_snapshot
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)
python
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", "create_snapshot", "(", "self", ",", "volume_id", ",", "notes", "=", "''", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "client", ".", "call", "(", "'Network_Storage'", ",", "'createSnapshot'", ",", "notes", ",", "id", "=", "volume_id", ",", "*", "*", "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
[ "Creates", "a", "snapshot", "on", "the", "given", "block", "volume", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L371-L380
train
234,403
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.order_snapshot_space
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)
python
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", "order_snapshot_space", "(", "self", ",", "volume_id", ",", "capacity", ",", "tier", ",", "upgrade", ",", "*", "*", "kwargs", ")", ":", "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", ")" ]
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
[ "Orders", "snapshot", "space", "for", "the", "given", "block", "volume", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L382-L402
train
234,404
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.enable_snapshots
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)
python
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", "enable_snapshots", "(", "self", ",", "volume_id", ",", "schedule_type", ",", "retention_count", ",", "minute", ",", "hour", ",", "day_of_week", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "client", ".", "call", "(", "'Network_Storage'", ",", "'enableSnapshots'", ",", "schedule_type", ",", "retention_count", ",", "minute", ",", "hour", ",", "day_of_week", ",", "id", "=", "volume_id", ",", "*", "*", "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
[ "Enables", "snapshots", "for", "a", "specific", "block", "volume", "at", "a", "given", "schedule" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L443-L463
train
234,405
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.disable_snapshots
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)
python
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", "disable_snapshots", "(", "self", ",", "volume_id", ",", "schedule_type", ")", ":", "return", "self", ".", "client", ".", "call", "(", "'Network_Storage'", ",", "'disableSnapshots'", ",", "schedule_type", ",", "id", "=", "volume_id", ")" ]
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
[ "Disables", "snapshots", "for", "a", "specific", "block", "volume", "at", "a", "given", "schedule" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L465-L474
train
234,406
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.list_volume_schedules
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')
python
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", "list_volume_schedules", "(", "self", ",", "volume_id", ")", ":", "volume_detail", "=", "self", ".", "client", ".", "call", "(", "'Network_Storage'", ",", "'getObject'", ",", "id", "=", "volume_id", ",", "mask", "=", "'schedules[type,properties[type]]'", ")", "return", "utils", ".", "lookup", "(", "volume_detail", ",", "'schedules'", ")" ]
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
[ "Lists", "schedules", "for", "a", "given", "volume" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L476-L488
train
234,407
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.restore_from_snapshot
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)
python
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", "restore_from_snapshot", "(", "self", ",", "volume_id", ",", "snapshot_id", ")", ":", "return", "self", ".", "client", ".", "call", "(", "'Network_Storage'", ",", "'restoreFromSnapshot'", ",", "snapshot_id", ",", "id", "=", "volume_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
[ "Restores", "a", "specific", "volume", "from", "a", "snapshot" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L490-L499
train
234,408
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.cancel_block_volume
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)
python
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", "cancel_block_volume", "(", "self", ",", "volume_id", ",", "reason", "=", "'No longer needed'", ",", "immediate", "=", "False", ")", ":", "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", ")" ]
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
[ "Cancels", "the", "given", "block", "storage", "volume", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L501-L526
train
234,409
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.failover_to_replicant
def failover_to_replicant(self, volume_id, replicant_id, immediate=False): """Failover to a volume replicant. :param integer volume_id: The id of the volume :param integer replicant_id: ID of replicant to failover to :param boolean immediate: Flag indicating if failover is immediate :return: Returns whether failover was successful or not """ return self.client.call('Network_Storage', 'failoverToReplicant', replicant_id, immediate, id=volume_id)
python
def failover_to_replicant(self, volume_id, replicant_id, immediate=False): """Failover to a volume replicant. :param integer volume_id: The id of the volume :param integer replicant_id: ID of replicant to failover to :param boolean immediate: Flag indicating if failover is immediate :return: Returns whether failover was successful or not """ return self.client.call('Network_Storage', 'failoverToReplicant', replicant_id, immediate, id=volume_id)
[ "def", "failover_to_replicant", "(", "self", ",", "volume_id", ",", "replicant_id", ",", "immediate", "=", "False", ")", ":", "return", "self", ".", "client", ".", "call", "(", "'Network_Storage'", ",", "'failoverToReplicant'", ",", "replicant_id", ",", "immediate", ",", "id", "=", "volume_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 :param boolean immediate: Flag indicating if failover is immediate :return: Returns whether failover was successful or not
[ "Failover", "to", "a", "volume", "replicant", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L528-L538
train
234,410
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.failback_from_replicant
def failback_from_replicant(self, volume_id, replicant_id): """Failback from a volume replicant. :param integer volume_id: The id of the volume :param integer replicant_id: ID of replicant to failback from :return: Returns whether failback was successful or not """ return self.client.call('Network_Storage', 'failbackFromReplicant', replicant_id, id=volume_id)
python
def failback_from_replicant(self, volume_id, replicant_id): """Failback from a volume replicant. :param integer volume_id: The id of the volume :param integer replicant_id: ID of replicant to failback from :return: Returns whether failback was successful or not """ return self.client.call('Network_Storage', 'failbackFromReplicant', replicant_id, id=volume_id)
[ "def", "failback_from_replicant", "(", "self", ",", "volume_id", ",", "replicant_id", ")", ":", "return", "self", ".", "client", ".", "call", "(", "'Network_Storage'", ",", "'failbackFromReplicant'", ",", "replicant_id", ",", "id", "=", "volume_id", ")" ]
Failback from a volume replicant. :param integer volume_id: The id of the volume :param integer replicant_id: ID of replicant to failback from :return: Returns whether failback was successful or not
[ "Failback", "from", "a", "volume", "replicant", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L540-L549
train
234,411
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.set_credential_password
def set_credential_password(self, access_id, password): """Sets the password for an access host :param integer access_id: id of the access host :param string password: password to set """ return self.client.call('Network_Storage_Allowed_Host', 'setCredentialPassword', password, id=access_id)
python
def set_credential_password(self, access_id, password): """Sets the password for an access host :param integer access_id: id of the access host :param string password: password to set """ return self.client.call('Network_Storage_Allowed_Host', 'setCredentialPassword', password, id=access_id)
[ "def", "set_credential_password", "(", "self", ",", "access_id", ",", "password", ")", ":", "return", "self", ".", "client", ".", "call", "(", "'Network_Storage_Allowed_Host'", ",", "'setCredentialPassword'", ",", "password", ",", "id", "=", "access_id", ")" ]
Sets the password for an access host :param integer access_id: id of the access host :param string password: password to set
[ "Sets", "the", "password", "for", "an", "access", "host" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L551-L559
train
234,412
softlayer/softlayer-python
SoftLayer/managers/block.py
BlockStorageManager.create_or_update_lun_id
def create_or_update_lun_id(self, volume_id, lun_id): """Set the LUN ID on a volume. :param integer volume_id: The id of the volume :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)
python
def create_or_update_lun_id(self, volume_id, lun_id): """Set the LUN ID on a volume. :param integer volume_id: The id of the volume :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)
[ "def", "create_or_update_lun_id", "(", "self", ",", "volume_id", ",", "lun_id", ")", ":", "return", "self", ".", "client", ".", "call", "(", "'Network_Storage'", ",", "'createOrUpdateLunId'", ",", "lun_id", ",", "id", "=", "volume_id", ")" ]
Set the LUN ID on a volume. :param integer volume_id: The id of the volume :param integer lun_id: LUN ID to set on the volume :return: a SoftLayer_Network_Storage_Property object
[ "Set", "the", "LUN", "ID", "on", "a", "volume", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/block.py#L561-L569
train
234,413
softlayer/softlayer-python
SoftLayer/CLI/summary.py
cli
def cli(env, sortby): """Account summary.""" mgr = SoftLayer.NetworkManager(env.client) datacenters = mgr.summary_by_datacenter() table = formatting.Table(COLUMNS) table.sortby = sortby for name, datacenter in datacenters.items(): table.add_row([ name, datacenter['hardware_count'], datacenter['virtual_guest_count'], datacenter['vlan_count'], datacenter['subnet_count'], datacenter['public_ip_count'], ]) env.fout(table)
python
def cli(env, sortby): """Account summary.""" mgr = SoftLayer.NetworkManager(env.client) datacenters = mgr.summary_by_datacenter() table = formatting.Table(COLUMNS) table.sortby = sortby for name, datacenter in datacenters.items(): table.add_row([ name, datacenter['hardware_count'], datacenter['virtual_guest_count'], datacenter['vlan_count'], datacenter['subnet_count'], datacenter['public_ip_count'], ]) env.fout(table)
[ "def", "cli", "(", "env", ",", "sortby", ")", ":", "mgr", "=", "SoftLayer", ".", "NetworkManager", "(", "env", ".", "client", ")", "datacenters", "=", "mgr", ".", "summary_by_datacenter", "(", ")", "table", "=", "formatting", ".", "Table", "(", "COLUMNS", ")", "table", ".", "sortby", "=", "sortby", "for", "name", ",", "datacenter", "in", "datacenters", ".", "items", "(", ")", ":", "table", ".", "add_row", "(", "[", "name", ",", "datacenter", "[", "'hardware_count'", "]", ",", "datacenter", "[", "'virtual_guest_count'", "]", ",", "datacenter", "[", "'vlan_count'", "]", ",", "datacenter", "[", "'subnet_count'", "]", ",", "datacenter", "[", "'public_ip_count'", "]", ",", "]", ")", "env", ".", "fout", "(", "table", ")" ]
Account summary.
[ "Account", "summary", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/summary.py#L25-L44
train
234,414
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_packages_of_type
def get_packages_of_type(self, package_types, mask=None): """Get packages that match a certain type. Each ordering package has a type, so return all packages that match the types we are looking for :param list package_types: List of strings representing the package type keynames we are interested in. :param string mask: Mask to specify the properties we want to retrieve """ _filter = { 'type': { 'keyName': { 'operation': 'in', 'options': [ {'name': 'data', 'value': package_types} ], }, }, } packages = self.package_svc.getAllObjects(mask=mask, filter=_filter) packages = self.filter_outlet_packages(packages) return packages
python
def get_packages_of_type(self, package_types, mask=None): """Get packages that match a certain type. Each ordering package has a type, so return all packages that match the types we are looking for :param list package_types: List of strings representing the package type keynames we are interested in. :param string mask: Mask to specify the properties we want to retrieve """ _filter = { 'type': { 'keyName': { 'operation': 'in', 'options': [ {'name': 'data', 'value': package_types} ], }, }, } packages = self.package_svc.getAllObjects(mask=mask, filter=_filter) packages = self.filter_outlet_packages(packages) return packages
[ "def", "get_packages_of_type", "(", "self", ",", "package_types", ",", "mask", "=", "None", ")", ":", "_filter", "=", "{", "'type'", ":", "{", "'keyName'", ":", "{", "'operation'", ":", "'in'", ",", "'options'", ":", "[", "{", "'name'", ":", "'data'", ",", "'value'", ":", "package_types", "}", "]", ",", "}", ",", "}", ",", "}", "packages", "=", "self", ".", "package_svc", ".", "getAllObjects", "(", "mask", "=", "mask", ",", "filter", "=", "_filter", ")", "packages", "=", "self", ".", "filter_outlet_packages", "(", "packages", ")", "return", "packages" ]
Get packages that match a certain type. Each ordering package has a type, so return all packages that match the types we are looking for :param list package_types: List of strings representing the package type keynames we are interested in. :param string mask: Mask to specify the properties we want to retrieve
[ "Get", "packages", "that", "match", "a", "certain", "type", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L40-L65
train
234,415
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.filter_outlet_packages
def filter_outlet_packages(packages): """Remove packages designated as OUTLET. Those type of packages must be handled in a different way, and they are not supported at the moment. :param packages: Dictionary of packages. Name and description keys must be present in each of them. """ non_outlet_packages = [] for package in packages: if all(['OUTLET' not in package.get('description', '').upper(), 'OUTLET' not in package.get('name', '').upper()]): non_outlet_packages.append(package) return non_outlet_packages
python
def filter_outlet_packages(packages): """Remove packages designated as OUTLET. Those type of packages must be handled in a different way, and they are not supported at the moment. :param packages: Dictionary of packages. Name and description keys must be present in each of them. """ non_outlet_packages = [] for package in packages: if all(['OUTLET' not in package.get('description', '').upper(), 'OUTLET' not in package.get('name', '').upper()]): non_outlet_packages.append(package) return non_outlet_packages
[ "def", "filter_outlet_packages", "(", "packages", ")", ":", "non_outlet_packages", "=", "[", "]", "for", "package", "in", "packages", ":", "if", "all", "(", "[", "'OUTLET'", "not", "in", "package", ".", "get", "(", "'description'", ",", "''", ")", ".", "upper", "(", ")", ",", "'OUTLET'", "not", "in", "package", ".", "get", "(", "'name'", ",", "''", ")", ".", "upper", "(", ")", "]", ")", ":", "non_outlet_packages", ".", "append", "(", "package", ")", "return", "non_outlet_packages" ]
Remove packages designated as OUTLET. Those type of packages must be handled in a different way, and they are not supported at the moment. :param packages: Dictionary of packages. Name and description keys must be present in each of them.
[ "Remove", "packages", "designated", "as", "OUTLET", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L68-L85
train
234,416
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_only_active_packages
def get_only_active_packages(packages): """Return only active packages. If a package is active, it is eligible for ordering This will inspect the 'isActive' property on the provided packages :param packages: Dictionary of packages, isActive key must be present """ active_packages = [] for package in packages: if package['isActive']: active_packages.append(package) return active_packages
python
def get_only_active_packages(packages): """Return only active packages. If a package is active, it is eligible for ordering This will inspect the 'isActive' property on the provided packages :param packages: Dictionary of packages, isActive key must be present """ active_packages = [] for package in packages: if package['isActive']: active_packages.append(package) return active_packages
[ "def", "get_only_active_packages", "(", "packages", ")", ":", "active_packages", "=", "[", "]", "for", "package", "in", "packages", ":", "if", "package", "[", "'isActive'", "]", ":", "active_packages", ".", "append", "(", "package", ")", "return", "active_packages" ]
Return only active packages. If a package is active, it is eligible for ordering This will inspect the 'isActive' property on the provided packages :param packages: Dictionary of packages, isActive key must be present
[ "Return", "only", "active", "packages", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L88-L103
train
234,417
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_package_by_type
def get_package_by_type(self, package_type, mask=None): """Get a single package of a given type. Syntactic sugar to retrieve a single package of a given type. If multiple packages share the given type, this will return the first one returned by the API. If no packages are found, returns None :param string package_type: representing the package type key name we are interested in """ packages = self.get_packages_of_type([package_type], mask) if len(packages) == 0: return None else: return packages.pop()
python
def get_package_by_type(self, package_type, mask=None): """Get a single package of a given type. Syntactic sugar to retrieve a single package of a given type. If multiple packages share the given type, this will return the first one returned by the API. If no packages are found, returns None :param string package_type: representing the package type key name we are interested in """ packages = self.get_packages_of_type([package_type], mask) if len(packages) == 0: return None else: return packages.pop()
[ "def", "get_package_by_type", "(", "self", ",", "package_type", ",", "mask", "=", "None", ")", ":", "packages", "=", "self", ".", "get_packages_of_type", "(", "[", "package_type", "]", ",", "mask", ")", "if", "len", "(", "packages", ")", "==", "0", ":", "return", "None", "else", ":", "return", "packages", ".", "pop", "(", ")" ]
Get a single package of a given type. Syntactic sugar to retrieve a single package of a given type. If multiple packages share the given type, this will return the first one returned by the API. If no packages are found, returns None :param string package_type: representing the package type key name we are interested in
[ "Get", "a", "single", "package", "of", "a", "given", "type", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L105-L119
train
234,418
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_package_id_by_type
def get_package_id_by_type(self, package_type): """Return the package ID of a Product Package with a given type. :param string package_type: representing the package type key name we are interested in :raises ValueError: when no package of the given type is found """ mask = "mask[id, name, description, isActive, type[keyName]]" package = self.get_package_by_type(package_type, mask) if package: return package['id'] else: raise ValueError("No package found for type: " + package_type)
python
def get_package_id_by_type(self, package_type): """Return the package ID of a Product Package with a given type. :param string package_type: representing the package type key name we are interested in :raises ValueError: when no package of the given type is found """ mask = "mask[id, name, description, isActive, type[keyName]]" package = self.get_package_by_type(package_type, mask) if package: return package['id'] else: raise ValueError("No package found for type: " + package_type)
[ "def", "get_package_id_by_type", "(", "self", ",", "package_type", ")", ":", "mask", "=", "\"mask[id, name, description, isActive, type[keyName]]\"", "package", "=", "self", ".", "get_package_by_type", "(", "package_type", ",", "mask", ")", "if", "package", ":", "return", "package", "[", "'id'", "]", "else", ":", "raise", "ValueError", "(", "\"No package found for type: \"", "+", "package_type", ")" ]
Return the package ID of a Product Package with a given type. :param string package_type: representing the package type key name we are interested in :raises ValueError: when no package of the given type is found
[ "Return", "the", "package", "ID", "of", "a", "Product", "Package", "with", "a", "given", "type", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L121-L133
train
234,419
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_quotes
def get_quotes(self): """Retrieve a list of active quotes. :returns: a list of SoftLayer_Billing_Order_Quote """ mask = "mask[order[id,items[id,package[id,keyName]]]]" quotes = self.client['Account'].getActiveQuotes(mask=mask) return quotes
python
def get_quotes(self): """Retrieve a list of active quotes. :returns: a list of SoftLayer_Billing_Order_Quote """ mask = "mask[order[id,items[id,package[id,keyName]]]]" quotes = self.client['Account'].getActiveQuotes(mask=mask) return quotes
[ "def", "get_quotes", "(", "self", ")", ":", "mask", "=", "\"mask[order[id,items[id,package[id,keyName]]]]\"", "quotes", "=", "self", ".", "client", "[", "'Account'", "]", ".", "getActiveQuotes", "(", "mask", "=", "mask", ")", "return", "quotes" ]
Retrieve a list of active quotes. :returns: a list of SoftLayer_Billing_Order_Quote
[ "Retrieve", "a", "list", "of", "active", "quotes", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L135-L142
train
234,420
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_quote_details
def get_quote_details(self, quote_id): """Retrieve quote details. :param quote_id: ID number of target quote """ mask = "mask[order[id,items[package[id,keyName]]]]" quote = self.client['Billing_Order_Quote'].getObject(id=quote_id, mask=mask) return quote
python
def get_quote_details(self, quote_id): """Retrieve quote details. :param quote_id: ID number of target quote """ mask = "mask[order[id,items[package[id,keyName]]]]" quote = self.client['Billing_Order_Quote'].getObject(id=quote_id, mask=mask) return quote
[ "def", "get_quote_details", "(", "self", ",", "quote_id", ")", ":", "mask", "=", "\"mask[order[id,items[package[id,keyName]]]]\"", "quote", "=", "self", ".", "client", "[", "'Billing_Order_Quote'", "]", ".", "getObject", "(", "id", "=", "quote_id", ",", "mask", "=", "mask", ")", "return", "quote" ]
Retrieve quote details. :param quote_id: ID number of target quote
[ "Retrieve", "quote", "details", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L144-L152
train
234,421
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_order_container
def get_order_container(self, quote_id): """Generate an order container from a quote object. :param quote_id: ID number of target quote """ quote = self.client['Billing_Order_Quote'] container = quote.getRecalculatedOrderContainer(id=quote_id) return container
python
def get_order_container(self, quote_id): """Generate an order container from a quote object. :param quote_id: ID number of target quote """ quote = self.client['Billing_Order_Quote'] container = quote.getRecalculatedOrderContainer(id=quote_id) return container
[ "def", "get_order_container", "(", "self", ",", "quote_id", ")", ":", "quote", "=", "self", ".", "client", "[", "'Billing_Order_Quote'", "]", "container", "=", "quote", ".", "getRecalculatedOrderContainer", "(", "id", "=", "quote_id", ")", "return", "container" ]
Generate an order container from a quote object. :param quote_id: ID number of target quote
[ "Generate", "an", "order", "container", "from", "a", "quote", "object", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L154-L162
train
234,422
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.generate_order_template
def generate_order_template(self, quote_id, extra, quantity=1): """Generate a complete order template. :param int quote_id: ID of target quote :param dictionary extra: Overrides for the defaults of SoftLayer_Container_Product_Order :param int quantity: Number of items to order. """ if not isinstance(extra, dict): raise ValueError("extra is not formatted properly") container = self.get_order_container(quote_id) container['quantity'] = quantity for key in extra.keys(): container[key] = extra[key] return container
python
def generate_order_template(self, quote_id, extra, quantity=1): """Generate a complete order template. :param int quote_id: ID of target quote :param dictionary extra: Overrides for the defaults of SoftLayer_Container_Product_Order :param int quantity: Number of items to order. """ if not isinstance(extra, dict): raise ValueError("extra is not formatted properly") container = self.get_order_container(quote_id) container['quantity'] = quantity for key in extra.keys(): container[key] = extra[key] return container
[ "def", "generate_order_template", "(", "self", ",", "quote_id", ",", "extra", ",", "quantity", "=", "1", ")", ":", "if", "not", "isinstance", "(", "extra", ",", "dict", ")", ":", "raise", "ValueError", "(", "\"extra is not formatted properly\"", ")", "container", "=", "self", ".", "get_order_container", "(", "quote_id", ")", "container", "[", "'quantity'", "]", "=", "quantity", "for", "key", "in", "extra", ".", "keys", "(", ")", ":", "container", "[", "key", "]", "=", "extra", "[", "key", "]", "return", "container" ]
Generate a complete order template. :param int quote_id: ID of target quote :param dictionary extra: Overrides for the defaults of SoftLayer_Container_Product_Order :param int quantity: Number of items to order.
[ "Generate", "a", "complete", "order", "template", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L164-L181
train
234,423
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.verify_quote
def verify_quote(self, quote_id, extra): """Verifies that a quote order is valid. :: extras = { 'hardware': {'hostname': 'test', 'domain': 'testing.com'}, 'quantity': 2 } manager = ordering.OrderingManager(env.client) result = manager.verify_quote(12345, extras) :param int quote_id: ID for the target quote :param dictionary extra: Overrides for the defaults of SoftLayer_Container_Product_Order :param int quantity: Quantity to override default """ container = self.generate_order_template(quote_id, extra) clean_container = {} # There are a few fields that wil cause exceptions in the XML endpoing if you send in '' # reservedCapacityId and hostId specifically. But we clean all just to be safe. # This for some reason is only a problem on verify_quote. for key in container.keys(): if container.get(key) != '': clean_container[key] = container[key] return self.client.call('SoftLayer_Billing_Order_Quote', 'verifyOrder', clean_container, id=quote_id)
python
def verify_quote(self, quote_id, extra): """Verifies that a quote order is valid. :: extras = { 'hardware': {'hostname': 'test', 'domain': 'testing.com'}, 'quantity': 2 } manager = ordering.OrderingManager(env.client) result = manager.verify_quote(12345, extras) :param int quote_id: ID for the target quote :param dictionary extra: Overrides for the defaults of SoftLayer_Container_Product_Order :param int quantity: Quantity to override default """ container = self.generate_order_template(quote_id, extra) clean_container = {} # There are a few fields that wil cause exceptions in the XML endpoing if you send in '' # reservedCapacityId and hostId specifically. But we clean all just to be safe. # This for some reason is only a problem on verify_quote. for key in container.keys(): if container.get(key) != '': clean_container[key] = container[key] return self.client.call('SoftLayer_Billing_Order_Quote', 'verifyOrder', clean_container, id=quote_id)
[ "def", "verify_quote", "(", "self", ",", "quote_id", ",", "extra", ")", ":", "container", "=", "self", ".", "generate_order_template", "(", "quote_id", ",", "extra", ")", "clean_container", "=", "{", "}", "# There are a few fields that wil cause exceptions in the XML endpoing if you send in ''", "# reservedCapacityId and hostId specifically. But we clean all just to be safe.", "# This for some reason is only a problem on verify_quote.", "for", "key", "in", "container", ".", "keys", "(", ")", ":", "if", "container", ".", "get", "(", "key", ")", "!=", "''", ":", "clean_container", "[", "key", "]", "=", "container", "[", "key", "]", "return", "self", ".", "client", ".", "call", "(", "'SoftLayer_Billing_Order_Quote'", ",", "'verifyOrder'", ",", "clean_container", ",", "id", "=", "quote_id", ")" ]
Verifies that a quote order is valid. :: extras = { 'hardware': {'hostname': 'test', 'domain': 'testing.com'}, 'quantity': 2 } manager = ordering.OrderingManager(env.client) result = manager.verify_quote(12345, extras) :param int quote_id: ID for the target quote :param dictionary extra: Overrides for the defaults of SoftLayer_Container_Product_Order :param int quantity: Quantity to override default
[ "Verifies", "that", "a", "quote", "order", "is", "valid", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L183-L210
train
234,424
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.order_quote
def order_quote(self, quote_id, extra): """Places an order using a quote :: extras = { 'hardware': {'hostname': 'test', 'domain': 'testing.com'}, 'quantity': 2 } manager = ordering.OrderingManager(env.client) result = manager.order_quote(12345, extras) :param int quote_id: ID for the target quote :param dictionary extra: Overrides for the defaults of SoftLayer_Container_Product_Order :param int quantity: Quantity to override default """ container = self.generate_order_template(quote_id, extra) return self.client.call('SoftLayer_Billing_Order_Quote', 'placeOrder', container, id=quote_id)
python
def order_quote(self, quote_id, extra): """Places an order using a quote :: extras = { 'hardware': {'hostname': 'test', 'domain': 'testing.com'}, 'quantity': 2 } manager = ordering.OrderingManager(env.client) result = manager.order_quote(12345, extras) :param int quote_id: ID for the target quote :param dictionary extra: Overrides for the defaults of SoftLayer_Container_Product_Order :param int quantity: Quantity to override default """ container = self.generate_order_template(quote_id, extra) return self.client.call('SoftLayer_Billing_Order_Quote', 'placeOrder', container, id=quote_id)
[ "def", "order_quote", "(", "self", ",", "quote_id", ",", "extra", ")", ":", "container", "=", "self", ".", "generate_order_template", "(", "quote_id", ",", "extra", ")", "return", "self", ".", "client", ".", "call", "(", "'SoftLayer_Billing_Order_Quote'", ",", "'placeOrder'", ",", "container", ",", "id", "=", "quote_id", ")" ]
Places an order using a quote :: extras = { 'hardware': {'hostname': 'test', 'domain': 'testing.com'}, 'quantity': 2 } manager = ordering.OrderingManager(env.client) result = manager.order_quote(12345, extras) :param int quote_id: ID for the target quote :param dictionary extra: Overrides for the defaults of SoftLayer_Container_Product_Order :param int quantity: Quantity to override default
[ "Places", "an", "order", "using", "a", "quote" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L212-L230
train
234,425
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_package_by_key
def get_package_by_key(self, package_keyname, mask=None): """Get a single package with a given key. If no packages are found, returns None :param package_keyname: string representing the package key name we are interested in. :param string mask: Mask to specify the properties we want to retrieve """ _filter = {'keyName': {'operation': package_keyname}} packages = self.package_svc.getAllObjects(mask=mask, filter=_filter) if len(packages) == 0: raise exceptions.SoftLayerError("Package {} does not exist".format(package_keyname)) return packages.pop()
python
def get_package_by_key(self, package_keyname, mask=None): """Get a single package with a given key. If no packages are found, returns None :param package_keyname: string representing the package key name we are interested in. :param string mask: Mask to specify the properties we want to retrieve """ _filter = {'keyName': {'operation': package_keyname}} packages = self.package_svc.getAllObjects(mask=mask, filter=_filter) if len(packages) == 0: raise exceptions.SoftLayerError("Package {} does not exist".format(package_keyname)) return packages.pop()
[ "def", "get_package_by_key", "(", "self", ",", "package_keyname", ",", "mask", "=", "None", ")", ":", "_filter", "=", "{", "'keyName'", ":", "{", "'operation'", ":", "package_keyname", "}", "}", "packages", "=", "self", ".", "package_svc", ".", "getAllObjects", "(", "mask", "=", "mask", ",", "filter", "=", "_filter", ")", "if", "len", "(", "packages", ")", "==", "0", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "\"Package {} does not exist\"", ".", "format", "(", "package_keyname", ")", ")", "return", "packages", ".", "pop", "(", ")" ]
Get a single package with a given key. If no packages are found, returns None :param package_keyname: string representing the package key name we are interested in. :param string mask: Mask to specify the properties we want to retrieve
[ "Get", "a", "single", "package", "with", "a", "given", "key", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L232-L246
train
234,426
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.list_categories
def list_categories(self, package_keyname, **kwargs): """List the categories for the given package. :param str package_keyname: The package for which to get the categories. :returns: List of categories associated with the package """ get_kwargs = {} get_kwargs['mask'] = kwargs.get('mask', CATEGORY_MASK) if 'filter' in kwargs: get_kwargs['filter'] = kwargs['filter'] package = self.get_package_by_key(package_keyname, mask='id') categories = self.package_svc.getConfiguration(id=package['id'], **get_kwargs) return categories
python
def list_categories(self, package_keyname, **kwargs): """List the categories for the given package. :param str package_keyname: The package for which to get the categories. :returns: List of categories associated with the package """ get_kwargs = {} get_kwargs['mask'] = kwargs.get('mask', CATEGORY_MASK) if 'filter' in kwargs: get_kwargs['filter'] = kwargs['filter'] package = self.get_package_by_key(package_keyname, mask='id') categories = self.package_svc.getConfiguration(id=package['id'], **get_kwargs) return categories
[ "def", "list_categories", "(", "self", ",", "package_keyname", ",", "*", "*", "kwargs", ")", ":", "get_kwargs", "=", "{", "}", "get_kwargs", "[", "'mask'", "]", "=", "kwargs", ".", "get", "(", "'mask'", ",", "CATEGORY_MASK", ")", "if", "'filter'", "in", "kwargs", ":", "get_kwargs", "[", "'filter'", "]", "=", "kwargs", "[", "'filter'", "]", "package", "=", "self", ".", "get_package_by_key", "(", "package_keyname", ",", "mask", "=", "'id'", ")", "categories", "=", "self", ".", "package_svc", ".", "getConfiguration", "(", "id", "=", "package", "[", "'id'", "]", ",", "*", "*", "get_kwargs", ")", "return", "categories" ]
List the categories for the given package. :param str package_keyname: The package for which to get the categories. :returns: List of categories associated with the package
[ "List", "the", "categories", "for", "the", "given", "package", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L248-L262
train
234,427
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.list_items
def list_items(self, package_keyname, **kwargs): """List the items for the given package. :param str package_keyname: The package for which to get the items. :returns: List of items in the package """ get_kwargs = {} get_kwargs['mask'] = kwargs.get('mask', ITEM_MASK) if 'filter' in kwargs: get_kwargs['filter'] = kwargs['filter'] package = self.get_package_by_key(package_keyname, mask='id') items = self.package_svc.getItems(id=package['id'], **get_kwargs) return items
python
def list_items(self, package_keyname, **kwargs): """List the items for the given package. :param str package_keyname: The package for which to get the items. :returns: List of items in the package """ get_kwargs = {} get_kwargs['mask'] = kwargs.get('mask', ITEM_MASK) if 'filter' in kwargs: get_kwargs['filter'] = kwargs['filter'] package = self.get_package_by_key(package_keyname, mask='id') items = self.package_svc.getItems(id=package['id'], **get_kwargs) return items
[ "def", "list_items", "(", "self", ",", "package_keyname", ",", "*", "*", "kwargs", ")", ":", "get_kwargs", "=", "{", "}", "get_kwargs", "[", "'mask'", "]", "=", "kwargs", ".", "get", "(", "'mask'", ",", "ITEM_MASK", ")", "if", "'filter'", "in", "kwargs", ":", "get_kwargs", "[", "'filter'", "]", "=", "kwargs", "[", "'filter'", "]", "package", "=", "self", ".", "get_package_by_key", "(", "package_keyname", ",", "mask", "=", "'id'", ")", "items", "=", "self", ".", "package_svc", ".", "getItems", "(", "id", "=", "package", "[", "'id'", "]", ",", "*", "*", "get_kwargs", ")", "return", "items" ]
List the items for the given package. :param str package_keyname: The package for which to get the items. :returns: List of items in the package
[ "List", "the", "items", "for", "the", "given", "package", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L264-L279
train
234,428
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.list_packages
def list_packages(self, **kwargs): """List active packages. :returns: List of active packages. """ get_kwargs = {} get_kwargs['mask'] = kwargs.get('mask', PACKAGE_MASK) if 'filter' in kwargs: get_kwargs['filter'] = kwargs['filter'] packages = self.package_svc.getAllObjects(**get_kwargs) return [package for package in packages if package['isActive']]
python
def list_packages(self, **kwargs): """List active packages. :returns: List of active packages. """ get_kwargs = {} get_kwargs['mask'] = kwargs.get('mask', PACKAGE_MASK) if 'filter' in kwargs: get_kwargs['filter'] = kwargs['filter'] packages = self.package_svc.getAllObjects(**get_kwargs) return [package for package in packages if package['isActive']]
[ "def", "list_packages", "(", "self", ",", "*", "*", "kwargs", ")", ":", "get_kwargs", "=", "{", "}", "get_kwargs", "[", "'mask'", "]", "=", "kwargs", ".", "get", "(", "'mask'", ",", "PACKAGE_MASK", ")", "if", "'filter'", "in", "kwargs", ":", "get_kwargs", "[", "'filter'", "]", "=", "kwargs", "[", "'filter'", "]", "packages", "=", "self", ".", "package_svc", ".", "getAllObjects", "(", "*", "*", "get_kwargs", ")", "return", "[", "package", "for", "package", "in", "packages", "if", "package", "[", "'isActive'", "]", "]" ]
List active packages. :returns: List of active packages.
[ "List", "active", "packages", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L281-L295
train
234,429
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.list_presets
def list_presets(self, package_keyname, **kwargs): """Gets active presets for the given package. :param str package_keyname: The package for which to get presets :returns: A list of package presets that can be used for ordering """ get_kwargs = {} get_kwargs['mask'] = kwargs.get('mask', PRESET_MASK) if 'filter' in kwargs: get_kwargs['filter'] = kwargs['filter'] package = self.get_package_by_key(package_keyname, mask='id') acc_presets = self.package_svc.getAccountRestrictedActivePresets(id=package['id'], **get_kwargs) active_presets = self.package_svc.getActivePresets(id=package['id'], **get_kwargs) return active_presets + acc_presets
python
def list_presets(self, package_keyname, **kwargs): """Gets active presets for the given package. :param str package_keyname: The package for which to get presets :returns: A list of package presets that can be used for ordering """ get_kwargs = {} get_kwargs['mask'] = kwargs.get('mask', PRESET_MASK) if 'filter' in kwargs: get_kwargs['filter'] = kwargs['filter'] package = self.get_package_by_key(package_keyname, mask='id') acc_presets = self.package_svc.getAccountRestrictedActivePresets(id=package['id'], **get_kwargs) active_presets = self.package_svc.getActivePresets(id=package['id'], **get_kwargs) return active_presets + acc_presets
[ "def", "list_presets", "(", "self", ",", "package_keyname", ",", "*", "*", "kwargs", ")", ":", "get_kwargs", "=", "{", "}", "get_kwargs", "[", "'mask'", "]", "=", "kwargs", ".", "get", "(", "'mask'", ",", "PRESET_MASK", ")", "if", "'filter'", "in", "kwargs", ":", "get_kwargs", "[", "'filter'", "]", "=", "kwargs", "[", "'filter'", "]", "package", "=", "self", ".", "get_package_by_key", "(", "package_keyname", ",", "mask", "=", "'id'", ")", "acc_presets", "=", "self", ".", "package_svc", ".", "getAccountRestrictedActivePresets", "(", "id", "=", "package", "[", "'id'", "]", ",", "*", "*", "get_kwargs", ")", "active_presets", "=", "self", ".", "package_svc", ".", "getActivePresets", "(", "id", "=", "package", "[", "'id'", "]", ",", "*", "*", "get_kwargs", ")", "return", "active_presets", "+", "acc_presets" ]
Gets active presets for the given package. :param str package_keyname: The package for which to get presets :returns: A list of package presets that can be used for ordering
[ "Gets", "active", "presets", "for", "the", "given", "package", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L297-L313
train
234,430
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_preset_by_key
def get_preset_by_key(self, package_keyname, preset_keyname, mask=None): """Gets a single preset with the given key.""" preset_operation = '_= %s' % preset_keyname _filter = { 'activePresets': { 'keyName': { 'operation': preset_operation } }, 'accountRestrictedActivePresets': { 'keyName': { 'operation': preset_operation } } } presets = self.list_presets(package_keyname, mask=mask, filter=_filter) if len(presets) == 0: raise exceptions.SoftLayerError( "Preset {} does not exist in package {}".format(preset_keyname, package_keyname)) return presets[0]
python
def get_preset_by_key(self, package_keyname, preset_keyname, mask=None): """Gets a single preset with the given key.""" preset_operation = '_= %s' % preset_keyname _filter = { 'activePresets': { 'keyName': { 'operation': preset_operation } }, 'accountRestrictedActivePresets': { 'keyName': { 'operation': preset_operation } } } presets = self.list_presets(package_keyname, mask=mask, filter=_filter) if len(presets) == 0: raise exceptions.SoftLayerError( "Preset {} does not exist in package {}".format(preset_keyname, package_keyname)) return presets[0]
[ "def", "get_preset_by_key", "(", "self", ",", "package_keyname", ",", "preset_keyname", ",", "mask", "=", "None", ")", ":", "preset_operation", "=", "'_= %s'", "%", "preset_keyname", "_filter", "=", "{", "'activePresets'", ":", "{", "'keyName'", ":", "{", "'operation'", ":", "preset_operation", "}", "}", ",", "'accountRestrictedActivePresets'", ":", "{", "'keyName'", ":", "{", "'operation'", ":", "preset_operation", "}", "}", "}", "presets", "=", "self", ".", "list_presets", "(", "package_keyname", ",", "mask", "=", "mask", ",", "filter", "=", "_filter", ")", "if", "len", "(", "presets", ")", "==", "0", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "\"Preset {} does not exist in package {}\"", ".", "format", "(", "preset_keyname", ",", "package_keyname", ")", ")", "return", "presets", "[", "0", "]" ]
Gets a single preset with the given key.
[ "Gets", "a", "single", "preset", "with", "the", "given", "key", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L315-L338
train
234,431
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_price_id_list
def get_price_id_list(self, package_keyname, item_keynames, core=None): """Converts a list of item keynames to a list of price IDs. This function is used to convert a list of item keynames into a list of price IDs that are used in the Product_Order verifyOrder() and placeOrder() functions. :param str package_keyname: The package associated with the prices :param list item_keynames: A list of item keyname strings :param str core: preset guest core capacity. :returns: A list of price IDs associated with the given item keynames in the given package """ mask = 'id, itemCategory, keyName, prices[categories]' items = self.list_items(package_keyname, mask=mask) prices = [] category_dict = {"gpu0": -1, "pcie_slot0": -1} for item_keyname in item_keynames: try: # Need to find the item in the package that has a matching # keyName with the current item we are searching for matching_item = [i for i in items if i['keyName'] == item_keyname][0] except IndexError: raise exceptions.SoftLayerError( "Item {} does not exist for package {}".format(item_keyname, package_keyname)) # we want to get the price ID that has no location attached to it, # because that is the most generic price. verifyOrder/placeOrder # can take that ID and create the proper price for us in the location # in which the order is made item_category = matching_item['itemCategory']['categoryCode'] if item_category not in category_dict: price_id = self.get_item_price_id(core, matching_item['prices']) else: # GPU and PCIe items has two generic prices and they are added to the list # according to the number of items in the order. category_dict[item_category] += 1 category_code = item_category[:-1] + str(category_dict[item_category]) price_id = [p['id'] for p in matching_item['prices'] if not p['locationGroupId'] and p['categories'][0]['categoryCode'] == category_code][0] prices.append(price_id) return prices
python
def get_price_id_list(self, package_keyname, item_keynames, core=None): """Converts a list of item keynames to a list of price IDs. This function is used to convert a list of item keynames into a list of price IDs that are used in the Product_Order verifyOrder() and placeOrder() functions. :param str package_keyname: The package associated with the prices :param list item_keynames: A list of item keyname strings :param str core: preset guest core capacity. :returns: A list of price IDs associated with the given item keynames in the given package """ mask = 'id, itemCategory, keyName, prices[categories]' items = self.list_items(package_keyname, mask=mask) prices = [] category_dict = {"gpu0": -1, "pcie_slot0": -1} for item_keyname in item_keynames: try: # Need to find the item in the package that has a matching # keyName with the current item we are searching for matching_item = [i for i in items if i['keyName'] == item_keyname][0] except IndexError: raise exceptions.SoftLayerError( "Item {} does not exist for package {}".format(item_keyname, package_keyname)) # we want to get the price ID that has no location attached to it, # because that is the most generic price. verifyOrder/placeOrder # can take that ID and create the proper price for us in the location # in which the order is made item_category = matching_item['itemCategory']['categoryCode'] if item_category not in category_dict: price_id = self.get_item_price_id(core, matching_item['prices']) else: # GPU and PCIe items has two generic prices and they are added to the list # according to the number of items in the order. category_dict[item_category] += 1 category_code = item_category[:-1] + str(category_dict[item_category]) price_id = [p['id'] for p in matching_item['prices'] if not p['locationGroupId'] and p['categories'][0]['categoryCode'] == category_code][0] prices.append(price_id) return prices
[ "def", "get_price_id_list", "(", "self", ",", "package_keyname", ",", "item_keynames", ",", "core", "=", "None", ")", ":", "mask", "=", "'id, itemCategory, keyName, prices[categories]'", "items", "=", "self", ".", "list_items", "(", "package_keyname", ",", "mask", "=", "mask", ")", "prices", "=", "[", "]", "category_dict", "=", "{", "\"gpu0\"", ":", "-", "1", ",", "\"pcie_slot0\"", ":", "-", "1", "}", "for", "item_keyname", "in", "item_keynames", ":", "try", ":", "# Need to find the item in the package that has a matching", "# keyName with the current item we are searching for", "matching_item", "=", "[", "i", "for", "i", "in", "items", "if", "i", "[", "'keyName'", "]", "==", "item_keyname", "]", "[", "0", "]", "except", "IndexError", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "\"Item {} does not exist for package {}\"", ".", "format", "(", "item_keyname", ",", "package_keyname", ")", ")", "# we want to get the price ID that has no location attached to it,", "# because that is the most generic price. verifyOrder/placeOrder", "# can take that ID and create the proper price for us in the location", "# in which the order is made", "item_category", "=", "matching_item", "[", "'itemCategory'", "]", "[", "'categoryCode'", "]", "if", "item_category", "not", "in", "category_dict", ":", "price_id", "=", "self", ".", "get_item_price_id", "(", "core", ",", "matching_item", "[", "'prices'", "]", ")", "else", ":", "# GPU and PCIe items has two generic prices and they are added to the list", "# according to the number of items in the order.", "category_dict", "[", "item_category", "]", "+=", "1", "category_code", "=", "item_category", "[", ":", "-", "1", "]", "+", "str", "(", "category_dict", "[", "item_category", "]", ")", "price_id", "=", "[", "p", "[", "'id'", "]", "for", "p", "in", "matching_item", "[", "'prices'", "]", "if", "not", "p", "[", "'locationGroupId'", "]", "and", "p", "[", "'categories'", "]", "[", "0", "]", "[", "'categoryCode'", "]", "==", "category_code", "]", "[", "0", "]", "prices", ".", "append", "(", "price_id", ")", "return", "prices" ]
Converts a list of item keynames to a list of price IDs. This function is used to convert a list of item keynames into a list of price IDs that are used in the Product_Order verifyOrder() and placeOrder() functions. :param str package_keyname: The package associated with the prices :param list item_keynames: A list of item keyname strings :param str core: preset guest core capacity. :returns: A list of price IDs associated with the given item keynames in the given package
[ "Converts", "a", "list", "of", "item", "keynames", "to", "a", "list", "of", "price", "IDs", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L340-L389
train
234,432
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_item_price_id
def get_item_price_id(core, prices): """get item price id""" price_id = None for price in prices: if not price['locationGroupId']: capacity_min = int(price.get('capacityRestrictionMinimum', -1)) capacity_max = int(price.get('capacityRestrictionMaximum', -1)) # return first match if no restirction, or no core to check if capacity_min == -1 or core is None: price_id = price['id'] # this check is mostly to work nicely with preset configs elif capacity_min <= int(core) <= capacity_max: price_id = price['id'] return price_id
python
def get_item_price_id(core, prices): """get item price id""" price_id = None for price in prices: if not price['locationGroupId']: capacity_min = int(price.get('capacityRestrictionMinimum', -1)) capacity_max = int(price.get('capacityRestrictionMaximum', -1)) # return first match if no restirction, or no core to check if capacity_min == -1 or core is None: price_id = price['id'] # this check is mostly to work nicely with preset configs elif capacity_min <= int(core) <= capacity_max: price_id = price['id'] return price_id
[ "def", "get_item_price_id", "(", "core", ",", "prices", ")", ":", "price_id", "=", "None", "for", "price", "in", "prices", ":", "if", "not", "price", "[", "'locationGroupId'", "]", ":", "capacity_min", "=", "int", "(", "price", ".", "get", "(", "'capacityRestrictionMinimum'", ",", "-", "1", ")", ")", "capacity_max", "=", "int", "(", "price", ".", "get", "(", "'capacityRestrictionMaximum'", ",", "-", "1", ")", ")", "# return first match if no restirction, or no core to check", "if", "capacity_min", "==", "-", "1", "or", "core", "is", "None", ":", "price_id", "=", "price", "[", "'id'", "]", "# this check is mostly to work nicely with preset configs", "elif", "capacity_min", "<=", "int", "(", "core", ")", "<=", "capacity_max", ":", "price_id", "=", "price", "[", "'id'", "]", "return", "price_id" ]
get item price id
[ "get", "item", "price", "id" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L392-L405
train
234,433
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_preset_prices
def get_preset_prices(self, preset): """Get preset item prices. Retrieve a SoftLayer_Product_Package_Preset record. :param int preset: preset identifier. :returns: A list of price IDs associated with the given preset_id. """ mask = 'mask[prices[item]]' prices = self.package_preset.getObject(id=preset, mask=mask) return prices
python
def get_preset_prices(self, preset): """Get preset item prices. Retrieve a SoftLayer_Product_Package_Preset record. :param int preset: preset identifier. :returns: A list of price IDs associated with the given preset_id. """ mask = 'mask[prices[item]]' prices = self.package_preset.getObject(id=preset, mask=mask) return prices
[ "def", "get_preset_prices", "(", "self", ",", "preset", ")", ":", "mask", "=", "'mask[prices[item]]'", "prices", "=", "self", ".", "package_preset", ".", "getObject", "(", "id", "=", "preset", ",", "mask", "=", "mask", ")", "return", "prices" ]
Get preset item prices. Retrieve a SoftLayer_Product_Package_Preset record. :param int preset: preset identifier. :returns: A list of price IDs associated with the given preset_id.
[ "Get", "preset", "item", "prices", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L407-L419
train
234,434
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_item_prices
def get_item_prices(self, package_id): """Get item prices. Retrieve a SoftLayer_Product_Package item prices record. :param int package_id: package identifier. :returns: A list of price IDs associated with the given package. """ mask = 'mask[pricingLocationGroup[locations]]' prices = self.package_svc.getItemPrices(id=package_id, mask=mask) return prices
python
def get_item_prices(self, package_id): """Get item prices. Retrieve a SoftLayer_Product_Package item prices record. :param int package_id: package identifier. :returns: A list of price IDs associated with the given package. """ mask = 'mask[pricingLocationGroup[locations]]' prices = self.package_svc.getItemPrices(id=package_id, mask=mask) return prices
[ "def", "get_item_prices", "(", "self", ",", "package_id", ")", ":", "mask", "=", "'mask[pricingLocationGroup[locations]]'", "prices", "=", "self", ".", "package_svc", ".", "getItemPrices", "(", "id", "=", "package_id", ",", "mask", "=", "mask", ")", "return", "prices" ]
Get item prices. Retrieve a SoftLayer_Product_Package item prices record. :param int package_id: package identifier. :returns: A list of price IDs associated with the given package.
[ "Get", "item", "prices", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L421-L433
train
234,435
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.verify_order
def verify_order(self, package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1): """Verifies an order with the given package and prices. This function takes in parameters needed for an order and verifies the order to ensure the given items are compatible with the given package. :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param bool hourly: If true, uses hourly billing, otherwise uses monthly billing :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: 'virtualGuests': [{'hostname': 'test', 'domain': 'softlayer.com'}]} :param int quantity: The number of resources to order """ order = self.generate_order(package_keyname, location, item_keynames, complex_type=complex_type, hourly=hourly, preset_keyname=preset_keyname, extras=extras, quantity=quantity) return self.order_svc.verifyOrder(order)
python
def verify_order(self, package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1): """Verifies an order with the given package and prices. This function takes in parameters needed for an order and verifies the order to ensure the given items are compatible with the given package. :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param bool hourly: If true, uses hourly billing, otherwise uses monthly billing :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: 'virtualGuests': [{'hostname': 'test', 'domain': 'softlayer.com'}]} :param int quantity: The number of resources to order """ order = self.generate_order(package_keyname, location, item_keynames, complex_type=complex_type, hourly=hourly, preset_keyname=preset_keyname, extras=extras, quantity=quantity) return self.order_svc.verifyOrder(order)
[ "def", "verify_order", "(", "self", ",", "package_keyname", ",", "location", ",", "item_keynames", ",", "complex_type", "=", "None", ",", "hourly", "=", "True", ",", "preset_keyname", "=", "None", ",", "extras", "=", "None", ",", "quantity", "=", "1", ")", ":", "order", "=", "self", ".", "generate_order", "(", "package_keyname", ",", "location", ",", "item_keynames", ",", "complex_type", "=", "complex_type", ",", "hourly", "=", "hourly", ",", "preset_keyname", "=", "preset_keyname", ",", "extras", "=", "extras", ",", "quantity", "=", "quantity", ")", "return", "self", ".", "order_svc", ".", "verifyOrder", "(", "order", ")" ]
Verifies an order with the given package and prices. This function takes in parameters needed for an order and verifies the order to ensure the given items are compatible with the given package. :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param bool hourly: If true, uses hourly billing, otherwise uses monthly billing :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: 'virtualGuests': [{'hostname': 'test', 'domain': 'softlayer.com'}]} :param int quantity: The number of resources to order
[ "Verifies", "an", "order", "with", "the", "given", "package", "and", "prices", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L435-L464
train
234,436
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.place_order
def place_order(self, package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1): """Places an order with the given package and prices. This function takes in parameters needed for an order and places the order. :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param bool hourly: If true, uses hourly billing, otherwise uses monthly billing :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {'virtualGuests': [{'hostname': 'test', domain': 'softlayer.com'}]} :param int quantity: The number of resources to order """ order = self.generate_order(package_keyname, location, item_keynames, complex_type=complex_type, hourly=hourly, preset_keyname=preset_keyname, extras=extras, quantity=quantity) return self.order_svc.placeOrder(order)
python
def place_order(self, package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1): """Places an order with the given package and prices. This function takes in parameters needed for an order and places the order. :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param bool hourly: If true, uses hourly billing, otherwise uses monthly billing :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {'virtualGuests': [{'hostname': 'test', domain': 'softlayer.com'}]} :param int quantity: The number of resources to order """ order = self.generate_order(package_keyname, location, item_keynames, complex_type=complex_type, hourly=hourly, preset_keyname=preset_keyname, extras=extras, quantity=quantity) return self.order_svc.placeOrder(order)
[ "def", "place_order", "(", "self", ",", "package_keyname", ",", "location", ",", "item_keynames", ",", "complex_type", "=", "None", ",", "hourly", "=", "True", ",", "preset_keyname", "=", "None", ",", "extras", "=", "None", ",", "quantity", "=", "1", ")", ":", "order", "=", "self", ".", "generate_order", "(", "package_keyname", ",", "location", ",", "item_keynames", ",", "complex_type", "=", "complex_type", ",", "hourly", "=", "hourly", ",", "preset_keyname", "=", "preset_keyname", ",", "extras", "=", "extras", ",", "quantity", "=", "quantity", ")", "return", "self", ".", "order_svc", ".", "placeOrder", "(", "order", ")" ]
Places an order with the given package and prices. This function takes in parameters needed for an order and places the order. :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param bool hourly: If true, uses hourly billing, otherwise uses monthly billing :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {'virtualGuests': [{'hostname': 'test', domain': 'softlayer.com'}]} :param int quantity: The number of resources to order
[ "Places", "an", "order", "with", "the", "given", "package", "and", "prices", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L466-L494
train
234,437
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.place_quote
def place_quote(self, package_keyname, location, item_keynames, complex_type=None, preset_keyname=None, extras=None, quantity=1, quote_name=None, send_email=False): """Place a quote with the given package and prices. This function takes in parameters needed for an order and places the quote. :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {'virtualGuests': [{'hostname': 'test', domain': 'softlayer.com'}]} :param int quantity: The number of resources to order :param string quote_name: A custom name to be assigned to the quote (optional). :param bool send_email: This flag indicates that the quote should be sent to the email address associated with the account or order. """ order = self.generate_order(package_keyname, location, item_keynames, complex_type=complex_type, hourly=False, preset_keyname=preset_keyname, extras=extras, quantity=quantity) order['quoteName'] = quote_name order['sendQuoteEmailFlag'] = send_email return self.order_svc.placeQuote(order)
python
def place_quote(self, package_keyname, location, item_keynames, complex_type=None, preset_keyname=None, extras=None, quantity=1, quote_name=None, send_email=False): """Place a quote with the given package and prices. This function takes in parameters needed for an order and places the quote. :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {'virtualGuests': [{'hostname': 'test', domain': 'softlayer.com'}]} :param int quantity: The number of resources to order :param string quote_name: A custom name to be assigned to the quote (optional). :param bool send_email: This flag indicates that the quote should be sent to the email address associated with the account or order. """ order = self.generate_order(package_keyname, location, item_keynames, complex_type=complex_type, hourly=False, preset_keyname=preset_keyname, extras=extras, quantity=quantity) order['quoteName'] = quote_name order['sendQuoteEmailFlag'] = send_email return self.order_svc.placeQuote(order)
[ "def", "place_quote", "(", "self", ",", "package_keyname", ",", "location", ",", "item_keynames", ",", "complex_type", "=", "None", ",", "preset_keyname", "=", "None", ",", "extras", "=", "None", ",", "quantity", "=", "1", ",", "quote_name", "=", "None", ",", "send_email", "=", "False", ")", ":", "order", "=", "self", ".", "generate_order", "(", "package_keyname", ",", "location", ",", "item_keynames", ",", "complex_type", "=", "complex_type", ",", "hourly", "=", "False", ",", "preset_keyname", "=", "preset_keyname", ",", "extras", "=", "extras", ",", "quantity", "=", "quantity", ")", "order", "[", "'quoteName'", "]", "=", "quote_name", "order", "[", "'sendQuoteEmailFlag'", "]", "=", "send_email", "return", "self", ".", "order_svc", ".", "placeQuote", "(", "order", ")" ]
Place a quote with the given package and prices. This function takes in parameters needed for an order and places the quote. :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {'virtualGuests': [{'hostname': 'test', domain': 'softlayer.com'}]} :param int quantity: The number of resources to order :param string quote_name: A custom name to be assigned to the quote (optional). :param bool send_email: This flag indicates that the quote should be sent to the email address associated with the account or order.
[ "Place", "a", "quote", "with", "the", "given", "package", "and", "prices", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L496-L527
train
234,438
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.generate_order
def generate_order(self, package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1): """Generates an order with the given package and prices. This function takes in parameters needed for an order and generates an order dictionary. This dictionary can then be used in either verify or placeOrder(). :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param bool hourly: If true, uses hourly billing, otherwise uses monthly billing :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {'virtualGuests': [{'hostname': 'test', 'domain': 'softlayer.com'}]} :param int quantity: The number of resources to order """ container = {} order = {} extras = extras or {} package = self.get_package_by_key(package_keyname, mask='id') # if there was extra data given for the order, add it to the order # example: VSIs require hostname and domain set on the order, so # extras will be {'virtualGuests': [{'hostname': 'test', # 'domain': 'softlayer.com'}]} order.update(extras) order['packageId'] = package['id'] order['quantity'] = quantity order['location'] = self.get_location_id(location) order['useHourlyPricing'] = hourly preset_core = None if preset_keyname: preset_id = self.get_preset_by_key(package_keyname, preset_keyname)['id'] preset_items = self.get_preset_prices(preset_id) for item in preset_items['prices']: if item['item']['itemCategory']['categoryCode'] == "guest_core": preset_core = item['item']['capacity'] order['presetId'] = preset_id if not complex_type: raise exceptions.SoftLayerError("A complex type must be specified with the order") order['complexType'] = complex_type price_ids = self.get_price_id_list(package_keyname, item_keynames, preset_core) order['prices'] = [{'id': price_id} for price_id in price_ids] container['orderContainers'] = [order] return container
python
def generate_order(self, package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1): """Generates an order with the given package and prices. This function takes in parameters needed for an order and generates an order dictionary. This dictionary can then be used in either verify or placeOrder(). :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param bool hourly: If true, uses hourly billing, otherwise uses monthly billing :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {'virtualGuests': [{'hostname': 'test', 'domain': 'softlayer.com'}]} :param int quantity: The number of resources to order """ container = {} order = {} extras = extras or {} package = self.get_package_by_key(package_keyname, mask='id') # if there was extra data given for the order, add it to the order # example: VSIs require hostname and domain set on the order, so # extras will be {'virtualGuests': [{'hostname': 'test', # 'domain': 'softlayer.com'}]} order.update(extras) order['packageId'] = package['id'] order['quantity'] = quantity order['location'] = self.get_location_id(location) order['useHourlyPricing'] = hourly preset_core = None if preset_keyname: preset_id = self.get_preset_by_key(package_keyname, preset_keyname)['id'] preset_items = self.get_preset_prices(preset_id) for item in preset_items['prices']: if item['item']['itemCategory']['categoryCode'] == "guest_core": preset_core = item['item']['capacity'] order['presetId'] = preset_id if not complex_type: raise exceptions.SoftLayerError("A complex type must be specified with the order") order['complexType'] = complex_type price_ids = self.get_price_id_list(package_keyname, item_keynames, preset_core) order['prices'] = [{'id': price_id} for price_id in price_ids] container['orderContainers'] = [order] return container
[ "def", "generate_order", "(", "self", ",", "package_keyname", ",", "location", ",", "item_keynames", ",", "complex_type", "=", "None", ",", "hourly", "=", "True", ",", "preset_keyname", "=", "None", ",", "extras", "=", "None", ",", "quantity", "=", "1", ")", ":", "container", "=", "{", "}", "order", "=", "{", "}", "extras", "=", "extras", "or", "{", "}", "package", "=", "self", ".", "get_package_by_key", "(", "package_keyname", ",", "mask", "=", "'id'", ")", "# if there was extra data given for the order, add it to the order", "# example: VSIs require hostname and domain set on the order, so", "# extras will be {'virtualGuests': [{'hostname': 'test',", "# 'domain': 'softlayer.com'}]}", "order", ".", "update", "(", "extras", ")", "order", "[", "'packageId'", "]", "=", "package", "[", "'id'", "]", "order", "[", "'quantity'", "]", "=", "quantity", "order", "[", "'location'", "]", "=", "self", ".", "get_location_id", "(", "location", ")", "order", "[", "'useHourlyPricing'", "]", "=", "hourly", "preset_core", "=", "None", "if", "preset_keyname", ":", "preset_id", "=", "self", ".", "get_preset_by_key", "(", "package_keyname", ",", "preset_keyname", ")", "[", "'id'", "]", "preset_items", "=", "self", ".", "get_preset_prices", "(", "preset_id", ")", "for", "item", "in", "preset_items", "[", "'prices'", "]", ":", "if", "item", "[", "'item'", "]", "[", "'itemCategory'", "]", "[", "'categoryCode'", "]", "==", "\"guest_core\"", ":", "preset_core", "=", "item", "[", "'item'", "]", "[", "'capacity'", "]", "order", "[", "'presetId'", "]", "=", "preset_id", "if", "not", "complex_type", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "\"A complex type must be specified with the order\"", ")", "order", "[", "'complexType'", "]", "=", "complex_type", "price_ids", "=", "self", ".", "get_price_id_list", "(", "package_keyname", ",", "item_keynames", ",", "preset_core", ")", "order", "[", "'prices'", "]", "=", "[", "{", "'id'", ":", "price_id", "}", "for", "price_id", "in", "price_ids", "]", "container", "[", "'orderContainers'", "]", "=", "[", "order", "]", "return", "container" ]
Generates an order with the given package and prices. This function takes in parameters needed for an order and generates an order dictionary. This dictionary can then be used in either verify or placeOrder(). :param str package_keyname: The keyname for the package being ordered :param str location: The datacenter location string for ordering (Ex: DALLAS13) :param list item_keynames: The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or `slcli order item-list`) :param str complex_type: The complex type to send with the order. Typically begins with `SoftLayer_Container_Product_Order_`. :param bool hourly: If true, uses hourly billing, otherwise uses monthly billing :param string preset_keyname: If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or `slcli order preset-list`) :param dict extras: The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {'virtualGuests': [{'hostname': 'test', 'domain': 'softlayer.com'}]} :param int quantity: The number of resources to order
[ "Generates", "an", "order", "with", "the", "given", "package", "and", "prices", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L529-L588
train
234,439
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.package_locations
def package_locations(self, package_keyname): """List datacenter locations for a package keyname :param str package_keyname: The package for which to get the items. :returns: List of locations a package is orderable in """ mask = "mask[description, keyname, locations]" package = self.get_package_by_key(package_keyname, mask='id') regions = self.package_svc.getRegions(id=package['id'], mask=mask) return regions
python
def package_locations(self, package_keyname): """List datacenter locations for a package keyname :param str package_keyname: The package for which to get the items. :returns: List of locations a package is orderable in """ mask = "mask[description, keyname, locations]" package = self.get_package_by_key(package_keyname, mask='id') regions = self.package_svc.getRegions(id=package['id'], mask=mask) return regions
[ "def", "package_locations", "(", "self", ",", "package_keyname", ")", ":", "mask", "=", "\"mask[description, keyname, locations]\"", "package", "=", "self", ".", "get_package_by_key", "(", "package_keyname", ",", "mask", "=", "'id'", ")", "regions", "=", "self", ".", "package_svc", ".", "getRegions", "(", "id", "=", "package", "[", "'id'", "]", ",", "mask", "=", "mask", ")", "return", "regions" ]
List datacenter locations for a package keyname :param str package_keyname: The package for which to get the items. :returns: List of locations a package is orderable in
[ "List", "datacenter", "locations", "for", "a", "package", "keyname" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L590-L601
train
234,440
softlayer/softlayer-python
SoftLayer/managers/ordering.py
OrderingManager.get_location_id
def get_location_id(self, location): """Finds the location ID of a given datacenter This is mostly used so either a dc name, or regions keyname can be used when ordering :param str location: Region Keyname (DALLAS13) or datacenter name (dal13) :returns: integer id of the datacenter """ if isinstance(location, int): return location mask = "mask[id,name,regions[keyname]]" if match(r'[a-zA-Z]{3}[0-9]{2}', location) is not None: search = {'name': {'operation': location}} else: search = {'regions': {'keyname': {'operation': location}}} datacenter = self.client.call('SoftLayer_Location', 'getDatacenters', mask=mask, filter=search) if len(datacenter) != 1: raise exceptions.SoftLayerError("Unable to find location: %s" % location) return datacenter[0]['id']
python
def get_location_id(self, location): """Finds the location ID of a given datacenter This is mostly used so either a dc name, or regions keyname can be used when ordering :param str location: Region Keyname (DALLAS13) or datacenter name (dal13) :returns: integer id of the datacenter """ if isinstance(location, int): return location mask = "mask[id,name,regions[keyname]]" if match(r'[a-zA-Z]{3}[0-9]{2}', location) is not None: search = {'name': {'operation': location}} else: search = {'regions': {'keyname': {'operation': location}}} datacenter = self.client.call('SoftLayer_Location', 'getDatacenters', mask=mask, filter=search) if len(datacenter) != 1: raise exceptions.SoftLayerError("Unable to find location: %s" % location) return datacenter[0]['id']
[ "def", "get_location_id", "(", "self", ",", "location", ")", ":", "if", "isinstance", "(", "location", ",", "int", ")", ":", "return", "location", "mask", "=", "\"mask[id,name,regions[keyname]]\"", "if", "match", "(", "r'[a-zA-Z]{3}[0-9]{2}'", ",", "location", ")", "is", "not", "None", ":", "search", "=", "{", "'name'", ":", "{", "'operation'", ":", "location", "}", "}", "else", ":", "search", "=", "{", "'regions'", ":", "{", "'keyname'", ":", "{", "'operation'", ":", "location", "}", "}", "}", "datacenter", "=", "self", ".", "client", ".", "call", "(", "'SoftLayer_Location'", ",", "'getDatacenters'", ",", "mask", "=", "mask", ",", "filter", "=", "search", ")", "if", "len", "(", "datacenter", ")", "!=", "1", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "\"Unable to find location: %s\"", "%", "location", ")", "return", "datacenter", "[", "0", "]", "[", "'id'", "]" ]
Finds the location ID of a given datacenter This is mostly used so either a dc name, or regions keyname can be used when ordering :param str location: Region Keyname (DALLAS13) or datacenter name (dal13) :returns: integer id of the datacenter
[ "Finds", "the", "location", "ID", "of", "a", "given", "datacenter" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ordering.py#L603-L621
train
234,441
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.add_global_ip
def add_global_ip(self, version=4, test_order=False): """Adds a global IP address to the account. :param int version: Specifies whether this is IPv4 or IPv6 :param bool test_order: If true, this will only verify the order. """ # This method is here to improve the public interface from a user's # perspective since ordering a single global IP through the subnet # interface is not intuitive. return self.add_subnet('global', version=version, test_order=test_order)
python
def add_global_ip(self, version=4, test_order=False): """Adds a global IP address to the account. :param int version: Specifies whether this is IPv4 or IPv6 :param bool test_order: If true, this will only verify the order. """ # This method is here to improve the public interface from a user's # perspective since ordering a single global IP through the subnet # interface is not intuitive. return self.add_subnet('global', version=version, test_order=test_order)
[ "def", "add_global_ip", "(", "self", ",", "version", "=", "4", ",", "test_order", "=", "False", ")", ":", "# This method is here to improve the public interface from a user's", "# perspective since ordering a single global IP through the subnet", "# interface is not intuitive.", "return", "self", ".", "add_subnet", "(", "'global'", ",", "version", "=", "version", ",", "test_order", "=", "test_order", ")" ]
Adds a global IP address to the account. :param int version: Specifies whether this is IPv4 or IPv6 :param bool test_order: If true, this will only verify the order.
[ "Adds", "a", "global", "IP", "address", "to", "the", "account", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L58-L68
train
234,442
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.add_securitygroup_rule
def add_securitygroup_rule(self, group_id, remote_ip=None, remote_group=None, direction=None, ethertype=None, port_max=None, port_min=None, protocol=None): """Add a rule to a security group :param int group_id: The ID of the security group to add this rule to :param str remote_ip: The remote IP or CIDR to enforce the rule on :param int remote_group: The remote security group ID to enforce the rule on :param str direction: The direction to enforce (egress or ingress) :param str ethertype: The ethertype to enforce (IPv4 or IPv6) :param int port_max: The upper port bound to enforce (icmp code if the protocol is icmp) :param int port_min: The lower port bound to enforce (icmp type if the protocol is icmp) :param str protocol: The protocol to enforce (icmp, udp, tcp) """ rule = {'direction': direction} if ethertype is not None: rule['ethertype'] = ethertype if port_max is not None: rule['portRangeMax'] = port_max if port_min is not None: rule['portRangeMin'] = port_min if protocol is not None: rule['protocol'] = protocol if remote_ip is not None: rule['remoteIp'] = remote_ip if remote_group is not None: rule['remoteGroupId'] = remote_group return self.add_securitygroup_rules(group_id, [rule])
python
def add_securitygroup_rule(self, group_id, remote_ip=None, remote_group=None, direction=None, ethertype=None, port_max=None, port_min=None, protocol=None): """Add a rule to a security group :param int group_id: The ID of the security group to add this rule to :param str remote_ip: The remote IP or CIDR to enforce the rule on :param int remote_group: The remote security group ID to enforce the rule on :param str direction: The direction to enforce (egress or ingress) :param str ethertype: The ethertype to enforce (IPv4 or IPv6) :param int port_max: The upper port bound to enforce (icmp code if the protocol is icmp) :param int port_min: The lower port bound to enforce (icmp type if the protocol is icmp) :param str protocol: The protocol to enforce (icmp, udp, tcp) """ rule = {'direction': direction} if ethertype is not None: rule['ethertype'] = ethertype if port_max is not None: rule['portRangeMax'] = port_max if port_min is not None: rule['portRangeMin'] = port_min if protocol is not None: rule['protocol'] = protocol if remote_ip is not None: rule['remoteIp'] = remote_ip if remote_group is not None: rule['remoteGroupId'] = remote_group return self.add_securitygroup_rules(group_id, [rule])
[ "def", "add_securitygroup_rule", "(", "self", ",", "group_id", ",", "remote_ip", "=", "None", ",", "remote_group", "=", "None", ",", "direction", "=", "None", ",", "ethertype", "=", "None", ",", "port_max", "=", "None", ",", "port_min", "=", "None", ",", "protocol", "=", "None", ")", ":", "rule", "=", "{", "'direction'", ":", "direction", "}", "if", "ethertype", "is", "not", "None", ":", "rule", "[", "'ethertype'", "]", "=", "ethertype", "if", "port_max", "is", "not", "None", ":", "rule", "[", "'portRangeMax'", "]", "=", "port_max", "if", "port_min", "is", "not", "None", ":", "rule", "[", "'portRangeMin'", "]", "=", "port_min", "if", "protocol", "is", "not", "None", ":", "rule", "[", "'protocol'", "]", "=", "protocol", "if", "remote_ip", "is", "not", "None", ":", "rule", "[", "'remoteIp'", "]", "=", "remote_ip", "if", "remote_group", "is", "not", "None", ":", "rule", "[", "'remoteGroupId'", "]", "=", "remote_group", "return", "self", ".", "add_securitygroup_rules", "(", "group_id", ",", "[", "rule", "]", ")" ]
Add a rule to a security group :param int group_id: The ID of the security group to add this rule to :param str remote_ip: The remote IP or CIDR to enforce the rule on :param int remote_group: The remote security group ID to enforce the rule on :param str direction: The direction to enforce (egress or ingress) :param str ethertype: The ethertype to enforce (IPv4 or IPv6) :param int port_max: The upper port bound to enforce (icmp code if the protocol is icmp) :param int port_min: The lower port bound to enforce (icmp type if the protocol is icmp) :param str protocol: The protocol to enforce (icmp, udp, tcp)
[ "Add", "a", "rule", "to", "a", "security", "group" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L70-L101
train
234,443
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.add_securitygroup_rules
def add_securitygroup_rules(self, group_id, rules): """Add rules to a security group :param int group_id: The ID of the security group to add the rules to :param list rules: The list of rule dictionaries to add """ if not isinstance(rules, list): raise TypeError("The rules provided must be a list of dictionaries") return self.security_group.addRules(rules, id=group_id)
python
def add_securitygroup_rules(self, group_id, rules): """Add rules to a security group :param int group_id: The ID of the security group to add the rules to :param list rules: The list of rule dictionaries to add """ if not isinstance(rules, list): raise TypeError("The rules provided must be a list of dictionaries") return self.security_group.addRules(rules, id=group_id)
[ "def", "add_securitygroup_rules", "(", "self", ",", "group_id", ",", "rules", ")", ":", "if", "not", "isinstance", "(", "rules", ",", "list", ")", ":", "raise", "TypeError", "(", "\"The rules provided must be a list of dictionaries\"", ")", "return", "self", ".", "security_group", ".", "addRules", "(", "rules", ",", "id", "=", "group_id", ")" ]
Add rules to a security group :param int group_id: The ID of the security group to add the rules to :param list rules: The list of rule dictionaries to add
[ "Add", "rules", "to", "a", "security", "group" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L103-L111
train
234,444
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.add_subnet
def add_subnet(self, subnet_type, quantity=None, vlan_id=None, version=4, test_order=False): """Orders a new subnet :param str subnet_type: Type of subnet to add: private, public, global :param int quantity: Number of IPs in the subnet :param int vlan_id: VLAN id for the subnet to be placed into :param int version: 4 for IPv4, 6 for IPv6 :param bool test_order: If true, this will only verify the order. """ package = self.client['Product_Package'] category = 'sov_sec_ip_addresses_priv' desc = '' if version == 4: if subnet_type == 'global': quantity = 0 category = 'global_ipv4' elif subnet_type == 'public': category = 'sov_sec_ip_addresses_pub' else: category = 'static_ipv6_addresses' if subnet_type == 'global': quantity = 0 category = 'global_ipv6' desc = 'Global' elif subnet_type == 'public': desc = 'Portable' # In the API, every non-server item is contained within package ID 0. # This means that we need to get all of the items and loop through them # looking for the items we need based upon the category, quantity, and # item description. price_id = None quantity_str = str(quantity) for item in package.getItems(id=0, mask='itemCategory'): category_code = utils.lookup(item, 'itemCategory', 'categoryCode') if all([category_code == category, item.get('capacity') == quantity_str, version == 4 or (version == 6 and desc in item['description'])]): price_id = item['prices'][0]['id'] break order = { 'packageId': 0, 'prices': [{'id': price_id}], 'quantity': 1, # This is necessary in order for the XML-RPC endpoint to select the # correct order container 'complexType': 'SoftLayer_Container_Product_Order_Network_Subnet', } if subnet_type != 'global': order['endPointVlanId'] = vlan_id if test_order: return self.client['Product_Order'].verifyOrder(order) else: return self.client['Product_Order'].placeOrder(order)
python
def add_subnet(self, subnet_type, quantity=None, vlan_id=None, version=4, test_order=False): """Orders a new subnet :param str subnet_type: Type of subnet to add: private, public, global :param int quantity: Number of IPs in the subnet :param int vlan_id: VLAN id for the subnet to be placed into :param int version: 4 for IPv4, 6 for IPv6 :param bool test_order: If true, this will only verify the order. """ package = self.client['Product_Package'] category = 'sov_sec_ip_addresses_priv' desc = '' if version == 4: if subnet_type == 'global': quantity = 0 category = 'global_ipv4' elif subnet_type == 'public': category = 'sov_sec_ip_addresses_pub' else: category = 'static_ipv6_addresses' if subnet_type == 'global': quantity = 0 category = 'global_ipv6' desc = 'Global' elif subnet_type == 'public': desc = 'Portable' # In the API, every non-server item is contained within package ID 0. # This means that we need to get all of the items and loop through them # looking for the items we need based upon the category, quantity, and # item description. price_id = None quantity_str = str(quantity) for item in package.getItems(id=0, mask='itemCategory'): category_code = utils.lookup(item, 'itemCategory', 'categoryCode') if all([category_code == category, item.get('capacity') == quantity_str, version == 4 or (version == 6 and desc in item['description'])]): price_id = item['prices'][0]['id'] break order = { 'packageId': 0, 'prices': [{'id': price_id}], 'quantity': 1, # This is necessary in order for the XML-RPC endpoint to select the # correct order container 'complexType': 'SoftLayer_Container_Product_Order_Network_Subnet', } if subnet_type != 'global': order['endPointVlanId'] = vlan_id if test_order: return self.client['Product_Order'].verifyOrder(order) else: return self.client['Product_Order'].placeOrder(order)
[ "def", "add_subnet", "(", "self", ",", "subnet_type", ",", "quantity", "=", "None", ",", "vlan_id", "=", "None", ",", "version", "=", "4", ",", "test_order", "=", "False", ")", ":", "package", "=", "self", ".", "client", "[", "'Product_Package'", "]", "category", "=", "'sov_sec_ip_addresses_priv'", "desc", "=", "''", "if", "version", "==", "4", ":", "if", "subnet_type", "==", "'global'", ":", "quantity", "=", "0", "category", "=", "'global_ipv4'", "elif", "subnet_type", "==", "'public'", ":", "category", "=", "'sov_sec_ip_addresses_pub'", "else", ":", "category", "=", "'static_ipv6_addresses'", "if", "subnet_type", "==", "'global'", ":", "quantity", "=", "0", "category", "=", "'global_ipv6'", "desc", "=", "'Global'", "elif", "subnet_type", "==", "'public'", ":", "desc", "=", "'Portable'", "# In the API, every non-server item is contained within package ID 0.", "# This means that we need to get all of the items and loop through them", "# looking for the items we need based upon the category, quantity, and", "# item description.", "price_id", "=", "None", "quantity_str", "=", "str", "(", "quantity", ")", "for", "item", "in", "package", ".", "getItems", "(", "id", "=", "0", ",", "mask", "=", "'itemCategory'", ")", ":", "category_code", "=", "utils", ".", "lookup", "(", "item", ",", "'itemCategory'", ",", "'categoryCode'", ")", "if", "all", "(", "[", "category_code", "==", "category", ",", "item", ".", "get", "(", "'capacity'", ")", "==", "quantity_str", ",", "version", "==", "4", "or", "(", "version", "==", "6", "and", "desc", "in", "item", "[", "'description'", "]", ")", "]", ")", ":", "price_id", "=", "item", "[", "'prices'", "]", "[", "0", "]", "[", "'id'", "]", "break", "order", "=", "{", "'packageId'", ":", "0", ",", "'prices'", ":", "[", "{", "'id'", ":", "price_id", "}", "]", ",", "'quantity'", ":", "1", ",", "# This is necessary in order for the XML-RPC endpoint to select the", "# correct order container", "'complexType'", ":", "'SoftLayer_Container_Product_Order_Network_Subnet'", ",", "}", "if", "subnet_type", "!=", "'global'", ":", "order", "[", "'endPointVlanId'", "]", "=", "vlan_id", "if", "test_order", ":", "return", "self", ".", "client", "[", "'Product_Order'", "]", ".", "verifyOrder", "(", "order", ")", "else", ":", "return", "self", ".", "client", "[", "'Product_Order'", "]", ".", "placeOrder", "(", "order", ")" ]
Orders a new subnet :param str subnet_type: Type of subnet to add: private, public, global :param int quantity: Number of IPs in the subnet :param int vlan_id: VLAN id for the subnet to be placed into :param int version: 4 for IPv4, 6 for IPv6 :param bool test_order: If true, this will only verify the order.
[ "Orders", "a", "new", "subnet" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L113-L171
train
234,445
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.assign_global_ip
def assign_global_ip(self, global_ip_id, target): """Assigns a global IP address to a specified target. :param int global_ip_id: The ID of the global IP being assigned :param string target: The IP address to assign """ return self.client['Network_Subnet_IpAddress_Global'].route( target, id=global_ip_id)
python
def assign_global_ip(self, global_ip_id, target): """Assigns a global IP address to a specified target. :param int global_ip_id: The ID of the global IP being assigned :param string target: The IP address to assign """ return self.client['Network_Subnet_IpAddress_Global'].route( target, id=global_ip_id)
[ "def", "assign_global_ip", "(", "self", ",", "global_ip_id", ",", "target", ")", ":", "return", "self", ".", "client", "[", "'Network_Subnet_IpAddress_Global'", "]", ".", "route", "(", "target", ",", "id", "=", "global_ip_id", ")" ]
Assigns a global IP address to a specified target. :param int global_ip_id: The ID of the global IP being assigned :param string target: The IP address to assign
[ "Assigns", "a", "global", "IP", "address", "to", "a", "specified", "target", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L173-L180
train
234,446
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.attach_securitygroup_components
def attach_securitygroup_components(self, group_id, component_ids): """Attaches network components to a security group. :param int group_id: The ID of the security group :param list component_ids: The IDs of the network components to attach """ return self.security_group.attachNetworkComponents(component_ids, id=group_id)
python
def attach_securitygroup_components(self, group_id, component_ids): """Attaches network components to a security group. :param int group_id: The ID of the security group :param list component_ids: The IDs of the network components to attach """ return self.security_group.attachNetworkComponents(component_ids, id=group_id)
[ "def", "attach_securitygroup_components", "(", "self", ",", "group_id", ",", "component_ids", ")", ":", "return", "self", ".", "security_group", ".", "attachNetworkComponents", "(", "component_ids", ",", "id", "=", "group_id", ")" ]
Attaches network components to a security group. :param int group_id: The ID of the security group :param list component_ids: The IDs of the network components to attach
[ "Attaches", "network", "components", "to", "a", "security", "group", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L191-L198
train
234,447
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.cancel_global_ip
def cancel_global_ip(self, global_ip_id): """Cancels the specified global IP address. :param int id: The ID of the global IP to be cancelled. """ service = self.client['Network_Subnet_IpAddress_Global'] ip_address = service.getObject(id=global_ip_id, mask='billingItem') billing_id = ip_address['billingItem']['id'] return self.client['Billing_Item'].cancelService(id=billing_id)
python
def cancel_global_ip(self, global_ip_id): """Cancels the specified global IP address. :param int id: The ID of the global IP to be cancelled. """ service = self.client['Network_Subnet_IpAddress_Global'] ip_address = service.getObject(id=global_ip_id, mask='billingItem') billing_id = ip_address['billingItem']['id'] return self.client['Billing_Item'].cancelService(id=billing_id)
[ "def", "cancel_global_ip", "(", "self", ",", "global_ip_id", ")", ":", "service", "=", "self", ".", "client", "[", "'Network_Subnet_IpAddress_Global'", "]", "ip_address", "=", "service", ".", "getObject", "(", "id", "=", "global_ip_id", ",", "mask", "=", "'billingItem'", ")", "billing_id", "=", "ip_address", "[", "'billingItem'", "]", "[", "'id'", "]", "return", "self", ".", "client", "[", "'Billing_Item'", "]", ".", "cancelService", "(", "id", "=", "billing_id", ")" ]
Cancels the specified global IP address. :param int id: The ID of the global IP to be cancelled.
[ "Cancels", "the", "specified", "global", "IP", "address", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L200-L209
train
234,448
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.cancel_subnet
def cancel_subnet(self, subnet_id): """Cancels the specified subnet. :param int subnet_id: The ID of the subnet to be cancelled. """ subnet = self.get_subnet(subnet_id, mask='id, billingItem.id') if "billingItem" not in subnet: raise exceptions.SoftLayerError("subnet %s can not be cancelled" " " % subnet_id) billing_id = subnet['billingItem']['id'] return self.client['Billing_Item'].cancelService(id=billing_id)
python
def cancel_subnet(self, subnet_id): """Cancels the specified subnet. :param int subnet_id: The ID of the subnet to be cancelled. """ subnet = self.get_subnet(subnet_id, mask='id, billingItem.id') if "billingItem" not in subnet: raise exceptions.SoftLayerError("subnet %s can not be cancelled" " " % subnet_id) billing_id = subnet['billingItem']['id'] return self.client['Billing_Item'].cancelService(id=billing_id)
[ "def", "cancel_subnet", "(", "self", ",", "subnet_id", ")", ":", "subnet", "=", "self", ".", "get_subnet", "(", "subnet_id", ",", "mask", "=", "'id, billingItem.id'", ")", "if", "\"billingItem\"", "not", "in", "subnet", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "\"subnet %s can not be cancelled\"", "\" \"", "%", "subnet_id", ")", "billing_id", "=", "subnet", "[", "'billingItem'", "]", "[", "'id'", "]", "return", "self", ".", "client", "[", "'Billing_Item'", "]", ".", "cancelService", "(", "id", "=", "billing_id", ")" ]
Cancels the specified subnet. :param int subnet_id: The ID of the subnet to be cancelled.
[ "Cancels", "the", "specified", "subnet", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L211-L221
train
234,449
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.create_securitygroup
def create_securitygroup(self, name=None, description=None): """Creates a security group. :param string name: The name of the security group :param string description: The description of the security group """ create_dict = {'name': name, 'description': description} return self.security_group.createObject(create_dict)
python
def create_securitygroup(self, name=None, description=None): """Creates a security group. :param string name: The name of the security group :param string description: The description of the security group """ create_dict = {'name': name, 'description': description} return self.security_group.createObject(create_dict)
[ "def", "create_securitygroup", "(", "self", ",", "name", "=", "None", ",", "description", "=", "None", ")", ":", "create_dict", "=", "{", "'name'", ":", "name", ",", "'description'", ":", "description", "}", "return", "self", ".", "security_group", ".", "createObject", "(", "create_dict", ")" ]
Creates a security group. :param string name: The name of the security group :param string description: The description of the security group
[ "Creates", "a", "security", "group", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L223-L231
train
234,450
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.detach_securitygroup_components
def detach_securitygroup_components(self, group_id, component_ids): """Detaches network components from a security group. :param int group_id: The ID of the security group :param list component_ids: The IDs of the network components to detach """ return self.security_group.detachNetworkComponents(component_ids, id=group_id)
python
def detach_securitygroup_components(self, group_id, component_ids): """Detaches network components from a security group. :param int group_id: The ID of the security group :param list component_ids: The IDs of the network components to detach """ return self.security_group.detachNetworkComponents(component_ids, id=group_id)
[ "def", "detach_securitygroup_components", "(", "self", ",", "group_id", ",", "component_ids", ")", ":", "return", "self", ".", "security_group", ".", "detachNetworkComponents", "(", "component_ids", ",", "id", "=", "group_id", ")" ]
Detaches network components from a security group. :param int group_id: The ID of the security group :param list component_ids: The IDs of the network components to detach
[ "Detaches", "network", "components", "from", "a", "security", "group", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L248-L255
train
234,451
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.edit_rwhois
def edit_rwhois(self, abuse_email=None, address1=None, address2=None, city=None, company_name=None, country=None, first_name=None, last_name=None, postal_code=None, private_residence=None, state=None): """Edit rwhois record.""" update = {} for key, value in [('abuseEmail', abuse_email), ('address1', address1), ('address2', address2), ('city', city), ('companyName', company_name), ('country', country), ('firstName', first_name), ('lastName', last_name), ('privateResidenceFlag', private_residence), ('state', state), ('postalCode', postal_code)]: if value is not None: update[key] = value # If there's anything to update, update it if update: rwhois = self.get_rwhois() return self.client['Network_Subnet_Rwhois_Data'].editObject( update, id=rwhois['id']) return True
python
def edit_rwhois(self, abuse_email=None, address1=None, address2=None, city=None, company_name=None, country=None, first_name=None, last_name=None, postal_code=None, private_residence=None, state=None): """Edit rwhois record.""" update = {} for key, value in [('abuseEmail', abuse_email), ('address1', address1), ('address2', address2), ('city', city), ('companyName', company_name), ('country', country), ('firstName', first_name), ('lastName', last_name), ('privateResidenceFlag', private_residence), ('state', state), ('postalCode', postal_code)]: if value is not None: update[key] = value # If there's anything to update, update it if update: rwhois = self.get_rwhois() return self.client['Network_Subnet_Rwhois_Data'].editObject( update, id=rwhois['id']) return True
[ "def", "edit_rwhois", "(", "self", ",", "abuse_email", "=", "None", ",", "address1", "=", "None", ",", "address2", "=", "None", ",", "city", "=", "None", ",", "company_name", "=", "None", ",", "country", "=", "None", ",", "first_name", "=", "None", ",", "last_name", "=", "None", ",", "postal_code", "=", "None", ",", "private_residence", "=", "None", ",", "state", "=", "None", ")", ":", "update", "=", "{", "}", "for", "key", ",", "value", "in", "[", "(", "'abuseEmail'", ",", "abuse_email", ")", ",", "(", "'address1'", ",", "address1", ")", ",", "(", "'address2'", ",", "address2", ")", ",", "(", "'city'", ",", "city", ")", ",", "(", "'companyName'", ",", "company_name", ")", ",", "(", "'country'", ",", "country", ")", ",", "(", "'firstName'", ",", "first_name", ")", ",", "(", "'lastName'", ",", "last_name", ")", ",", "(", "'privateResidenceFlag'", ",", "private_residence", ")", ",", "(", "'state'", ",", "state", ")", ",", "(", "'postalCode'", ",", "postal_code", ")", "]", ":", "if", "value", "is", "not", "None", ":", "update", "[", "key", "]", "=", "value", "# If there's anything to update, update it", "if", "update", ":", "rwhois", "=", "self", ".", "get_rwhois", "(", ")", "return", "self", ".", "client", "[", "'Network_Subnet_Rwhois_Data'", "]", ".", "editObject", "(", "update", ",", "id", "=", "rwhois", "[", "'id'", "]", ")", "return", "True" ]
Edit rwhois record.
[ "Edit", "rwhois", "record", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L257-L283
train
234,452
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.edit_securitygroup
def edit_securitygroup(self, group_id, name=None, description=None): """Edit security group details. :param int group_id: The ID of the security group :param string name: The name of the security group :param string description: The description of the security group """ successful = False obj = {} if name: obj['name'] = name if description: obj['description'] = description if obj: successful = self.security_group.editObject(obj, id=group_id) return successful
python
def edit_securitygroup(self, group_id, name=None, description=None): """Edit security group details. :param int group_id: The ID of the security group :param string name: The name of the security group :param string description: The description of the security group """ successful = False obj = {} if name: obj['name'] = name if description: obj['description'] = description if obj: successful = self.security_group.editObject(obj, id=group_id) return successful
[ "def", "edit_securitygroup", "(", "self", ",", "group_id", ",", "name", "=", "None", ",", "description", "=", "None", ")", ":", "successful", "=", "False", "obj", "=", "{", "}", "if", "name", ":", "obj", "[", "'name'", "]", "=", "name", "if", "description", ":", "obj", "[", "'description'", "]", "=", "description", "if", "obj", ":", "successful", "=", "self", ".", "security_group", ".", "editObject", "(", "obj", ",", "id", "=", "group_id", ")", "return", "successful" ]
Edit security group details. :param int group_id: The ID of the security group :param string name: The name of the security group :param string description: The description of the security group
[ "Edit", "security", "group", "details", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L285-L302
train
234,453
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.edit_securitygroup_rule
def edit_securitygroup_rule(self, group_id, rule_id, remote_ip=None, remote_group=None, direction=None, ethertype=None, port_max=None, port_min=None, protocol=None): """Edit a security group rule. :param int group_id: The ID of the security group the rule belongs to :param int rule_id: The ID of the rule to edit :param str remote_ip: The remote IP or CIDR to enforce the rule on :param int remote_group: The remote security group ID to enforce the rule on :param str direction: The direction to enforce (egress or ingress) :param str ethertype: The ethertype to enforce (IPv4 or IPv6) :param str port_max: The upper port bound to enforce :param str port_min: The lower port bound to enforce :param str protocol: The protocol to enforce (icmp, udp, tcp) """ successful = False obj = {} if remote_ip is not None: obj['remoteIp'] = remote_ip if remote_group is not None: obj['remoteGroupId'] = remote_group if direction is not None: obj['direction'] = direction if ethertype is not None: obj['ethertype'] = ethertype if port_max is not None: obj['portRangeMax'] = port_max if port_min is not None: obj['portRangeMin'] = port_min if protocol is not None: obj['protocol'] = protocol if obj: obj['id'] = rule_id successful = self.security_group.editRules([obj], id=group_id) return successful
python
def edit_securitygroup_rule(self, group_id, rule_id, remote_ip=None, remote_group=None, direction=None, ethertype=None, port_max=None, port_min=None, protocol=None): """Edit a security group rule. :param int group_id: The ID of the security group the rule belongs to :param int rule_id: The ID of the rule to edit :param str remote_ip: The remote IP or CIDR to enforce the rule on :param int remote_group: The remote security group ID to enforce the rule on :param str direction: The direction to enforce (egress or ingress) :param str ethertype: The ethertype to enforce (IPv4 or IPv6) :param str port_max: The upper port bound to enforce :param str port_min: The lower port bound to enforce :param str protocol: The protocol to enforce (icmp, udp, tcp) """ successful = False obj = {} if remote_ip is not None: obj['remoteIp'] = remote_ip if remote_group is not None: obj['remoteGroupId'] = remote_group if direction is not None: obj['direction'] = direction if ethertype is not None: obj['ethertype'] = ethertype if port_max is not None: obj['portRangeMax'] = port_max if port_min is not None: obj['portRangeMin'] = port_min if protocol is not None: obj['protocol'] = protocol if obj: obj['id'] = rule_id successful = self.security_group.editRules([obj], id=group_id) return successful
[ "def", "edit_securitygroup_rule", "(", "self", ",", "group_id", ",", "rule_id", ",", "remote_ip", "=", "None", ",", "remote_group", "=", "None", ",", "direction", "=", "None", ",", "ethertype", "=", "None", ",", "port_max", "=", "None", ",", "port_min", "=", "None", ",", "protocol", "=", "None", ")", ":", "successful", "=", "False", "obj", "=", "{", "}", "if", "remote_ip", "is", "not", "None", ":", "obj", "[", "'remoteIp'", "]", "=", "remote_ip", "if", "remote_group", "is", "not", "None", ":", "obj", "[", "'remoteGroupId'", "]", "=", "remote_group", "if", "direction", "is", "not", "None", ":", "obj", "[", "'direction'", "]", "=", "direction", "if", "ethertype", "is", "not", "None", ":", "obj", "[", "'ethertype'", "]", "=", "ethertype", "if", "port_max", "is", "not", "None", ":", "obj", "[", "'portRangeMax'", "]", "=", "port_max", "if", "port_min", "is", "not", "None", ":", "obj", "[", "'portRangeMin'", "]", "=", "port_min", "if", "protocol", "is", "not", "None", ":", "obj", "[", "'protocol'", "]", "=", "protocol", "if", "obj", ":", "obj", "[", "'id'", "]", "=", "rule_id", "successful", "=", "self", ".", "security_group", ".", "editRules", "(", "[", "obj", "]", ",", "id", "=", "group_id", ")", "return", "successful" ]
Edit a security group rule. :param int group_id: The ID of the security group the rule belongs to :param int rule_id: The ID of the rule to edit :param str remote_ip: The remote IP or CIDR to enforce the rule on :param int remote_group: The remote security group ID to enforce the rule on :param str direction: The direction to enforce (egress or ingress) :param str ethertype: The ethertype to enforce (IPv4 or IPv6) :param str port_max: The upper port bound to enforce :param str port_min: The lower port bound to enforce :param str protocol: The protocol to enforce (icmp, udp, tcp)
[ "Edit", "a", "security", "group", "rule", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L304-L342
train
234,454
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.ip_lookup
def ip_lookup(self, ip_address): """Looks up an IP address and returns network information about it. :param string ip_address: An IP address. Can be IPv4 or IPv6 :returns: A dictionary of information about the IP """ obj = self.client['Network_Subnet_IpAddress'] return obj.getByIpAddress(ip_address, mask='hardware, virtualGuest')
python
def ip_lookup(self, ip_address): """Looks up an IP address and returns network information about it. :param string ip_address: An IP address. Can be IPv4 or IPv6 :returns: A dictionary of information about the IP """ obj = self.client['Network_Subnet_IpAddress'] return obj.getByIpAddress(ip_address, mask='hardware, virtualGuest')
[ "def", "ip_lookup", "(", "self", ",", "ip_address", ")", ":", "obj", "=", "self", ".", "client", "[", "'Network_Subnet_IpAddress'", "]", "return", "obj", ".", "getByIpAddress", "(", "ip_address", ",", "mask", "=", "'hardware, virtualGuest'", ")" ]
Looks up an IP address and returns network information about it. :param string ip_address: An IP address. Can be IPv4 or IPv6 :returns: A dictionary of information about the IP
[ "Looks", "up", "an", "IP", "address", "and", "returns", "network", "information", "about", "it", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L344-L352
train
234,455
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.get_securitygroup
def get_securitygroup(self, group_id, **kwargs): """Returns the information about the given security group. :param string id: The ID for the security group :returns: A diction of information about the security group """ if 'mask' not in kwargs: kwargs['mask'] = ( 'id,' 'name,' 'description,' '''rules[id, remoteIp, remoteGroupId, direction, ethertype, portRangeMin, portRangeMax, protocol, createDate, modifyDate],''' '''networkComponentBindings[ networkComponent[ id, port, guest[ id, hostname, primaryBackendIpAddress, primaryIpAddress ] ] ]''' ) return self.security_group.getObject(id=group_id, **kwargs)
python
def get_securitygroup(self, group_id, **kwargs): """Returns the information about the given security group. :param string id: The ID for the security group :returns: A diction of information about the security group """ if 'mask' not in kwargs: kwargs['mask'] = ( 'id,' 'name,' 'description,' '''rules[id, remoteIp, remoteGroupId, direction, ethertype, portRangeMin, portRangeMax, protocol, createDate, modifyDate],''' '''networkComponentBindings[ networkComponent[ id, port, guest[ id, hostname, primaryBackendIpAddress, primaryIpAddress ] ] ]''' ) return self.security_group.getObject(id=group_id, **kwargs)
[ "def", "get_securitygroup", "(", "self", ",", "group_id", ",", "*", "*", "kwargs", ")", ":", "if", "'mask'", "not", "in", "kwargs", ":", "kwargs", "[", "'mask'", "]", "=", "(", "'id,'", "'name,'", "'description,'", "'''rules[id, remoteIp, remoteGroupId,\n direction, ethertype, portRangeMin,\n portRangeMax, protocol, createDate, modifyDate],'''", "'''networkComponentBindings[\n networkComponent[\n id,\n port,\n guest[\n id,\n hostname,\n primaryBackendIpAddress,\n primaryIpAddress\n ]\n ]\n ]'''", ")", "return", "self", ".", "security_group", ".", "getObject", "(", "id", "=", "group_id", ",", "*", "*", "kwargs", ")" ]
Returns the information about the given security group. :param string id: The ID for the security group :returns: A diction of information about the security group
[ "Returns", "the", "information", "about", "the", "given", "security", "group", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L361-L389
train
234,456
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.get_subnet
def get_subnet(self, subnet_id, **kwargs): """Returns information about a single subnet. :param string id: Either the ID for the subnet or its network identifier :returns: A dictionary of information about the subnet """ if 'mask' not in kwargs: kwargs['mask'] = DEFAULT_SUBNET_MASK return self.subnet.getObject(id=subnet_id, **kwargs)
python
def get_subnet(self, subnet_id, **kwargs): """Returns information about a single subnet. :param string id: Either the ID for the subnet or its network identifier :returns: A dictionary of information about the subnet """ if 'mask' not in kwargs: kwargs['mask'] = DEFAULT_SUBNET_MASK return self.subnet.getObject(id=subnet_id, **kwargs)
[ "def", "get_subnet", "(", "self", ",", "subnet_id", ",", "*", "*", "kwargs", ")", ":", "if", "'mask'", "not", "in", "kwargs", ":", "kwargs", "[", "'mask'", "]", "=", "DEFAULT_SUBNET_MASK", "return", "self", ".", "subnet", ".", "getObject", "(", "id", "=", "subnet_id", ",", "*", "*", "kwargs", ")" ]
Returns information about a single subnet. :param string id: Either the ID for the subnet or its network identifier :returns: A dictionary of information about the subnet
[ "Returns", "information", "about", "a", "single", "subnet", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L391-L401
train
234,457
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.get_vlan
def get_vlan(self, vlan_id): """Returns information about a single VLAN. :param int id: The unique identifier for the VLAN :returns: A dictionary containing a large amount of information about the specified VLAN. """ return self.vlan.getObject(id=vlan_id, mask=DEFAULT_GET_VLAN_MASK)
python
def get_vlan(self, vlan_id): """Returns information about a single VLAN. :param int id: The unique identifier for the VLAN :returns: A dictionary containing a large amount of information about the specified VLAN. """ return self.vlan.getObject(id=vlan_id, mask=DEFAULT_GET_VLAN_MASK)
[ "def", "get_vlan", "(", "self", ",", "vlan_id", ")", ":", "return", "self", ".", "vlan", ".", "getObject", "(", "id", "=", "vlan_id", ",", "mask", "=", "DEFAULT_GET_VLAN_MASK", ")" ]
Returns information about a single VLAN. :param int id: The unique identifier for the VLAN :returns: A dictionary containing a large amount of information about the specified VLAN.
[ "Returns", "information", "about", "a", "single", "VLAN", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L403-L411
train
234,458
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.list_global_ips
def list_global_ips(self, version=None, identifier=None, **kwargs): """Returns a list of all global IP address records on the account. :param int version: Only returns IPs of this version (4 or 6) :param string identifier: If specified, the list will only contain the global ips matching this network identifier. """ if 'mask' not in kwargs: mask = ['destinationIpAddress[hardware, virtualGuest]', 'ipAddress'] kwargs['mask'] = ','.join(mask) _filter = utils.NestedDict({}) if version: ver = utils.query_filter(version) _filter['globalIpRecords']['ipAddress']['subnet']['version'] = ver if identifier: subnet_filter = _filter['globalIpRecords']['ipAddress']['subnet'] subnet_filter['networkIdentifier'] = utils.query_filter(identifier) kwargs['filter'] = _filter.to_dict() return self.account.getGlobalIpRecords(**kwargs)
python
def list_global_ips(self, version=None, identifier=None, **kwargs): """Returns a list of all global IP address records on the account. :param int version: Only returns IPs of this version (4 or 6) :param string identifier: If specified, the list will only contain the global ips matching this network identifier. """ if 'mask' not in kwargs: mask = ['destinationIpAddress[hardware, virtualGuest]', 'ipAddress'] kwargs['mask'] = ','.join(mask) _filter = utils.NestedDict({}) if version: ver = utils.query_filter(version) _filter['globalIpRecords']['ipAddress']['subnet']['version'] = ver if identifier: subnet_filter = _filter['globalIpRecords']['ipAddress']['subnet'] subnet_filter['networkIdentifier'] = utils.query_filter(identifier) kwargs['filter'] = _filter.to_dict() return self.account.getGlobalIpRecords(**kwargs)
[ "def", "list_global_ips", "(", "self", ",", "version", "=", "None", ",", "identifier", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "'mask'", "not", "in", "kwargs", ":", "mask", "=", "[", "'destinationIpAddress[hardware, virtualGuest]'", ",", "'ipAddress'", "]", "kwargs", "[", "'mask'", "]", "=", "','", ".", "join", "(", "mask", ")", "_filter", "=", "utils", ".", "NestedDict", "(", "{", "}", ")", "if", "version", ":", "ver", "=", "utils", ".", "query_filter", "(", "version", ")", "_filter", "[", "'globalIpRecords'", "]", "[", "'ipAddress'", "]", "[", "'subnet'", "]", "[", "'version'", "]", "=", "ver", "if", "identifier", ":", "subnet_filter", "=", "_filter", "[", "'globalIpRecords'", "]", "[", "'ipAddress'", "]", "[", "'subnet'", "]", "subnet_filter", "[", "'networkIdentifier'", "]", "=", "utils", ".", "query_filter", "(", "identifier", ")", "kwargs", "[", "'filter'", "]", "=", "_filter", ".", "to_dict", "(", ")", "return", "self", ".", "account", ".", "getGlobalIpRecords", "(", "*", "*", "kwargs", ")" ]
Returns a list of all global IP address records on the account. :param int version: Only returns IPs of this version (4 or 6) :param string identifier: If specified, the list will only contain the global ips matching this network identifier.
[ "Returns", "a", "list", "of", "all", "global", "IP", "address", "records", "on", "the", "account", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L413-L436
train
234,459
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.list_subnets
def list_subnets(self, identifier=None, datacenter=None, version=0, subnet_type=None, network_space=None, **kwargs): """Display a list of all subnets on the account. This provides a quick overview of all subnets including information about data center residence and the number of devices attached. :param string identifier: If specified, the list will only contain the subnet matching this network identifier. :param string datacenter: If specified, the list will only contain subnets in the specified data center. :param int version: Only returns subnets of this version (4 or 6). :param string subnet_type: If specified, it will only returns subnets of this type. :param string network_space: If specified, it will only returns subnets with the given address space label. :param dict \\*\\*kwargs: response-level options (mask, limit, etc.) """ if 'mask' not in kwargs: kwargs['mask'] = DEFAULT_SUBNET_MASK _filter = utils.NestedDict(kwargs.get('filter') or {}) if identifier: _filter['subnets']['networkIdentifier'] = ( utils.query_filter(identifier)) if datacenter: _filter['subnets']['datacenter']['name'] = ( utils.query_filter(datacenter)) if version: _filter['subnets']['version'] = utils.query_filter(version) if subnet_type: _filter['subnets']['subnetType'] = utils.query_filter(subnet_type) else: # This filters out global IPs from the subnet listing. _filter['subnets']['subnetType'] = {'operation': '!= GLOBAL_IP'} if network_space: _filter['subnets']['networkVlan']['networkSpace'] = ( utils.query_filter(network_space)) kwargs['filter'] = _filter.to_dict() kwargs['iter'] = True return self.client.call('Account', 'getSubnets', **kwargs)
python
def list_subnets(self, identifier=None, datacenter=None, version=0, subnet_type=None, network_space=None, **kwargs): """Display a list of all subnets on the account. This provides a quick overview of all subnets including information about data center residence and the number of devices attached. :param string identifier: If specified, the list will only contain the subnet matching this network identifier. :param string datacenter: If specified, the list will only contain subnets in the specified data center. :param int version: Only returns subnets of this version (4 or 6). :param string subnet_type: If specified, it will only returns subnets of this type. :param string network_space: If specified, it will only returns subnets with the given address space label. :param dict \\*\\*kwargs: response-level options (mask, limit, etc.) """ if 'mask' not in kwargs: kwargs['mask'] = DEFAULT_SUBNET_MASK _filter = utils.NestedDict(kwargs.get('filter') or {}) if identifier: _filter['subnets']['networkIdentifier'] = ( utils.query_filter(identifier)) if datacenter: _filter['subnets']['datacenter']['name'] = ( utils.query_filter(datacenter)) if version: _filter['subnets']['version'] = utils.query_filter(version) if subnet_type: _filter['subnets']['subnetType'] = utils.query_filter(subnet_type) else: # This filters out global IPs from the subnet listing. _filter['subnets']['subnetType'] = {'operation': '!= GLOBAL_IP'} if network_space: _filter['subnets']['networkVlan']['networkSpace'] = ( utils.query_filter(network_space)) kwargs['filter'] = _filter.to_dict() kwargs['iter'] = True return self.client.call('Account', 'getSubnets', **kwargs)
[ "def", "list_subnets", "(", "self", ",", "identifier", "=", "None", ",", "datacenter", "=", "None", ",", "version", "=", "0", ",", "subnet_type", "=", "None", ",", "network_space", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "'mask'", "not", "in", "kwargs", ":", "kwargs", "[", "'mask'", "]", "=", "DEFAULT_SUBNET_MASK", "_filter", "=", "utils", ".", "NestedDict", "(", "kwargs", ".", "get", "(", "'filter'", ")", "or", "{", "}", ")", "if", "identifier", ":", "_filter", "[", "'subnets'", "]", "[", "'networkIdentifier'", "]", "=", "(", "utils", ".", "query_filter", "(", "identifier", ")", ")", "if", "datacenter", ":", "_filter", "[", "'subnets'", "]", "[", "'datacenter'", "]", "[", "'name'", "]", "=", "(", "utils", ".", "query_filter", "(", "datacenter", ")", ")", "if", "version", ":", "_filter", "[", "'subnets'", "]", "[", "'version'", "]", "=", "utils", ".", "query_filter", "(", "version", ")", "if", "subnet_type", ":", "_filter", "[", "'subnets'", "]", "[", "'subnetType'", "]", "=", "utils", ".", "query_filter", "(", "subnet_type", ")", "else", ":", "# This filters out global IPs from the subnet listing.", "_filter", "[", "'subnets'", "]", "[", "'subnetType'", "]", "=", "{", "'operation'", ":", "'!= GLOBAL_IP'", "}", "if", "network_space", ":", "_filter", "[", "'subnets'", "]", "[", "'networkVlan'", "]", "[", "'networkSpace'", "]", "=", "(", "utils", ".", "query_filter", "(", "network_space", ")", ")", "kwargs", "[", "'filter'", "]", "=", "_filter", ".", "to_dict", "(", ")", "kwargs", "[", "'iter'", "]", "=", "True", "return", "self", ".", "client", ".", "call", "(", "'Account'", ",", "'getSubnets'", ",", "*", "*", "kwargs", ")" ]
Display a list of all subnets on the account. This provides a quick overview of all subnets including information about data center residence and the number of devices attached. :param string identifier: If specified, the list will only contain the subnet matching this network identifier. :param string datacenter: If specified, the list will only contain subnets in the specified data center. :param int version: Only returns subnets of this version (4 or 6). :param string subnet_type: If specified, it will only returns subnets of this type. :param string network_space: If specified, it will only returns subnets with the given address space label. :param dict \\*\\*kwargs: response-level options (mask, limit, etc.)
[ "Display", "a", "list", "of", "all", "subnets", "on", "the", "account", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L438-L480
train
234,460
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.list_vlans
def list_vlans(self, datacenter=None, vlan_number=None, name=None, **kwargs): """Display a list of all VLANs on the account. This provides a quick overview of all VLANs including information about data center residence and the number of devices attached. :param string datacenter: If specified, the list will only contain VLANs in the specified data center. :param int vlan_number: If specified, the list will only contain the VLAN matching this VLAN number. :param int name: If specified, the list will only contain the VLAN matching this VLAN name. :param dict \\*\\*kwargs: response-level options (mask, limit, etc.) """ _filter = utils.NestedDict(kwargs.get('filter') or {}) if vlan_number: _filter['networkVlans']['vlanNumber'] = ( utils.query_filter(vlan_number)) if name: _filter['networkVlans']['name'] = utils.query_filter(name) if datacenter: _filter['networkVlans']['primaryRouter']['datacenter']['name'] = ( utils.query_filter(datacenter)) kwargs['filter'] = _filter.to_dict() if 'mask' not in kwargs: kwargs['mask'] = DEFAULT_VLAN_MASK kwargs['iter'] = True return self.account.getNetworkVlans(**kwargs)
python
def list_vlans(self, datacenter=None, vlan_number=None, name=None, **kwargs): """Display a list of all VLANs on the account. This provides a quick overview of all VLANs including information about data center residence and the number of devices attached. :param string datacenter: If specified, the list will only contain VLANs in the specified data center. :param int vlan_number: If specified, the list will only contain the VLAN matching this VLAN number. :param int name: If specified, the list will only contain the VLAN matching this VLAN name. :param dict \\*\\*kwargs: response-level options (mask, limit, etc.) """ _filter = utils.NestedDict(kwargs.get('filter') or {}) if vlan_number: _filter['networkVlans']['vlanNumber'] = ( utils.query_filter(vlan_number)) if name: _filter['networkVlans']['name'] = utils.query_filter(name) if datacenter: _filter['networkVlans']['primaryRouter']['datacenter']['name'] = ( utils.query_filter(datacenter)) kwargs['filter'] = _filter.to_dict() if 'mask' not in kwargs: kwargs['mask'] = DEFAULT_VLAN_MASK kwargs['iter'] = True return self.account.getNetworkVlans(**kwargs)
[ "def", "list_vlans", "(", "self", ",", "datacenter", "=", "None", ",", "vlan_number", "=", "None", ",", "name", "=", "None", ",", "*", "*", "kwargs", ")", ":", "_filter", "=", "utils", ".", "NestedDict", "(", "kwargs", ".", "get", "(", "'filter'", ")", "or", "{", "}", ")", "if", "vlan_number", ":", "_filter", "[", "'networkVlans'", "]", "[", "'vlanNumber'", "]", "=", "(", "utils", ".", "query_filter", "(", "vlan_number", ")", ")", "if", "name", ":", "_filter", "[", "'networkVlans'", "]", "[", "'name'", "]", "=", "utils", ".", "query_filter", "(", "name", ")", "if", "datacenter", ":", "_filter", "[", "'networkVlans'", "]", "[", "'primaryRouter'", "]", "[", "'datacenter'", "]", "[", "'name'", "]", "=", "(", "utils", ".", "query_filter", "(", "datacenter", ")", ")", "kwargs", "[", "'filter'", "]", "=", "_filter", ".", "to_dict", "(", ")", "if", "'mask'", "not", "in", "kwargs", ":", "kwargs", "[", "'mask'", "]", "=", "DEFAULT_VLAN_MASK", "kwargs", "[", "'iter'", "]", "=", "True", "return", "self", ".", "account", ".", "getNetworkVlans", "(", "*", "*", "kwargs", ")" ]
Display a list of all VLANs on the account. This provides a quick overview of all VLANs including information about data center residence and the number of devices attached. :param string datacenter: If specified, the list will only contain VLANs in the specified data center. :param int vlan_number: If specified, the list will only contain the VLAN matching this VLAN number. :param int name: If specified, the list will only contain the VLAN matching this VLAN name. :param dict \\*\\*kwargs: response-level options (mask, limit, etc.)
[ "Display", "a", "list", "of", "all", "VLANs", "on", "the", "account", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L482-L516
train
234,461
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.list_securitygroup_rules
def list_securitygroup_rules(self, group_id): """List security group rules associated with a security group. :param int group_id: The security group to list rules for """ return self.security_group.getRules(id=group_id, iter=True)
python
def list_securitygroup_rules(self, group_id): """List security group rules associated with a security group. :param int group_id: The security group to list rules for """ return self.security_group.getRules(id=group_id, iter=True)
[ "def", "list_securitygroup_rules", "(", "self", ",", "group_id", ")", ":", "return", "self", ".", "security_group", ".", "getRules", "(", "id", "=", "group_id", ",", "iter", "=", "True", ")" ]
List security group rules associated with a security group. :param int group_id: The security group to list rules for
[ "List", "security", "group", "rules", "associated", "with", "a", "security", "group", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L523-L528
train
234,462
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.remove_securitygroup_rules
def remove_securitygroup_rules(self, group_id, rules): """Remove rules from a security group. :param int group_id: The ID of the security group :param list rules: The list of IDs to remove """ return self.security_group.removeRules(rules, id=group_id)
python
def remove_securitygroup_rules(self, group_id, rules): """Remove rules from a security group. :param int group_id: The ID of the security group :param list rules: The list of IDs to remove """ return self.security_group.removeRules(rules, id=group_id)
[ "def", "remove_securitygroup_rules", "(", "self", ",", "group_id", ",", "rules", ")", ":", "return", "self", ".", "security_group", ".", "removeRules", "(", "rules", ",", "id", "=", "group_id", ")" ]
Remove rules from a security group. :param int group_id: The ID of the security group :param list rules: The list of IDs to remove
[ "Remove", "rules", "from", "a", "security", "group", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L538-L544
train
234,463
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.get_event_logs_by_request_id
def get_event_logs_by_request_id(self, request_id): """Gets all event logs by the given request id :param string request_id: The request id we want to filter on """ # Get all relevant event logs unfiltered_logs = self._get_cci_event_logs() + self._get_security_group_event_logs() # Grab only those that have the specific request id filtered_logs = [] for unfiltered_log in unfiltered_logs: try: metadata = json.loads(unfiltered_log['metaData']) if 'requestId' in metadata: if metadata['requestId'] == request_id: filtered_logs.append(unfiltered_log) except ValueError: continue return filtered_logs
python
def get_event_logs_by_request_id(self, request_id): """Gets all event logs by the given request id :param string request_id: The request id we want to filter on """ # Get all relevant event logs unfiltered_logs = self._get_cci_event_logs() + self._get_security_group_event_logs() # Grab only those that have the specific request id filtered_logs = [] for unfiltered_log in unfiltered_logs: try: metadata = json.loads(unfiltered_log['metaData']) if 'requestId' in metadata: if metadata['requestId'] == request_id: filtered_logs.append(unfiltered_log) except ValueError: continue return filtered_logs
[ "def", "get_event_logs_by_request_id", "(", "self", ",", "request_id", ")", ":", "# Get all relevant event logs", "unfiltered_logs", "=", "self", ".", "_get_cci_event_logs", "(", ")", "+", "self", ".", "_get_security_group_event_logs", "(", ")", "# Grab only those that have the specific request id", "filtered_logs", "=", "[", "]", "for", "unfiltered_log", "in", "unfiltered_logs", ":", "try", ":", "metadata", "=", "json", ".", "loads", "(", "unfiltered_log", "[", "'metaData'", "]", ")", "if", "'requestId'", "in", "metadata", ":", "if", "metadata", "[", "'requestId'", "]", "==", "request_id", ":", "filtered_logs", ".", "append", "(", "unfiltered_log", ")", "except", "ValueError", ":", "continue", "return", "filtered_logs" ]
Gets all event logs by the given request id :param string request_id: The request id we want to filter on
[ "Gets", "all", "event", "logs", "by", "the", "given", "request", "id" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L546-L567
train
234,464
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager.summary_by_datacenter
def summary_by_datacenter(self): """Summary of the networks on the account, grouped by data center. The resultant dictionary is primarily useful for statistical purposes. It contains count information rather than raw data. If you want raw information, see the :func:`list_vlans` method instead. :returns: A dictionary keyed by data center with the data containing a set of counts for subnets, hardware, virtual servers, and other objects residing within that data center. """ datacenters = collections.defaultdict(lambda: { 'hardware_count': 0, 'public_ip_count': 0, 'subnet_count': 0, 'virtual_guest_count': 0, 'vlan_count': 0, }) for vlan in self.list_vlans(): name = utils.lookup(vlan, 'primaryRouter', 'datacenter', 'name') datacenters[name]['vlan_count'] += 1 datacenters[name]['public_ip_count'] += ( vlan['totalPrimaryIpAddressCount']) datacenters[name]['subnet_count'] += vlan['subnetCount'] # NOTE(kmcdonald): Only count hardware/guests once if vlan.get('networkSpace') == 'PRIVATE': datacenters[name]['hardware_count'] += ( vlan['hardwareCount']) datacenters[name]['virtual_guest_count'] += ( vlan['virtualGuestCount']) return dict(datacenters)
python
def summary_by_datacenter(self): """Summary of the networks on the account, grouped by data center. The resultant dictionary is primarily useful for statistical purposes. It contains count information rather than raw data. If you want raw information, see the :func:`list_vlans` method instead. :returns: A dictionary keyed by data center with the data containing a set of counts for subnets, hardware, virtual servers, and other objects residing within that data center. """ datacenters = collections.defaultdict(lambda: { 'hardware_count': 0, 'public_ip_count': 0, 'subnet_count': 0, 'virtual_guest_count': 0, 'vlan_count': 0, }) for vlan in self.list_vlans(): name = utils.lookup(vlan, 'primaryRouter', 'datacenter', 'name') datacenters[name]['vlan_count'] += 1 datacenters[name]['public_ip_count'] += ( vlan['totalPrimaryIpAddressCount']) datacenters[name]['subnet_count'] += vlan['subnetCount'] # NOTE(kmcdonald): Only count hardware/guests once if vlan.get('networkSpace') == 'PRIVATE': datacenters[name]['hardware_count'] += ( vlan['hardwareCount']) datacenters[name]['virtual_guest_count'] += ( vlan['virtualGuestCount']) return dict(datacenters)
[ "def", "summary_by_datacenter", "(", "self", ")", ":", "datacenters", "=", "collections", ".", "defaultdict", "(", "lambda", ":", "{", "'hardware_count'", ":", "0", ",", "'public_ip_count'", ":", "0", ",", "'subnet_count'", ":", "0", ",", "'virtual_guest_count'", ":", "0", ",", "'vlan_count'", ":", "0", ",", "}", ")", "for", "vlan", "in", "self", ".", "list_vlans", "(", ")", ":", "name", "=", "utils", ".", "lookup", "(", "vlan", ",", "'primaryRouter'", ",", "'datacenter'", ",", "'name'", ")", "datacenters", "[", "name", "]", "[", "'vlan_count'", "]", "+=", "1", "datacenters", "[", "name", "]", "[", "'public_ip_count'", "]", "+=", "(", "vlan", "[", "'totalPrimaryIpAddressCount'", "]", ")", "datacenters", "[", "name", "]", "[", "'subnet_count'", "]", "+=", "vlan", "[", "'subnetCount'", "]", "# NOTE(kmcdonald): Only count hardware/guests once", "if", "vlan", ".", "get", "(", "'networkSpace'", ")", "==", "'PRIVATE'", ":", "datacenters", "[", "name", "]", "[", "'hardware_count'", "]", "+=", "(", "vlan", "[", "'hardwareCount'", "]", ")", "datacenters", "[", "name", "]", "[", "'virtual_guest_count'", "]", "+=", "(", "vlan", "[", "'virtualGuestCount'", "]", ")", "return", "dict", "(", "datacenters", ")" ]
Summary of the networks on the account, grouped by data center. The resultant dictionary is primarily useful for statistical purposes. It contains count information rather than raw data. If you want raw information, see the :func:`list_vlans` method instead. :returns: A dictionary keyed by data center with the data containing a set of counts for subnets, hardware, virtual servers, and other objects residing within that data center.
[ "Summary", "of", "the", "networks", "on", "the", "account", "grouped", "by", "data", "center", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L599-L634
train
234,465
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager._list_global_ips_by_identifier
def _list_global_ips_by_identifier(self, identifier): """Returns a list of IDs of the global IP matching the identifier. :param string identifier: The identifier to look up :returns: List of matching IDs """ results = self.list_global_ips(identifier=identifier, mask='id') return [result['id'] for result in results]
python
def _list_global_ips_by_identifier(self, identifier): """Returns a list of IDs of the global IP matching the identifier. :param string identifier: The identifier to look up :returns: List of matching IDs """ results = self.list_global_ips(identifier=identifier, mask='id') return [result['id'] for result in results]
[ "def", "_list_global_ips_by_identifier", "(", "self", ",", "identifier", ")", ":", "results", "=", "self", ".", "list_global_ips", "(", "identifier", "=", "identifier", ",", "mask", "=", "'id'", ")", "return", "[", "result", "[", "'id'", "]", "for", "result", "in", "results", "]" ]
Returns a list of IDs of the global IP matching the identifier. :param string identifier: The identifier to look up :returns: List of matching IDs
[ "Returns", "a", "list", "of", "IDs", "of", "the", "global", "IP", "matching", "the", "identifier", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L644-L651
train
234,466
softlayer/softlayer-python
SoftLayer/managers/network.py
NetworkManager._list_subnets_by_identifier
def _list_subnets_by_identifier(self, identifier): """Returns a list of IDs of the subnet matching the identifier. :param string identifier: The identifier to look up :returns: List of matching IDs """ identifier = identifier.split('/', 1)[0] results = self.list_subnets(identifier=identifier, mask='id') return [result['id'] for result in results]
python
def _list_subnets_by_identifier(self, identifier): """Returns a list of IDs of the subnet matching the identifier. :param string identifier: The identifier to look up :returns: List of matching IDs """ identifier = identifier.split('/', 1)[0] results = self.list_subnets(identifier=identifier, mask='id') return [result['id'] for result in results]
[ "def", "_list_subnets_by_identifier", "(", "self", ",", "identifier", ")", ":", "identifier", "=", "identifier", ".", "split", "(", "'/'", ",", "1", ")", "[", "0", "]", "results", "=", "self", ".", "list_subnets", "(", "identifier", "=", "identifier", ",", "mask", "=", "'id'", ")", "return", "[", "result", "[", "'id'", "]", "for", "result", "in", "results", "]" ]
Returns a list of IDs of the subnet matching the identifier. :param string identifier: The identifier to look up :returns: List of matching IDs
[ "Returns", "a", "list", "of", "IDs", "of", "the", "subnet", "matching", "the", "identifier", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/network.py#L653-L662
train
234,467
softlayer/softlayer-python
SoftLayer/CLI/file/replication/partners.py
cli
def cli(env, columns, sortby, volume_id): """List existing replicant volumes for a file volume.""" file_storage_manager = SoftLayer.FileStorageManager(env.client) legal_volumes = file_storage_manager.get_replication_partners( volume_id ) if not legal_volumes: click.echo("There are no replication partners for the given volume.") else: table = formatting.Table(columns.columns) table.sortby = sortby for legal_volume in legal_volumes: table.add_row([value or formatting.blank() for value in columns.row(legal_volume)]) env.fout(table)
python
def cli(env, columns, sortby, volume_id): """List existing replicant volumes for a file volume.""" file_storage_manager = SoftLayer.FileStorageManager(env.client) legal_volumes = file_storage_manager.get_replication_partners( volume_id ) if not legal_volumes: click.echo("There are no replication partners for the given volume.") else: table = formatting.Table(columns.columns) table.sortby = sortby for legal_volume in legal_volumes: table.add_row([value or formatting.blank() for value in columns.row(legal_volume)]) env.fout(table)
[ "def", "cli", "(", "env", ",", "columns", ",", "sortby", ",", "volume_id", ")", ":", "file_storage_manager", "=", "SoftLayer", ".", "FileStorageManager", "(", "env", ".", "client", ")", "legal_volumes", "=", "file_storage_manager", ".", "get_replication_partners", "(", "volume_id", ")", "if", "not", "legal_volumes", ":", "click", ".", "echo", "(", "\"There are no replication partners for the given volume.\"", ")", "else", ":", "table", "=", "formatting", ".", "Table", "(", "columns", ".", "columns", ")", "table", ".", "sortby", "=", "sortby", "for", "legal_volume", "in", "legal_volumes", ":", "table", ".", "add_row", "(", "[", "value", "or", "formatting", ".", "blank", "(", ")", "for", "value", "in", "columns", ".", "row", "(", "legal_volume", ")", "]", ")", "env", ".", "fout", "(", "table", ")" ]
List existing replicant volumes for a file volume.
[ "List", "existing", "replicant", "volumes", "for", "a", "file", "volume", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/file/replication/partners.py#L42-L60
train
234,468
softlayer/softlayer-python
SoftLayer/CLI/ticket/__init__.py
get_ticket_results
def get_ticket_results(mgr, ticket_id, update_count=1): """Get output about a ticket. :param integer id: the ticket ID :param integer update_count: number of entries to retrieve from ticket :returns: a KeyValue table containing the details of the ticket """ ticket = mgr.get_ticket(ticket_id) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', ticket['id']]) table.add_row(['title', ticket['title']]) table.add_row(['priority', PRIORITY_MAP[ticket.get('priority', 0)]]) if ticket.get('assignedUser'): user = ticket['assignedUser'] table.add_row([ 'user', "%s %s" % (user.get('firstName'), user.get('lastName')), ]) table.add_row(['status', ticket['status']['name']]) table.add_row(['created', ticket.get('createDate')]) table.add_row(['edited', ticket.get('lastEditDate')]) # Only show up to the specified update count updates = ticket.get('updates', []) count = min(len(updates), update_count) count_offset = len(updates) - count + 1 # Display as one-indexed for i, update in enumerate(updates[-count:]): wrapped_entry = "" # Add user details (fields are different between employee and users) editor = update.get('editor') if editor: if editor.get('displayName'): wrapped_entry += "By %s (Employee)\n" % (editor['displayName']) if editor.get('firstName'): wrapped_entry += "By %s %s\n" % (editor.get('firstName'), editor.get('lastName')) # NOTE(kmcdonald): Windows new-line characters need to be stripped out wrapped_entry += click.wrap_text(update['entry'].replace('\r', '')) table.add_row(['update %s' % (count_offset + i,), wrapped_entry]) return table
python
def get_ticket_results(mgr, ticket_id, update_count=1): """Get output about a ticket. :param integer id: the ticket ID :param integer update_count: number of entries to retrieve from ticket :returns: a KeyValue table containing the details of the ticket """ ticket = mgr.get_ticket(ticket_id) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', ticket['id']]) table.add_row(['title', ticket['title']]) table.add_row(['priority', PRIORITY_MAP[ticket.get('priority', 0)]]) if ticket.get('assignedUser'): user = ticket['assignedUser'] table.add_row([ 'user', "%s %s" % (user.get('firstName'), user.get('lastName')), ]) table.add_row(['status', ticket['status']['name']]) table.add_row(['created', ticket.get('createDate')]) table.add_row(['edited', ticket.get('lastEditDate')]) # Only show up to the specified update count updates = ticket.get('updates', []) count = min(len(updates), update_count) count_offset = len(updates) - count + 1 # Display as one-indexed for i, update in enumerate(updates[-count:]): wrapped_entry = "" # Add user details (fields are different between employee and users) editor = update.get('editor') if editor: if editor.get('displayName'): wrapped_entry += "By %s (Employee)\n" % (editor['displayName']) if editor.get('firstName'): wrapped_entry += "By %s %s\n" % (editor.get('firstName'), editor.get('lastName')) # NOTE(kmcdonald): Windows new-line characters need to be stripped out wrapped_entry += click.wrap_text(update['entry'].replace('\r', '')) table.add_row(['update %s' % (count_offset + i,), wrapped_entry]) return table
[ "def", "get_ticket_results", "(", "mgr", ",", "ticket_id", ",", "update_count", "=", "1", ")", ":", "ticket", "=", "mgr", ".", "get_ticket", "(", "ticket_id", ")", "table", "=", "formatting", ".", "KeyValueTable", "(", "[", "'name'", ",", "'value'", "]", ")", "table", ".", "align", "[", "'name'", "]", "=", "'r'", "table", ".", "align", "[", "'value'", "]", "=", "'l'", "table", ".", "add_row", "(", "[", "'id'", ",", "ticket", "[", "'id'", "]", "]", ")", "table", ".", "add_row", "(", "[", "'title'", ",", "ticket", "[", "'title'", "]", "]", ")", "table", ".", "add_row", "(", "[", "'priority'", ",", "PRIORITY_MAP", "[", "ticket", ".", "get", "(", "'priority'", ",", "0", ")", "]", "]", ")", "if", "ticket", ".", "get", "(", "'assignedUser'", ")", ":", "user", "=", "ticket", "[", "'assignedUser'", "]", "table", ".", "add_row", "(", "[", "'user'", ",", "\"%s %s\"", "%", "(", "user", ".", "get", "(", "'firstName'", ")", ",", "user", ".", "get", "(", "'lastName'", ")", ")", ",", "]", ")", "table", ".", "add_row", "(", "[", "'status'", ",", "ticket", "[", "'status'", "]", "[", "'name'", "]", "]", ")", "table", ".", "add_row", "(", "[", "'created'", ",", "ticket", ".", "get", "(", "'createDate'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'edited'", ",", "ticket", ".", "get", "(", "'lastEditDate'", ")", "]", ")", "# Only show up to the specified update count", "updates", "=", "ticket", ".", "get", "(", "'updates'", ",", "[", "]", ")", "count", "=", "min", "(", "len", "(", "updates", ")", ",", "update_count", ")", "count_offset", "=", "len", "(", "updates", ")", "-", "count", "+", "1", "# Display as one-indexed", "for", "i", ",", "update", "in", "enumerate", "(", "updates", "[", "-", "count", ":", "]", ")", ":", "wrapped_entry", "=", "\"\"", "# Add user details (fields are different between employee and users)", "editor", "=", "update", ".", "get", "(", "'editor'", ")", "if", "editor", ":", "if", "editor", ".", "get", "(", "'displayName'", ")", ":", "wrapped_entry", "+=", "\"By %s (Employee)\\n\"", "%", "(", "editor", "[", "'displayName'", "]", ")", "if", "editor", ".", "get", "(", "'firstName'", ")", ":", "wrapped_entry", "+=", "\"By %s %s\\n\"", "%", "(", "editor", ".", "get", "(", "'firstName'", ")", ",", "editor", ".", "get", "(", "'lastName'", ")", ")", "# NOTE(kmcdonald): Windows new-line characters need to be stripped out", "wrapped_entry", "+=", "click", ".", "wrap_text", "(", "update", "[", "'entry'", "]", ".", "replace", "(", "'\\r'", ",", "''", ")", ")", "table", ".", "add_row", "(", "[", "'update %s'", "%", "(", "count_offset", "+", "i", ",", ")", ",", "wrapped_entry", "]", ")", "return", "table" ]
Get output about a ticket. :param integer id: the ticket ID :param integer update_count: number of entries to retrieve from ticket :returns: a KeyValue table containing the details of the ticket
[ "Get", "output", "about", "a", "ticket", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/ticket/__init__.py#L20-L68
train
234,469
softlayer/softlayer-python
SoftLayer/CLI/subnet/create.py
cli
def cli(env, network, quantity, vlan_id, ipv6, test): """Add a new subnet to your account. Valid quantities vary by type. \b Type - Valid Quantities (IPv4) public - 4, 8, 16, 32 private - 4, 8, 16, 32, 64 \b Type - Valid Quantities (IPv6) public - 64 """ mgr = SoftLayer.NetworkManager(env.client) if not (test or env.skip_confirmations): if not formatting.confirm("This action will incur charges on your " "account. Continue?"): raise exceptions.CLIAbort('Cancelling order.') version = 4 if ipv6: version = 6 try: result = mgr.add_subnet(network, quantity=quantity, vlan_id=vlan_id, version=version, test_order=test) except SoftLayer.SoftLayerAPIError: raise exceptions.CLIAbort('There is no price id for {} {} ipv{}'.format(quantity, network, version)) table = formatting.Table(['Item', 'cost']) table.align['Item'] = 'r' table.align['cost'] = 'r' total = 0.0 if 'prices' in result: for price in result['prices']: total += float(price.get('recurringFee', 0.0)) rate = "%.2f" % float(price['recurringFee']) table.add_row([price['item']['description'], rate]) table.add_row(['Total monthly cost', "%.2f" % total]) env.fout(table)
python
def cli(env, network, quantity, vlan_id, ipv6, test): """Add a new subnet to your account. Valid quantities vary by type. \b Type - Valid Quantities (IPv4) public - 4, 8, 16, 32 private - 4, 8, 16, 32, 64 \b Type - Valid Quantities (IPv6) public - 64 """ mgr = SoftLayer.NetworkManager(env.client) if not (test or env.skip_confirmations): if not formatting.confirm("This action will incur charges on your " "account. Continue?"): raise exceptions.CLIAbort('Cancelling order.') version = 4 if ipv6: version = 6 try: result = mgr.add_subnet(network, quantity=quantity, vlan_id=vlan_id, version=version, test_order=test) except SoftLayer.SoftLayerAPIError: raise exceptions.CLIAbort('There is no price id for {} {} ipv{}'.format(quantity, network, version)) table = formatting.Table(['Item', 'cost']) table.align['Item'] = 'r' table.align['cost'] = 'r' total = 0.0 if 'prices' in result: for price in result['prices']: total += float(price.get('recurringFee', 0.0)) rate = "%.2f" % float(price['recurringFee']) table.add_row([price['item']['description'], rate]) table.add_row(['Total monthly cost', "%.2f" % total]) env.fout(table)
[ "def", "cli", "(", "env", ",", "network", ",", "quantity", ",", "vlan_id", ",", "ipv6", ",", "test", ")", ":", "mgr", "=", "SoftLayer", ".", "NetworkManager", "(", "env", ".", "client", ")", "if", "not", "(", "test", "or", "env", ".", "skip_confirmations", ")", ":", "if", "not", "formatting", ".", "confirm", "(", "\"This action will incur charges on your \"", "\"account. Continue?\"", ")", ":", "raise", "exceptions", ".", "CLIAbort", "(", "'Cancelling order.'", ")", "version", "=", "4", "if", "ipv6", ":", "version", "=", "6", "try", ":", "result", "=", "mgr", ".", "add_subnet", "(", "network", ",", "quantity", "=", "quantity", ",", "vlan_id", "=", "vlan_id", ",", "version", "=", "version", ",", "test_order", "=", "test", ")", "except", "SoftLayer", ".", "SoftLayerAPIError", ":", "raise", "exceptions", ".", "CLIAbort", "(", "'There is no price id for {} {} ipv{}'", ".", "format", "(", "quantity", ",", "network", ",", "version", ")", ")", "table", "=", "formatting", ".", "Table", "(", "[", "'Item'", ",", "'cost'", "]", ")", "table", ".", "align", "[", "'Item'", "]", "=", "'r'", "table", ".", "align", "[", "'cost'", "]", "=", "'r'", "total", "=", "0.0", "if", "'prices'", "in", "result", ":", "for", "price", "in", "result", "[", "'prices'", "]", ":", "total", "+=", "float", "(", "price", ".", "get", "(", "'recurringFee'", ",", "0.0", ")", ")", "rate", "=", "\"%.2f\"", "%", "float", "(", "price", "[", "'recurringFee'", "]", ")", "table", ".", "add_row", "(", "[", "price", "[", "'item'", "]", "[", "'description'", "]", ",", "rate", "]", ")", "table", ".", "add_row", "(", "[", "'Total monthly cost'", ",", "\"%.2f\"", "%", "total", "]", ")", "env", ".", "fout", "(", "table", ")" ]
Add a new subnet to your account. Valid quantities vary by type. \b Type - Valid Quantities (IPv4) public - 4, 8, 16, 32 private - 4, 8, 16, 32, 64 \b Type - Valid Quantities (IPv6) public - 64
[ "Add", "a", "new", "subnet", "to", "your", "account", ".", "Valid", "quantities", "vary", "by", "type", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/subnet/create.py#L21-L63
train
234,470
softlayer/softlayer-python
SoftLayer/managers/ticket.py
TicketManager.list_tickets
def list_tickets(self, open_status=True, closed_status=True): """List all tickets. :param boolean open_status: include open tickets :param boolean closed_status: include closed tickets """ mask = """mask[id, title, assignedUser[firstName, lastName], priority, createDate, lastEditDate, accountId, status, updateCount]""" call = 'getTickets' if not all([open_status, closed_status]): if open_status: call = 'getOpenTickets' elif closed_status: call = 'getClosedTickets' else: raise ValueError("open_status and closed_status cannot both be False") return self.client.call('Account', call, mask=mask, iter=True)
python
def list_tickets(self, open_status=True, closed_status=True): """List all tickets. :param boolean open_status: include open tickets :param boolean closed_status: include closed tickets """ mask = """mask[id, title, assignedUser[firstName, lastName], priority, createDate, lastEditDate, accountId, status, updateCount]""" call = 'getTickets' if not all([open_status, closed_status]): if open_status: call = 'getOpenTickets' elif closed_status: call = 'getClosedTickets' else: raise ValueError("open_status and closed_status cannot both be False") return self.client.call('Account', call, mask=mask, iter=True)
[ "def", "list_tickets", "(", "self", ",", "open_status", "=", "True", ",", "closed_status", "=", "True", ")", ":", "mask", "=", "\"\"\"mask[id, title, assignedUser[firstName, lastName], priority,\n createDate, lastEditDate, accountId, status, updateCount]\"\"\"", "call", "=", "'getTickets'", "if", "not", "all", "(", "[", "open_status", ",", "closed_status", "]", ")", ":", "if", "open_status", ":", "call", "=", "'getOpenTickets'", "elif", "closed_status", ":", "call", "=", "'getClosedTickets'", "else", ":", "raise", "ValueError", "(", "\"open_status and closed_status cannot both be False\"", ")", "return", "self", ".", "client", ".", "call", "(", "'Account'", ",", "call", ",", "mask", "=", "mask", ",", "iter", "=", "True", ")" ]
List all tickets. :param boolean open_status: include open tickets :param boolean closed_status: include closed tickets
[ "List", "all", "tickets", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ticket.py#L25-L43
train
234,471
softlayer/softlayer-python
SoftLayer/managers/ticket.py
TicketManager.create_ticket
def create_ticket(self, title=None, body=None, subject=None, priority=None): """Create a new ticket. :param string title: title for the new ticket :param string body: body for the new ticket :param integer subject: id of the subject to be assigned to the ticket :param integer priority: Value from 1 (highest) to 4 (lowest) """ current_user = self.account.getCurrentUser() new_ticket = { 'subjectId': subject, 'contents': body, 'assignedUserId': current_user['id'], 'title': title, } if priority is not None: new_ticket['priority'] = int(priority) created_ticket = self.ticket.createStandardTicket(new_ticket, body) return created_ticket
python
def create_ticket(self, title=None, body=None, subject=None, priority=None): """Create a new ticket. :param string title: title for the new ticket :param string body: body for the new ticket :param integer subject: id of the subject to be assigned to the ticket :param integer priority: Value from 1 (highest) to 4 (lowest) """ current_user = self.account.getCurrentUser() new_ticket = { 'subjectId': subject, 'contents': body, 'assignedUserId': current_user['id'], 'title': title, } if priority is not None: new_ticket['priority'] = int(priority) created_ticket = self.ticket.createStandardTicket(new_ticket, body) return created_ticket
[ "def", "create_ticket", "(", "self", ",", "title", "=", "None", ",", "body", "=", "None", ",", "subject", "=", "None", ",", "priority", "=", "None", ")", ":", "current_user", "=", "self", ".", "account", ".", "getCurrentUser", "(", ")", "new_ticket", "=", "{", "'subjectId'", ":", "subject", ",", "'contents'", ":", "body", ",", "'assignedUserId'", ":", "current_user", "[", "'id'", "]", ",", "'title'", ":", "title", ",", "}", "if", "priority", "is", "not", "None", ":", "new_ticket", "[", "'priority'", "]", "=", "int", "(", "priority", ")", "created_ticket", "=", "self", ".", "ticket", ".", "createStandardTicket", "(", "new_ticket", ",", "body", ")", "return", "created_ticket" ]
Create a new ticket. :param string title: title for the new ticket :param string body: body for the new ticket :param integer subject: id of the subject to be assigned to the ticket :param integer priority: Value from 1 (highest) to 4 (lowest)
[ "Create", "a", "new", "ticket", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ticket.py#L60-L79
train
234,472
softlayer/softlayer-python
SoftLayer/managers/ticket.py
TicketManager.update_ticket
def update_ticket(self, ticket_id=None, body=None): """Update a ticket. :param integer ticket_id: the id of the ticket to update :param string body: entry to update in the ticket """ return self.ticket.addUpdate({'entry': body}, id=ticket_id)
python
def update_ticket(self, ticket_id=None, body=None): """Update a ticket. :param integer ticket_id: the id of the ticket to update :param string body: entry to update in the ticket """ return self.ticket.addUpdate({'entry': body}, id=ticket_id)
[ "def", "update_ticket", "(", "self", ",", "ticket_id", "=", "None", ",", "body", "=", "None", ")", ":", "return", "self", ".", "ticket", ".", "addUpdate", "(", "{", "'entry'", ":", "body", "}", ",", "id", "=", "ticket_id", ")" ]
Update a ticket. :param integer ticket_id: the id of the ticket to update :param string body: entry to update in the ticket
[ "Update", "a", "ticket", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ticket.py#L81-L87
train
234,473
softlayer/softlayer-python
SoftLayer/managers/ticket.py
TicketManager.upload_attachment
def upload_attachment(self, ticket_id=None, file_path=None, file_name=None): """Upload an attachment to a ticket. :param integer ticket_id: the id of the ticket to upload the attachment to :param string file_path: The path of the attachment to be uploaded :param string file_name: The name of the attachment shown in the ticket :returns: dict -- The uploaded attachment """ file_content = None with open(file_path, 'rb') as attached_file: file_content = attached_file.read() file_object = { "filename": file_name, "data": file_content } return self.ticket.addAttachedFile(file_object, id=ticket_id)
python
def upload_attachment(self, ticket_id=None, file_path=None, file_name=None): """Upload an attachment to a ticket. :param integer ticket_id: the id of the ticket to upload the attachment to :param string file_path: The path of the attachment to be uploaded :param string file_name: The name of the attachment shown in the ticket :returns: dict -- The uploaded attachment """ file_content = None with open(file_path, 'rb') as attached_file: file_content = attached_file.read() file_object = { "filename": file_name, "data": file_content } return self.ticket.addAttachedFile(file_object, id=ticket_id)
[ "def", "upload_attachment", "(", "self", ",", "ticket_id", "=", "None", ",", "file_path", "=", "None", ",", "file_name", "=", "None", ")", ":", "file_content", "=", "None", "with", "open", "(", "file_path", ",", "'rb'", ")", "as", "attached_file", ":", "file_content", "=", "attached_file", ".", "read", "(", ")", "file_object", "=", "{", "\"filename\"", ":", "file_name", ",", "\"data\"", ":", "file_content", "}", "return", "self", ".", "ticket", ".", "addAttachedFile", "(", "file_object", ",", "id", "=", "ticket_id", ")" ]
Upload an attachment to a ticket. :param integer ticket_id: the id of the ticket to upload the attachment to :param string file_path: The path of the attachment to be uploaded :param string file_name: The name of the attachment shown in the ticket :returns: dict -- The uploaded attachment
[ "Upload", "an", "attachment", "to", "a", "ticket", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ticket.py#L89-L106
train
234,474
softlayer/softlayer-python
SoftLayer/managers/ticket.py
TicketManager.attach_hardware
def attach_hardware(self, ticket_id=None, hardware_id=None): """Attach hardware to a ticket. :param integer ticket_id: the id of the ticket to attach to :param integer hardware_id: the id of the hardware to attach :returns: dict -- The new ticket attachment """ return self.ticket.addAttachedHardware(hardware_id, id=ticket_id)
python
def attach_hardware(self, ticket_id=None, hardware_id=None): """Attach hardware to a ticket. :param integer ticket_id: the id of the ticket to attach to :param integer hardware_id: the id of the hardware to attach :returns: dict -- The new ticket attachment """ return self.ticket.addAttachedHardware(hardware_id, id=ticket_id)
[ "def", "attach_hardware", "(", "self", ",", "ticket_id", "=", "None", ",", "hardware_id", "=", "None", ")", ":", "return", "self", ".", "ticket", ".", "addAttachedHardware", "(", "hardware_id", ",", "id", "=", "ticket_id", ")" ]
Attach hardware to a ticket. :param integer ticket_id: the id of the ticket to attach to :param integer hardware_id: the id of the hardware to attach :returns: dict -- The new ticket attachment
[ "Attach", "hardware", "to", "a", "ticket", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ticket.py#L108-L116
train
234,475
softlayer/softlayer-python
SoftLayer/managers/ticket.py
TicketManager.attach_virtual_server
def attach_virtual_server(self, ticket_id=None, virtual_id=None): """Attach a virtual server to a ticket. :param integer ticket_id: the id of the ticket to attach to :param integer virtual_id: the id of the virtual server to attach :returns: dict -- The new ticket attachment """ return self.ticket.addAttachedVirtualGuest(virtual_id, id=ticket_id)
python
def attach_virtual_server(self, ticket_id=None, virtual_id=None): """Attach a virtual server to a ticket. :param integer ticket_id: the id of the ticket to attach to :param integer virtual_id: the id of the virtual server to attach :returns: dict -- The new ticket attachment """ return self.ticket.addAttachedVirtualGuest(virtual_id, id=ticket_id)
[ "def", "attach_virtual_server", "(", "self", ",", "ticket_id", "=", "None", ",", "virtual_id", "=", "None", ")", ":", "return", "self", ".", "ticket", ".", "addAttachedVirtualGuest", "(", "virtual_id", ",", "id", "=", "ticket_id", ")" ]
Attach a virtual server to a ticket. :param integer ticket_id: the id of the ticket to attach to :param integer virtual_id: the id of the virtual server to attach :returns: dict -- The new ticket attachment
[ "Attach", "a", "virtual", "server", "to", "a", "ticket", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ticket.py#L118-L126
train
234,476
softlayer/softlayer-python
SoftLayer/managers/ticket.py
TicketManager.detach_hardware
def detach_hardware(self, ticket_id=None, hardware_id=None): """Detach hardware from a ticket. :param ticket_id: the id of the ticket to detach from :param hardware_id: the id of the hardware to detach :returns: bool -- Whether the detachment was successful """ return self.ticket.removeAttachedHardware(hardware_id, id=ticket_id)
python
def detach_hardware(self, ticket_id=None, hardware_id=None): """Detach hardware from a ticket. :param ticket_id: the id of the ticket to detach from :param hardware_id: the id of the hardware to detach :returns: bool -- Whether the detachment was successful """ return self.ticket.removeAttachedHardware(hardware_id, id=ticket_id)
[ "def", "detach_hardware", "(", "self", ",", "ticket_id", "=", "None", ",", "hardware_id", "=", "None", ")", ":", "return", "self", ".", "ticket", ".", "removeAttachedHardware", "(", "hardware_id", ",", "id", "=", "ticket_id", ")" ]
Detach hardware from a ticket. :param ticket_id: the id of the ticket to detach from :param hardware_id: the id of the hardware to detach :returns: bool -- Whether the detachment was successful
[ "Detach", "hardware", "from", "a", "ticket", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ticket.py#L128-L136
train
234,477
softlayer/softlayer-python
SoftLayer/managers/ticket.py
TicketManager.detach_virtual_server
def detach_virtual_server(self, ticket_id=None, virtual_id=None): """Detach a virtual server from a ticket. :param ticket_id: the id of the ticket to detach from :param virtual_id: the id of the virtual server to detach :returns: bool -- Whether the detachment was successful """ return self.ticket.removeAttachedVirtualGuest(virtual_id, id=ticket_id)
python
def detach_virtual_server(self, ticket_id=None, virtual_id=None): """Detach a virtual server from a ticket. :param ticket_id: the id of the ticket to detach from :param virtual_id: the id of the virtual server to detach :returns: bool -- Whether the detachment was successful """ return self.ticket.removeAttachedVirtualGuest(virtual_id, id=ticket_id)
[ "def", "detach_virtual_server", "(", "self", ",", "ticket_id", "=", "None", ",", "virtual_id", "=", "None", ")", ":", "return", "self", ".", "ticket", ".", "removeAttachedVirtualGuest", "(", "virtual_id", ",", "id", "=", "ticket_id", ")" ]
Detach a virtual server from a ticket. :param ticket_id: the id of the ticket to detach from :param virtual_id: the id of the virtual server to detach :returns: bool -- Whether the detachment was successful
[ "Detach", "a", "virtual", "server", "from", "a", "ticket", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/ticket.py#L138-L146
train
234,478
softlayer/softlayer-python
SoftLayer/CLI/subnet/detail.py
cli
def cli(env, identifier, no_vs, no_hardware): """Get subnet details.""" mgr = SoftLayer.NetworkManager(env.client) subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier, name='subnet') subnet = mgr.get_subnet(subnet_id) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', subnet['id']]) table.add_row(['identifier', '%s/%s' % (subnet['networkIdentifier'], str(subnet['cidr']))]) table.add_row(['subnet type', subnet['subnetType']]) table.add_row(['network space', utils.lookup(subnet, 'networkVlan', 'networkSpace')]) table.add_row(['gateway', subnet.get('gateway', formatting.blank())]) table.add_row(['broadcast', subnet.get('broadcastAddress', formatting.blank())]) table.add_row(['datacenter', subnet['datacenter']['name']]) table.add_row(['usable ips', subnet.get('usableIpAddressCount', formatting.blank())]) if not no_vs: if subnet['virtualGuests']: vs_table = formatting.Table(['hostname', 'domain', 'public_ip', 'private_ip']) for vsi in subnet['virtualGuests']: vs_table.add_row([vsi['hostname'], vsi['domain'], vsi.get('primaryIpAddress'), vsi.get('primaryBackendIpAddress')]) table.add_row(['vs', vs_table]) else: table.add_row(['vs', 'none']) if not no_hardware: if subnet['hardware']: hw_table = formatting.Table(['hostname', 'domain', 'public_ip', 'private_ip']) for hardware in subnet['hardware']: hw_table.add_row([hardware['hostname'], hardware['domain'], hardware.get('primaryIpAddress'), hardware.get('primaryBackendIpAddress')]) table.add_row(['hardware', hw_table]) else: table.add_row(['hardware', 'none']) env.fout(table)
python
def cli(env, identifier, no_vs, no_hardware): """Get subnet details.""" mgr = SoftLayer.NetworkManager(env.client) subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier, name='subnet') subnet = mgr.get_subnet(subnet_id) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', subnet['id']]) table.add_row(['identifier', '%s/%s' % (subnet['networkIdentifier'], str(subnet['cidr']))]) table.add_row(['subnet type', subnet['subnetType']]) table.add_row(['network space', utils.lookup(subnet, 'networkVlan', 'networkSpace')]) table.add_row(['gateway', subnet.get('gateway', formatting.blank())]) table.add_row(['broadcast', subnet.get('broadcastAddress', formatting.blank())]) table.add_row(['datacenter', subnet['datacenter']['name']]) table.add_row(['usable ips', subnet.get('usableIpAddressCount', formatting.blank())]) if not no_vs: if subnet['virtualGuests']: vs_table = formatting.Table(['hostname', 'domain', 'public_ip', 'private_ip']) for vsi in subnet['virtualGuests']: vs_table.add_row([vsi['hostname'], vsi['domain'], vsi.get('primaryIpAddress'), vsi.get('primaryBackendIpAddress')]) table.add_row(['vs', vs_table]) else: table.add_row(['vs', 'none']) if not no_hardware: if subnet['hardware']: hw_table = formatting.Table(['hostname', 'domain', 'public_ip', 'private_ip']) for hardware in subnet['hardware']: hw_table.add_row([hardware['hostname'], hardware['domain'], hardware.get('primaryIpAddress'), hardware.get('primaryBackendIpAddress')]) table.add_row(['hardware', hw_table]) else: table.add_row(['hardware', 'none']) env.fout(table)
[ "def", "cli", "(", "env", ",", "identifier", ",", "no_vs", ",", "no_hardware", ")", ":", "mgr", "=", "SoftLayer", ".", "NetworkManager", "(", "env", ".", "client", ")", "subnet_id", "=", "helpers", ".", "resolve_id", "(", "mgr", ".", "resolve_subnet_ids", ",", "identifier", ",", "name", "=", "'subnet'", ")", "subnet", "=", "mgr", ".", "get_subnet", "(", "subnet_id", ")", "table", "=", "formatting", ".", "KeyValueTable", "(", "[", "'name'", ",", "'value'", "]", ")", "table", ".", "align", "[", "'name'", "]", "=", "'r'", "table", ".", "align", "[", "'value'", "]", "=", "'l'", "table", ".", "add_row", "(", "[", "'id'", ",", "subnet", "[", "'id'", "]", "]", ")", "table", ".", "add_row", "(", "[", "'identifier'", ",", "'%s/%s'", "%", "(", "subnet", "[", "'networkIdentifier'", "]", ",", "str", "(", "subnet", "[", "'cidr'", "]", ")", ")", "]", ")", "table", ".", "add_row", "(", "[", "'subnet type'", ",", "subnet", "[", "'subnetType'", "]", "]", ")", "table", ".", "add_row", "(", "[", "'network space'", ",", "utils", ".", "lookup", "(", "subnet", ",", "'networkVlan'", ",", "'networkSpace'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'gateway'", ",", "subnet", ".", "get", "(", "'gateway'", ",", "formatting", ".", "blank", "(", ")", ")", "]", ")", "table", ".", "add_row", "(", "[", "'broadcast'", ",", "subnet", ".", "get", "(", "'broadcastAddress'", ",", "formatting", ".", "blank", "(", ")", ")", "]", ")", "table", ".", "add_row", "(", "[", "'datacenter'", ",", "subnet", "[", "'datacenter'", "]", "[", "'name'", "]", "]", ")", "table", ".", "add_row", "(", "[", "'usable ips'", ",", "subnet", ".", "get", "(", "'usableIpAddressCount'", ",", "formatting", ".", "blank", "(", ")", ")", "]", ")", "if", "not", "no_vs", ":", "if", "subnet", "[", "'virtualGuests'", "]", ":", "vs_table", "=", "formatting", ".", "Table", "(", "[", "'hostname'", ",", "'domain'", ",", "'public_ip'", ",", "'private_ip'", "]", ")", "for", "vsi", "in", "subnet", "[", "'virtualGuests'", "]", ":", "vs_table", ".", "add_row", "(", "[", "vsi", "[", "'hostname'", "]", ",", "vsi", "[", "'domain'", "]", ",", "vsi", ".", "get", "(", "'primaryIpAddress'", ")", ",", "vsi", ".", "get", "(", "'primaryBackendIpAddress'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'vs'", ",", "vs_table", "]", ")", "else", ":", "table", ".", "add_row", "(", "[", "'vs'", ",", "'none'", "]", ")", "if", "not", "no_hardware", ":", "if", "subnet", "[", "'hardware'", "]", ":", "hw_table", "=", "formatting", ".", "Table", "(", "[", "'hostname'", ",", "'domain'", ",", "'public_ip'", ",", "'private_ip'", "]", ")", "for", "hardware", "in", "subnet", "[", "'hardware'", "]", ":", "hw_table", ".", "add_row", "(", "[", "hardware", "[", "'hostname'", "]", ",", "hardware", "[", "'domain'", "]", ",", "hardware", ".", "get", "(", "'primaryIpAddress'", ")", ",", "hardware", ".", "get", "(", "'primaryBackendIpAddress'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'hardware'", ",", "hw_table", "]", ")", "else", ":", "table", ".", "add_row", "(", "[", "'hardware'", ",", "'none'", "]", ")", "env", ".", "fout", "(", "table", ")" ]
Get subnet details.
[ "Get", "subnet", "details", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/subnet/detail.py#L22-L72
train
234,479
softlayer/softlayer-python
SoftLayer/CLI/dns/zone_import.py
cli
def cli(env, zonefile, dry_run): """Import zone based off a BIND zone file.""" manager = SoftLayer.DNSManager(env.client) with open(zonefile) as zone_f: zone_contents = zone_f.read() zone, records, bad_lines = parse_zone_details(zone_contents) env.out("Parsed: zone=%s" % zone) for record in records: env.out("Parsed: %s" % RECORD_FMT.format(**record)) for line in bad_lines: env.out("Unparsed: %s" % line) if dry_run: return # Find zone id or create the zone if it doesn't exist try: zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone') except exceptions.CLIAbort: zone_id = manager.create_zone(zone)['id'] env.out(click.style("Created: %s" % zone, fg='green')) # Attempt to create each record for record in records: try: manager.create_record(zone_id, record['record'], record['type'], record['data'], record['ttl']) env.out(click.style("Created: %s" % RECORD_FMT.format(**record), fg='green')) except SoftLayer.SoftLayerAPIError as ex: env.out(click.style("Failed: %s" % RECORD_FMT.format(**record), fg='red')) env.out(click.style(str(ex), fg='red')) env.out(click.style("Finished", fg='green'))
python
def cli(env, zonefile, dry_run): """Import zone based off a BIND zone file.""" manager = SoftLayer.DNSManager(env.client) with open(zonefile) as zone_f: zone_contents = zone_f.read() zone, records, bad_lines = parse_zone_details(zone_contents) env.out("Parsed: zone=%s" % zone) for record in records: env.out("Parsed: %s" % RECORD_FMT.format(**record)) for line in bad_lines: env.out("Unparsed: %s" % line) if dry_run: return # Find zone id or create the zone if it doesn't exist try: zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone') except exceptions.CLIAbort: zone_id = manager.create_zone(zone)['id'] env.out(click.style("Created: %s" % zone, fg='green')) # Attempt to create each record for record in records: try: manager.create_record(zone_id, record['record'], record['type'], record['data'], record['ttl']) env.out(click.style("Created: %s" % RECORD_FMT.format(**record), fg='green')) except SoftLayer.SoftLayerAPIError as ex: env.out(click.style("Failed: %s" % RECORD_FMT.format(**record), fg='red')) env.out(click.style(str(ex), fg='red')) env.out(click.style("Finished", fg='green'))
[ "def", "cli", "(", "env", ",", "zonefile", ",", "dry_run", ")", ":", "manager", "=", "SoftLayer", ".", "DNSManager", "(", "env", ".", "client", ")", "with", "open", "(", "zonefile", ")", "as", "zone_f", ":", "zone_contents", "=", "zone_f", ".", "read", "(", ")", "zone", ",", "records", ",", "bad_lines", "=", "parse_zone_details", "(", "zone_contents", ")", "env", ".", "out", "(", "\"Parsed: zone=%s\"", "%", "zone", ")", "for", "record", "in", "records", ":", "env", ".", "out", "(", "\"Parsed: %s\"", "%", "RECORD_FMT", ".", "format", "(", "*", "*", "record", ")", ")", "for", "line", "in", "bad_lines", ":", "env", ".", "out", "(", "\"Unparsed: %s\"", "%", "line", ")", "if", "dry_run", ":", "return", "# Find zone id or create the zone if it doesn't exist", "try", ":", "zone_id", "=", "helpers", ".", "resolve_id", "(", "manager", ".", "resolve_ids", ",", "zone", ",", "name", "=", "'zone'", ")", "except", "exceptions", ".", "CLIAbort", ":", "zone_id", "=", "manager", ".", "create_zone", "(", "zone", ")", "[", "'id'", "]", "env", ".", "out", "(", "click", ".", "style", "(", "\"Created: %s\"", "%", "zone", ",", "fg", "=", "'green'", ")", ")", "# Attempt to create each record", "for", "record", "in", "records", ":", "try", ":", "manager", ".", "create_record", "(", "zone_id", ",", "record", "[", "'record'", "]", ",", "record", "[", "'type'", "]", ",", "record", "[", "'data'", "]", ",", "record", "[", "'ttl'", "]", ")", "env", ".", "out", "(", "click", ".", "style", "(", "\"Created: %s\"", "%", "RECORD_FMT", ".", "format", "(", "*", "*", "record", ")", ",", "fg", "=", "'green'", ")", ")", "except", "SoftLayer", ".", "SoftLayerAPIError", "as", "ex", ":", "env", ".", "out", "(", "click", ".", "style", "(", "\"Failed: %s\"", "%", "RECORD_FMT", ".", "format", "(", "*", "*", "record", ")", ",", "fg", "=", "'red'", ")", ")", "env", ".", "out", "(", "click", ".", "style", "(", "str", "(", "ex", ")", ",", "fg", "=", "'red'", ")", ")", "env", ".", "out", "(", "click", ".", "style", "(", "\"Finished\"", ",", "fg", "=", "'green'", ")", ")" ]
Import zone based off a BIND zone file.
[ "Import", "zone", "based", "off", "a", "BIND", "zone", "file", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/dns/zone_import.py#L25-L68
train
234,480
softlayer/softlayer-python
SoftLayer/CLI/dns/zone_import.py
parse_zone_details
def parse_zone_details(zone_contents): """Parses a zone file into python data-structures.""" records = [] bad_lines = [] zone_lines = [line.strip() for line in zone_contents.split('\n')] zone_search = re.search(r'^\$ORIGIN (?P<zone>.*)\.', zone_lines[0]) zone = zone_search.group('zone') for line in zone_lines[1:]: record_search = re.search(RECORD_REGEX, line) if record_search is None: bad_lines.append(line) continue name = record_search.group('domain') # The API requires we send a host, although bind allows a blank # entry. @ is the same thing as blank if name is None: name = "@" ttl = record_search.group('ttl') # we don't do anything with the class # domain_class = domainSearch.group('class') record_type = record_search.group('type').upper() data = record_search.group('data') # the dns class doesn't support weighted MX records yet, so we chomp # that part out. if record_type == "MX": record_search = re.search(r'(?P<weight>\d+)\s+(?P<data>.*)', data) data = record_search.group('data') # This will skip the SOA record bit. And any domain that gets # parsed oddly. if record_type == 'IN': bad_lines.append(line) continue records.append({ 'record': name, 'type': record_type, 'data': data, 'ttl': ttl, }) return zone, records, bad_lines
python
def parse_zone_details(zone_contents): """Parses a zone file into python data-structures.""" records = [] bad_lines = [] zone_lines = [line.strip() for line in zone_contents.split('\n')] zone_search = re.search(r'^\$ORIGIN (?P<zone>.*)\.', zone_lines[0]) zone = zone_search.group('zone') for line in zone_lines[1:]: record_search = re.search(RECORD_REGEX, line) if record_search is None: bad_lines.append(line) continue name = record_search.group('domain') # The API requires we send a host, although bind allows a blank # entry. @ is the same thing as blank if name is None: name = "@" ttl = record_search.group('ttl') # we don't do anything with the class # domain_class = domainSearch.group('class') record_type = record_search.group('type').upper() data = record_search.group('data') # the dns class doesn't support weighted MX records yet, so we chomp # that part out. if record_type == "MX": record_search = re.search(r'(?P<weight>\d+)\s+(?P<data>.*)', data) data = record_search.group('data') # This will skip the SOA record bit. And any domain that gets # parsed oddly. if record_type == 'IN': bad_lines.append(line) continue records.append({ 'record': name, 'type': record_type, 'data': data, 'ttl': ttl, }) return zone, records, bad_lines
[ "def", "parse_zone_details", "(", "zone_contents", ")", ":", "records", "=", "[", "]", "bad_lines", "=", "[", "]", "zone_lines", "=", "[", "line", ".", "strip", "(", ")", "for", "line", "in", "zone_contents", ".", "split", "(", "'\\n'", ")", "]", "zone_search", "=", "re", ".", "search", "(", "r'^\\$ORIGIN (?P<zone>.*)\\.'", ",", "zone_lines", "[", "0", "]", ")", "zone", "=", "zone_search", ".", "group", "(", "'zone'", ")", "for", "line", "in", "zone_lines", "[", "1", ":", "]", ":", "record_search", "=", "re", ".", "search", "(", "RECORD_REGEX", ",", "line", ")", "if", "record_search", "is", "None", ":", "bad_lines", ".", "append", "(", "line", ")", "continue", "name", "=", "record_search", ".", "group", "(", "'domain'", ")", "# The API requires we send a host, although bind allows a blank", "# entry. @ is the same thing as blank", "if", "name", "is", "None", ":", "name", "=", "\"@\"", "ttl", "=", "record_search", ".", "group", "(", "'ttl'", ")", "# we don't do anything with the class", "# domain_class = domainSearch.group('class')", "record_type", "=", "record_search", ".", "group", "(", "'type'", ")", ".", "upper", "(", ")", "data", "=", "record_search", ".", "group", "(", "'data'", ")", "# the dns class doesn't support weighted MX records yet, so we chomp", "# that part out.", "if", "record_type", "==", "\"MX\"", ":", "record_search", "=", "re", ".", "search", "(", "r'(?P<weight>\\d+)\\s+(?P<data>.*)'", ",", "data", ")", "data", "=", "record_search", ".", "group", "(", "'data'", ")", "# This will skip the SOA record bit. And any domain that gets", "# parsed oddly.", "if", "record_type", "==", "'IN'", ":", "bad_lines", ".", "append", "(", "line", ")", "continue", "records", ".", "append", "(", "{", "'record'", ":", "name", ",", "'type'", ":", "record_type", ",", "'data'", ":", "data", ",", "'ttl'", ":", "ttl", ",", "}", ")", "return", "zone", ",", "records", ",", "bad_lines" ]
Parses a zone file into python data-structures.
[ "Parses", "a", "zone", "file", "into", "python", "data", "-", "structures", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/dns/zone_import.py#L71-L117
train
234,481
softlayer/softlayer-python
SoftLayer/CLI/object_storage/list_accounts.py
cli
def cli(env): """List object storage accounts.""" mgr = SoftLayer.ObjectStorageManager(env.client) accounts = mgr.list_accounts() table = formatting.Table(['id', 'name', 'apiType']) table.sortby = 'id' api_type = None for account in accounts: if 'vendorName' in account and account['vendorName'] == 'Swift': api_type = 'Swift' elif 'Cleversafe' in account['serviceResource']['name']: api_type = 'S3' table.add_row([ account['id'], account['username'], api_type, ]) env.fout(table)
python
def cli(env): """List object storage accounts.""" mgr = SoftLayer.ObjectStorageManager(env.client) accounts = mgr.list_accounts() table = formatting.Table(['id', 'name', 'apiType']) table.sortby = 'id' api_type = None for account in accounts: if 'vendorName' in account and account['vendorName'] == 'Swift': api_type = 'Swift' elif 'Cleversafe' in account['serviceResource']['name']: api_type = 'S3' table.add_row([ account['id'], account['username'], api_type, ]) env.fout(table)
[ "def", "cli", "(", "env", ")", ":", "mgr", "=", "SoftLayer", ".", "ObjectStorageManager", "(", "env", ".", "client", ")", "accounts", "=", "mgr", ".", "list_accounts", "(", ")", "table", "=", "formatting", ".", "Table", "(", "[", "'id'", ",", "'name'", ",", "'apiType'", "]", ")", "table", ".", "sortby", "=", "'id'", "api_type", "=", "None", "for", "account", "in", "accounts", ":", "if", "'vendorName'", "in", "account", "and", "account", "[", "'vendorName'", "]", "==", "'Swift'", ":", "api_type", "=", "'Swift'", "elif", "'Cleversafe'", "in", "account", "[", "'serviceResource'", "]", "[", "'name'", "]", ":", "api_type", "=", "'S3'", "table", ".", "add_row", "(", "[", "account", "[", "'id'", "]", ",", "account", "[", "'username'", "]", ",", "api_type", ",", "]", ")", "env", ".", "fout", "(", "table", ")" ]
List object storage accounts.
[ "List", "object", "storage", "accounts", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/object_storage/list_accounts.py#L13-L33
train
234,482
softlayer/softlayer-python
SoftLayer/CLI/dns/zone_create.py
cli
def cli(env, zone): """Create a zone.""" manager = SoftLayer.DNSManager(env.client) manager.create_zone(zone)
python
def cli(env, zone): """Create a zone.""" manager = SoftLayer.DNSManager(env.client) manager.create_zone(zone)
[ "def", "cli", "(", "env", ",", "zone", ")", ":", "manager", "=", "SoftLayer", ".", "DNSManager", "(", "env", ".", "client", ")", "manager", ".", "create_zone", "(", "zone", ")" ]
Create a zone.
[ "Create", "a", "zone", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/dns/zone_create.py#L13-L17
train
234,483
softlayer/softlayer-python
SoftLayer/CLI/loadbal/create.py
cli
def cli(env, billing_id, datacenter): """Adds a load balancer given the id returned from create-options.""" mgr = SoftLayer.LoadBalancerManager(env.client) if not formatting.confirm("This action will incur charges on your " "account. Continue?"): raise exceptions.CLIAbort('Aborted.') mgr.add_local_lb(billing_id, datacenter=datacenter) env.fout("Load balancer is being created!")
python
def cli(env, billing_id, datacenter): """Adds a load balancer given the id returned from create-options.""" mgr = SoftLayer.LoadBalancerManager(env.client) if not formatting.confirm("This action will incur charges on your " "account. Continue?"): raise exceptions.CLIAbort('Aborted.') mgr.add_local_lb(billing_id, datacenter=datacenter) env.fout("Load balancer is being created!")
[ "def", "cli", "(", "env", ",", "billing_id", ",", "datacenter", ")", ":", "mgr", "=", "SoftLayer", ".", "LoadBalancerManager", "(", "env", ".", "client", ")", "if", "not", "formatting", ".", "confirm", "(", "\"This action will incur charges on your \"", "\"account. Continue?\"", ")", ":", "raise", "exceptions", ".", "CLIAbort", "(", "'Aborted.'", ")", "mgr", ".", "add_local_lb", "(", "billing_id", ",", "datacenter", "=", "datacenter", ")", "env", ".", "fout", "(", "\"Load balancer is being created!\"", ")" ]
Adds a load balancer given the id returned from create-options.
[ "Adds", "a", "load", "balancer", "given", "the", "id", "returned", "from", "create", "-", "options", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/loadbal/create.py#L17-L25
train
234,484
softlayer/softlayer-python
SoftLayer/CLI/loadbal/group_reset.py
cli
def cli(env, identifier): """Reset connections on a certain service group.""" mgr = SoftLayer.LoadBalancerManager(env.client) loadbal_id, group_id = loadbal.parse_id(identifier) mgr.reset_service_group(loadbal_id, group_id) env.fout('Load balancer service group connections are being reset!')
python
def cli(env, identifier): """Reset connections on a certain service group.""" mgr = SoftLayer.LoadBalancerManager(env.client) loadbal_id, group_id = loadbal.parse_id(identifier) mgr.reset_service_group(loadbal_id, group_id) env.fout('Load balancer service group connections are being reset!')
[ "def", "cli", "(", "env", ",", "identifier", ")", ":", "mgr", "=", "SoftLayer", ".", "LoadBalancerManager", "(", "env", ".", "client", ")", "loadbal_id", ",", "group_id", "=", "loadbal", ".", "parse_id", "(", "identifier", ")", "mgr", ".", "reset_service_group", "(", "loadbal_id", ",", "group_id", ")", "env", ".", "fout", "(", "'Load balancer service group connections are being reset!'", ")" ]
Reset connections on a certain service group.
[ "Reset", "connections", "on", "a", "certain", "service", "group", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/loadbal/group_reset.py#L14-L21
train
234,485
softlayer/softlayer-python
SoftLayer/CLI/ticket/upload.py
cli
def cli(env, identifier, path, name): """Adds an attachment to an existing ticket.""" mgr = SoftLayer.TicketManager(env.client) ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket') if path is None: raise exceptions.ArgumentError("Missing argument --path") if not os.path.exists(path): raise exceptions.ArgumentError("%s not exist" % path) if name is None: name = os.path.basename(path) attached_file = mgr.upload_attachment(ticket_id=ticket_id, file_path=path, file_name=name) env.fout("File attached: \n%s" % attached_file)
python
def cli(env, identifier, path, name): """Adds an attachment to an existing ticket.""" mgr = SoftLayer.TicketManager(env.client) ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket') if path is None: raise exceptions.ArgumentError("Missing argument --path") if not os.path.exists(path): raise exceptions.ArgumentError("%s not exist" % path) if name is None: name = os.path.basename(path) attached_file = mgr.upload_attachment(ticket_id=ticket_id, file_path=path, file_name=name) env.fout("File attached: \n%s" % attached_file)
[ "def", "cli", "(", "env", ",", "identifier", ",", "path", ",", "name", ")", ":", "mgr", "=", "SoftLayer", ".", "TicketManager", "(", "env", ".", "client", ")", "ticket_id", "=", "helpers", ".", "resolve_id", "(", "mgr", ".", "resolve_ids", ",", "identifier", ",", "'ticket'", ")", "if", "path", "is", "None", ":", "raise", "exceptions", ".", "ArgumentError", "(", "\"Missing argument --path\"", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "path", ")", ":", "raise", "exceptions", ".", "ArgumentError", "(", "\"%s not exist\"", "%", "path", ")", "if", "name", "is", "None", ":", "name", "=", "os", ".", "path", ".", "basename", "(", "path", ")", "attached_file", "=", "mgr", ".", "upload_attachment", "(", "ticket_id", "=", "ticket_id", ",", "file_path", "=", "path", ",", "file_name", "=", "name", ")", "env", ".", "fout", "(", "\"File attached: \\n%s\"", "%", "attached_file", ")" ]
Adds an attachment to an existing ticket.
[ "Adds", "an", "attachment", "to", "an", "existing", "ticket", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/ticket/upload.py#L19-L37
train
234,486
softlayer/softlayer-python
SoftLayer/managers/firewall.py
has_firewall
def has_firewall(vlan): """Helper to determine whether or not a VLAN has a firewall. :param dict vlan: A dictionary representing a VLAN :returns: True if the VLAN has a firewall, false if it doesn't. """ return bool( vlan.get('dedicatedFirewallFlag', None) or vlan.get('highAvailabilityFirewallFlag', None) or vlan.get('firewallInterfaces', None) or vlan.get('firewallNetworkComponents', None) or vlan.get('firewallGuestNetworkComponents', None) )
python
def has_firewall(vlan): """Helper to determine whether or not a VLAN has a firewall. :param dict vlan: A dictionary representing a VLAN :returns: True if the VLAN has a firewall, false if it doesn't. """ return bool( vlan.get('dedicatedFirewallFlag', None) or vlan.get('highAvailabilityFirewallFlag', None) or vlan.get('firewallInterfaces', None) or vlan.get('firewallNetworkComponents', None) or vlan.get('firewallGuestNetworkComponents', None) )
[ "def", "has_firewall", "(", "vlan", ")", ":", "return", "bool", "(", "vlan", ".", "get", "(", "'dedicatedFirewallFlag'", ",", "None", ")", "or", "vlan", ".", "get", "(", "'highAvailabilityFirewallFlag'", ",", "None", ")", "or", "vlan", ".", "get", "(", "'firewallInterfaces'", ",", "None", ")", "or", "vlan", ".", "get", "(", "'firewallNetworkComponents'", ",", "None", ")", "or", "vlan", ".", "get", "(", "'firewallGuestNetworkComponents'", ",", "None", ")", ")" ]
Helper to determine whether or not a VLAN has a firewall. :param dict vlan: A dictionary representing a VLAN :returns: True if the VLAN has a firewall, false if it doesn't.
[ "Helper", "to", "determine", "whether", "or", "not", "a", "VLAN", "has", "a", "firewall", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L17-L29
train
234,487
softlayer/softlayer-python
SoftLayer/managers/firewall.py
FirewallManager.get_standard_package
def get_standard_package(self, server_id, is_virt=True): """Retrieves the standard firewall package for the virtual server. :param int server_id: The ID of the server to create the firewall for :param bool is_virt: True if the ID provided is for a virtual server, False for a server :returns: A dictionary containing the standard virtual server firewall package """ firewall_port_speed = self._get_fwl_port_speed(server_id, is_virt) _value = "%s%s" % (firewall_port_speed, "Mbps Hardware Firewall") _filter = {'items': {'description': utils.query_filter(_value)}} return self.prod_pkg.getItems(id=0, filter=_filter)
python
def get_standard_package(self, server_id, is_virt=True): """Retrieves the standard firewall package for the virtual server. :param int server_id: The ID of the server to create the firewall for :param bool is_virt: True if the ID provided is for a virtual server, False for a server :returns: A dictionary containing the standard virtual server firewall package """ firewall_port_speed = self._get_fwl_port_speed(server_id, is_virt) _value = "%s%s" % (firewall_port_speed, "Mbps Hardware Firewall") _filter = {'items': {'description': utils.query_filter(_value)}} return self.prod_pkg.getItems(id=0, filter=_filter)
[ "def", "get_standard_package", "(", "self", ",", "server_id", ",", "is_virt", "=", "True", ")", ":", "firewall_port_speed", "=", "self", ".", "_get_fwl_port_speed", "(", "server_id", ",", "is_virt", ")", "_value", "=", "\"%s%s\"", "%", "(", "firewall_port_speed", ",", "\"Mbps Hardware Firewall\"", ")", "_filter", "=", "{", "'items'", ":", "{", "'description'", ":", "utils", ".", "query_filter", "(", "_value", ")", "}", "}", "return", "self", ".", "prod_pkg", ".", "getItems", "(", "id", "=", "0", ",", "filter", "=", "_filter", ")" ]
Retrieves the standard firewall package for the virtual server. :param int server_id: The ID of the server to create the firewall for :param bool is_virt: True if the ID provided is for a virtual server, False for a server :returns: A dictionary containing the standard virtual server firewall package
[ "Retrieves", "the", "standard", "firewall", "package", "for", "the", "virtual", "server", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L46-L61
train
234,488
softlayer/softlayer-python
SoftLayer/managers/firewall.py
FirewallManager.get_dedicated_package
def get_dedicated_package(self, ha_enabled=False): """Retrieves the dedicated firewall package. :param bool ha_enabled: True if HA is to be enabled on the firewall False for No HA :returns: A dictionary containing the dedicated virtual server firewall package """ fwl_filter = 'Hardware Firewall (Dedicated)' ha_fwl_filter = 'Hardware Firewall (High Availability)' _filter = utils.NestedDict({}) if ha_enabled: _filter['items']['description'] = utils.query_filter(ha_fwl_filter) else: _filter['items']['description'] = utils.query_filter(fwl_filter) return self.prod_pkg.getItems(id=0, filter=_filter.to_dict())
python
def get_dedicated_package(self, ha_enabled=False): """Retrieves the dedicated firewall package. :param bool ha_enabled: True if HA is to be enabled on the firewall False for No HA :returns: A dictionary containing the dedicated virtual server firewall package """ fwl_filter = 'Hardware Firewall (Dedicated)' ha_fwl_filter = 'Hardware Firewall (High Availability)' _filter = utils.NestedDict({}) if ha_enabled: _filter['items']['description'] = utils.query_filter(ha_fwl_filter) else: _filter['items']['description'] = utils.query_filter(fwl_filter) return self.prod_pkg.getItems(id=0, filter=_filter.to_dict())
[ "def", "get_dedicated_package", "(", "self", ",", "ha_enabled", "=", "False", ")", ":", "fwl_filter", "=", "'Hardware Firewall (Dedicated)'", "ha_fwl_filter", "=", "'Hardware Firewall (High Availability)'", "_filter", "=", "utils", ".", "NestedDict", "(", "{", "}", ")", "if", "ha_enabled", ":", "_filter", "[", "'items'", "]", "[", "'description'", "]", "=", "utils", ".", "query_filter", "(", "ha_fwl_filter", ")", "else", ":", "_filter", "[", "'items'", "]", "[", "'description'", "]", "=", "utils", ".", "query_filter", "(", "fwl_filter", ")", "return", "self", ".", "prod_pkg", ".", "getItems", "(", "id", "=", "0", ",", "filter", "=", "_filter", ".", "to_dict", "(", ")", ")" ]
Retrieves the dedicated firewall package. :param bool ha_enabled: True if HA is to be enabled on the firewall False for No HA :returns: A dictionary containing the dedicated virtual server firewall package
[ "Retrieves", "the", "dedicated", "firewall", "package", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L63-L80
train
234,489
softlayer/softlayer-python
SoftLayer/managers/firewall.py
FirewallManager.cancel_firewall
def cancel_firewall(self, firewall_id, dedicated=False): """Cancels the specified firewall. :param int firewall_id: Firewall ID to be cancelled. :param bool dedicated: If true, the firewall instance is dedicated, otherwise, the firewall instance is shared. """ fwl_billing = self._get_fwl_billing_item(firewall_id, dedicated) billing_item_service = self.client['Billing_Item'] return billing_item_service.cancelService(id=fwl_billing['id'])
python
def cancel_firewall(self, firewall_id, dedicated=False): """Cancels the specified firewall. :param int firewall_id: Firewall ID to be cancelled. :param bool dedicated: If true, the firewall instance is dedicated, otherwise, the firewall instance is shared. """ fwl_billing = self._get_fwl_billing_item(firewall_id, dedicated) billing_item_service = self.client['Billing_Item'] return billing_item_service.cancelService(id=fwl_billing['id'])
[ "def", "cancel_firewall", "(", "self", ",", "firewall_id", ",", "dedicated", "=", "False", ")", ":", "fwl_billing", "=", "self", ".", "_get_fwl_billing_item", "(", "firewall_id", ",", "dedicated", ")", "billing_item_service", "=", "self", ".", "client", "[", "'Billing_Item'", "]", "return", "billing_item_service", ".", "cancelService", "(", "id", "=", "fwl_billing", "[", "'id'", "]", ")" ]
Cancels the specified firewall. :param int firewall_id: Firewall ID to be cancelled. :param bool dedicated: If true, the firewall instance is dedicated, otherwise, the firewall instance is shared.
[ "Cancels", "the", "specified", "firewall", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L82-L92
train
234,490
softlayer/softlayer-python
SoftLayer/managers/firewall.py
FirewallManager.add_vlan_firewall
def add_vlan_firewall(self, vlan_id, ha_enabled=False): """Creates a firewall for the specified vlan. :param int vlan_id: The ID of the vlan to create the firewall for :param bool ha_enabled: If True, an HA firewall will be created :returns: A dictionary containing the VLAN firewall order """ package = self.get_dedicated_package(ha_enabled) product_order = { 'complexType': 'SoftLayer_Container_Product_Order_Network_' 'Protection_Firewall_Dedicated', 'quantity': 1, 'packageId': 0, 'vlanId': vlan_id, 'prices': [{'id': package[0]['prices'][0]['id']}] } return self.client['Product_Order'].placeOrder(product_order)
python
def add_vlan_firewall(self, vlan_id, ha_enabled=False): """Creates a firewall for the specified vlan. :param int vlan_id: The ID of the vlan to create the firewall for :param bool ha_enabled: If True, an HA firewall will be created :returns: A dictionary containing the VLAN firewall order """ package = self.get_dedicated_package(ha_enabled) product_order = { 'complexType': 'SoftLayer_Container_Product_Order_Network_' 'Protection_Firewall_Dedicated', 'quantity': 1, 'packageId': 0, 'vlanId': vlan_id, 'prices': [{'id': package[0]['prices'][0]['id']}] } return self.client['Product_Order'].placeOrder(product_order)
[ "def", "add_vlan_firewall", "(", "self", ",", "vlan_id", ",", "ha_enabled", "=", "False", ")", ":", "package", "=", "self", ".", "get_dedicated_package", "(", "ha_enabled", ")", "product_order", "=", "{", "'complexType'", ":", "'SoftLayer_Container_Product_Order_Network_'", "'Protection_Firewall_Dedicated'", ",", "'quantity'", ":", "1", ",", "'packageId'", ":", "0", ",", "'vlanId'", ":", "vlan_id", ",", "'prices'", ":", "[", "{", "'id'", ":", "package", "[", "0", "]", "[", "'prices'", "]", "[", "0", "]", "[", "'id'", "]", "}", "]", "}", "return", "self", ".", "client", "[", "'Product_Order'", "]", ".", "placeOrder", "(", "product_order", ")" ]
Creates a firewall for the specified vlan. :param int vlan_id: The ID of the vlan to create the firewall for :param bool ha_enabled: If True, an HA firewall will be created :returns: A dictionary containing the VLAN firewall order
[ "Creates", "a", "firewall", "for", "the", "specified", "vlan", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L125-L143
train
234,491
softlayer/softlayer-python
SoftLayer/managers/firewall.py
FirewallManager._get_fwl_billing_item
def _get_fwl_billing_item(self, firewall_id, dedicated=False): """Retrieves the billing item of the firewall. :param int firewall_id: Firewall ID to get the billing item for :param bool dedicated: whether the firewall is dedicated or standard :returns: A dictionary of the firewall billing item. """ mask = 'mask[id,billingItem[id]]' if dedicated: firewall_service = self.client['Network_Vlan_Firewall'] else: firewall_service = self.client['Network_Component_Firewall'] firewall = firewall_service.getObject(id=firewall_id, mask=mask) if firewall is None: raise exceptions.SoftLayerError( "Unable to find firewall %d" % firewall_id) if firewall.get('billingItem') is None: raise exceptions.SoftLayerError( "Unable to find billing item for firewall %d" % firewall_id) return firewall['billingItem']
python
def _get_fwl_billing_item(self, firewall_id, dedicated=False): """Retrieves the billing item of the firewall. :param int firewall_id: Firewall ID to get the billing item for :param bool dedicated: whether the firewall is dedicated or standard :returns: A dictionary of the firewall billing item. """ mask = 'mask[id,billingItem[id]]' if dedicated: firewall_service = self.client['Network_Vlan_Firewall'] else: firewall_service = self.client['Network_Component_Firewall'] firewall = firewall_service.getObject(id=firewall_id, mask=mask) if firewall is None: raise exceptions.SoftLayerError( "Unable to find firewall %d" % firewall_id) if firewall.get('billingItem') is None: raise exceptions.SoftLayerError( "Unable to find billing item for firewall %d" % firewall_id) return firewall['billingItem']
[ "def", "_get_fwl_billing_item", "(", "self", ",", "firewall_id", ",", "dedicated", "=", "False", ")", ":", "mask", "=", "'mask[id,billingItem[id]]'", "if", "dedicated", ":", "firewall_service", "=", "self", ".", "client", "[", "'Network_Vlan_Firewall'", "]", "else", ":", "firewall_service", "=", "self", ".", "client", "[", "'Network_Component_Firewall'", "]", "firewall", "=", "firewall_service", ".", "getObject", "(", "id", "=", "firewall_id", ",", "mask", "=", "mask", ")", "if", "firewall", "is", "None", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "\"Unable to find firewall %d\"", "%", "firewall_id", ")", "if", "firewall", ".", "get", "(", "'billingItem'", ")", "is", "None", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "\"Unable to find billing item for firewall %d\"", "%", "firewall_id", ")", "return", "firewall", "[", "'billingItem'", "]" ]
Retrieves the billing item of the firewall. :param int firewall_id: Firewall ID to get the billing item for :param bool dedicated: whether the firewall is dedicated or standard :returns: A dictionary of the firewall billing item.
[ "Retrieves", "the", "billing", "item", "of", "the", "firewall", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L145-L166
train
234,492
softlayer/softlayer-python
SoftLayer/managers/firewall.py
FirewallManager._get_fwl_port_speed
def _get_fwl_port_speed(self, server_id, is_virt=True): """Determines the appropriate speed for a firewall. :param int server_id: The ID of server the firewall is for :param bool is_virt: True if the server_id is for a virtual server :returns: a integer representing the Mbps speed of a firewall """ fwl_port_speed = 0 if is_virt: mask = ('primaryNetworkComponent[maxSpeed]') svc = self.client['Virtual_Guest'] primary = svc.getObject(mask=mask, id=server_id) fwl_port_speed = primary['primaryNetworkComponent']['maxSpeed'] else: mask = ('id,maxSpeed,networkComponentGroup.networkComponents') svc = self.client['Hardware_Server'] network_components = svc.getFrontendNetworkComponents( mask=mask, id=server_id) grouped = [interface['networkComponentGroup']['networkComponents'] for interface in network_components if 'networkComponentGroup' in interface] ungrouped = [interface for interface in network_components if 'networkComponentGroup' not in interface] # For each group, sum the maxSpeeds of each compoment in the # group. Put the sum for each in a new list group_speeds = [] for group in grouped: group_speed = 0 for interface in group: group_speed += interface['maxSpeed'] group_speeds.append(group_speed) # The max speed of all groups is the max of the list max_grouped_speed = max(group_speeds) max_ungrouped = 0 for interface in ungrouped: max_ungrouped = max(max_ungrouped, interface['maxSpeed']) fwl_port_speed = max(max_grouped_speed, max_ungrouped) return fwl_port_speed
python
def _get_fwl_port_speed(self, server_id, is_virt=True): """Determines the appropriate speed for a firewall. :param int server_id: The ID of server the firewall is for :param bool is_virt: True if the server_id is for a virtual server :returns: a integer representing the Mbps speed of a firewall """ fwl_port_speed = 0 if is_virt: mask = ('primaryNetworkComponent[maxSpeed]') svc = self.client['Virtual_Guest'] primary = svc.getObject(mask=mask, id=server_id) fwl_port_speed = primary['primaryNetworkComponent']['maxSpeed'] else: mask = ('id,maxSpeed,networkComponentGroup.networkComponents') svc = self.client['Hardware_Server'] network_components = svc.getFrontendNetworkComponents( mask=mask, id=server_id) grouped = [interface['networkComponentGroup']['networkComponents'] for interface in network_components if 'networkComponentGroup' in interface] ungrouped = [interface for interface in network_components if 'networkComponentGroup' not in interface] # For each group, sum the maxSpeeds of each compoment in the # group. Put the sum for each in a new list group_speeds = [] for group in grouped: group_speed = 0 for interface in group: group_speed += interface['maxSpeed'] group_speeds.append(group_speed) # The max speed of all groups is the max of the list max_grouped_speed = max(group_speeds) max_ungrouped = 0 for interface in ungrouped: max_ungrouped = max(max_ungrouped, interface['maxSpeed']) fwl_port_speed = max(max_grouped_speed, max_ungrouped) return fwl_port_speed
[ "def", "_get_fwl_port_speed", "(", "self", ",", "server_id", ",", "is_virt", "=", "True", ")", ":", "fwl_port_speed", "=", "0", "if", "is_virt", ":", "mask", "=", "(", "'primaryNetworkComponent[maxSpeed]'", ")", "svc", "=", "self", ".", "client", "[", "'Virtual_Guest'", "]", "primary", "=", "svc", ".", "getObject", "(", "mask", "=", "mask", ",", "id", "=", "server_id", ")", "fwl_port_speed", "=", "primary", "[", "'primaryNetworkComponent'", "]", "[", "'maxSpeed'", "]", "else", ":", "mask", "=", "(", "'id,maxSpeed,networkComponentGroup.networkComponents'", ")", "svc", "=", "self", ".", "client", "[", "'Hardware_Server'", "]", "network_components", "=", "svc", ".", "getFrontendNetworkComponents", "(", "mask", "=", "mask", ",", "id", "=", "server_id", ")", "grouped", "=", "[", "interface", "[", "'networkComponentGroup'", "]", "[", "'networkComponents'", "]", "for", "interface", "in", "network_components", "if", "'networkComponentGroup'", "in", "interface", "]", "ungrouped", "=", "[", "interface", "for", "interface", "in", "network_components", "if", "'networkComponentGroup'", "not", "in", "interface", "]", "# For each group, sum the maxSpeeds of each compoment in the", "# group. Put the sum for each in a new list", "group_speeds", "=", "[", "]", "for", "group", "in", "grouped", ":", "group_speed", "=", "0", "for", "interface", "in", "group", ":", "group_speed", "+=", "interface", "[", "'maxSpeed'", "]", "group_speeds", ".", "append", "(", "group_speed", ")", "# The max speed of all groups is the max of the list", "max_grouped_speed", "=", "max", "(", "group_speeds", ")", "max_ungrouped", "=", "0", "for", "interface", "in", "ungrouped", ":", "max_ungrouped", "=", "max", "(", "max_ungrouped", ",", "interface", "[", "'maxSpeed'", "]", ")", "fwl_port_speed", "=", "max", "(", "max_grouped_speed", ",", "max_ungrouped", ")", "return", "fwl_port_speed" ]
Determines the appropriate speed for a firewall. :param int server_id: The ID of server the firewall is for :param bool is_virt: True if the server_id is for a virtual server :returns: a integer representing the Mbps speed of a firewall
[ "Determines", "the", "appropriate", "speed", "for", "a", "firewall", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L168-L212
train
234,493
softlayer/softlayer-python
SoftLayer/managers/firewall.py
FirewallManager.get_firewalls
def get_firewalls(self): """Returns a list of all firewalls on the account. :returns: A list of firewalls on the current account. """ mask = ('firewallNetworkComponents,' 'networkVlanFirewall,' 'dedicatedFirewallFlag,' 'firewallGuestNetworkComponents,' 'firewallInterfaces,' 'firewallRules,' 'highAvailabilityFirewallFlag') return [firewall for firewall in self.account.getNetworkVlans(mask=mask) if has_firewall(firewall)]
python
def get_firewalls(self): """Returns a list of all firewalls on the account. :returns: A list of firewalls on the current account. """ mask = ('firewallNetworkComponents,' 'networkVlanFirewall,' 'dedicatedFirewallFlag,' 'firewallGuestNetworkComponents,' 'firewallInterfaces,' 'firewallRules,' 'highAvailabilityFirewallFlag') return [firewall for firewall in self.account.getNetworkVlans(mask=mask) if has_firewall(firewall)]
[ "def", "get_firewalls", "(", "self", ")", ":", "mask", "=", "(", "'firewallNetworkComponents,'", "'networkVlanFirewall,'", "'dedicatedFirewallFlag,'", "'firewallGuestNetworkComponents,'", "'firewallInterfaces,'", "'firewallRules,'", "'highAvailabilityFirewallFlag'", ")", "return", "[", "firewall", "for", "firewall", "in", "self", ".", "account", ".", "getNetworkVlans", "(", "mask", "=", "mask", ")", "if", "has_firewall", "(", "firewall", ")", "]" ]
Returns a list of all firewalls on the account. :returns: A list of firewalls on the current account.
[ "Returns", "a", "list", "of", "all", "firewalls", "on", "the", "account", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L214-L230
train
234,494
softlayer/softlayer-python
SoftLayer/managers/firewall.py
FirewallManager.get_standard_fwl_rules
def get_standard_fwl_rules(self, firewall_id): """Get the rules of a standard firewall. :param integer firewall_id: the instance ID of the standard firewall :returns: A list of the rules. """ svc = self.client['Network_Component_Firewall'] return svc.getRules(id=firewall_id, mask=RULE_MASK)
python
def get_standard_fwl_rules(self, firewall_id): """Get the rules of a standard firewall. :param integer firewall_id: the instance ID of the standard firewall :returns: A list of the rules. """ svc = self.client['Network_Component_Firewall'] return svc.getRules(id=firewall_id, mask=RULE_MASK)
[ "def", "get_standard_fwl_rules", "(", "self", ",", "firewall_id", ")", ":", "svc", "=", "self", ".", "client", "[", "'Network_Component_Firewall'", "]", "return", "svc", ".", "getRules", "(", "id", "=", "firewall_id", ",", "mask", "=", "RULE_MASK", ")" ]
Get the rules of a standard firewall. :param integer firewall_id: the instance ID of the standard firewall :returns: A list of the rules.
[ "Get", "the", "rules", "of", "a", "standard", "firewall", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L232-L240
train
234,495
softlayer/softlayer-python
SoftLayer/managers/firewall.py
FirewallManager.edit_dedicated_fwl_rules
def edit_dedicated_fwl_rules(self, firewall_id, rules): """Edit the rules for dedicated firewall. :param integer firewall_id: the instance ID of the dedicated firewall :param list rules: the rules to be pushed on the firewall as defined by SoftLayer_Network_Firewall_Update_Request_Rule """ mask = ('mask[networkVlan[firewallInterfaces' '[firewallContextAccessControlLists]]]') svc = self.client['Network_Vlan_Firewall'] fwl = svc.getObject(id=firewall_id, mask=mask) network_vlan = fwl['networkVlan'] for fwl1 in network_vlan['firewallInterfaces']: if fwl1['name'] == 'inside': continue for control_list in fwl1['firewallContextAccessControlLists']: if control_list['direction'] == 'out': continue fwl_ctx_acl_id = control_list['id'] template = {'firewallContextAccessControlListId': fwl_ctx_acl_id, 'rules': rules} svc = self.client['Network_Firewall_Update_Request'] return svc.createObject(template)
python
def edit_dedicated_fwl_rules(self, firewall_id, rules): """Edit the rules for dedicated firewall. :param integer firewall_id: the instance ID of the dedicated firewall :param list rules: the rules to be pushed on the firewall as defined by SoftLayer_Network_Firewall_Update_Request_Rule """ mask = ('mask[networkVlan[firewallInterfaces' '[firewallContextAccessControlLists]]]') svc = self.client['Network_Vlan_Firewall'] fwl = svc.getObject(id=firewall_id, mask=mask) network_vlan = fwl['networkVlan'] for fwl1 in network_vlan['firewallInterfaces']: if fwl1['name'] == 'inside': continue for control_list in fwl1['firewallContextAccessControlLists']: if control_list['direction'] == 'out': continue fwl_ctx_acl_id = control_list['id'] template = {'firewallContextAccessControlListId': fwl_ctx_acl_id, 'rules': rules} svc = self.client['Network_Firewall_Update_Request'] return svc.createObject(template)
[ "def", "edit_dedicated_fwl_rules", "(", "self", ",", "firewall_id", ",", "rules", ")", ":", "mask", "=", "(", "'mask[networkVlan[firewallInterfaces'", "'[firewallContextAccessControlLists]]]'", ")", "svc", "=", "self", ".", "client", "[", "'Network_Vlan_Firewall'", "]", "fwl", "=", "svc", ".", "getObject", "(", "id", "=", "firewall_id", ",", "mask", "=", "mask", ")", "network_vlan", "=", "fwl", "[", "'networkVlan'", "]", "for", "fwl1", "in", "network_vlan", "[", "'firewallInterfaces'", "]", ":", "if", "fwl1", "[", "'name'", "]", "==", "'inside'", ":", "continue", "for", "control_list", "in", "fwl1", "[", "'firewallContextAccessControlLists'", "]", ":", "if", "control_list", "[", "'direction'", "]", "==", "'out'", ":", "continue", "fwl_ctx_acl_id", "=", "control_list", "[", "'id'", "]", "template", "=", "{", "'firewallContextAccessControlListId'", ":", "fwl_ctx_acl_id", ",", "'rules'", ":", "rules", "}", "svc", "=", "self", ".", "client", "[", "'Network_Firewall_Update_Request'", "]", "return", "svc", ".", "createObject", "(", "template", ")" ]
Edit the rules for dedicated firewall. :param integer firewall_id: the instance ID of the dedicated firewall :param list rules: the rules to be pushed on the firewall as defined by SoftLayer_Network_Firewall_Update_Request_Rule
[ "Edit", "the", "rules", "for", "dedicated", "firewall", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L252-L279
train
234,496
softlayer/softlayer-python
SoftLayer/managers/firewall.py
FirewallManager.edit_standard_fwl_rules
def edit_standard_fwl_rules(self, firewall_id, rules): """Edit the rules for standard firewall. :param integer firewall_id: the instance ID of the standard firewall :param dict rules: the rules to be pushed on the firewall """ rule_svc = self.client['Network_Firewall_Update_Request'] template = {'networkComponentFirewallId': firewall_id, 'rules': rules} return rule_svc.createObject(template)
python
def edit_standard_fwl_rules(self, firewall_id, rules): """Edit the rules for standard firewall. :param integer firewall_id: the instance ID of the standard firewall :param dict rules: the rules to be pushed on the firewall """ rule_svc = self.client['Network_Firewall_Update_Request'] template = {'networkComponentFirewallId': firewall_id, 'rules': rules} return rule_svc.createObject(template)
[ "def", "edit_standard_fwl_rules", "(", "self", ",", "firewall_id", ",", "rules", ")", ":", "rule_svc", "=", "self", ".", "client", "[", "'Network_Firewall_Update_Request'", "]", "template", "=", "{", "'networkComponentFirewallId'", ":", "firewall_id", ",", "'rules'", ":", "rules", "}", "return", "rule_svc", ".", "createObject", "(", "template", ")" ]
Edit the rules for standard firewall. :param integer firewall_id: the instance ID of the standard firewall :param dict rules: the rules to be pushed on the firewall
[ "Edit", "the", "rules", "for", "standard", "firewall", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/firewall.py#L281-L291
train
234,497
softlayer/softlayer-python
SoftLayer/CLI/image/edit.py
cli
def cli(env, identifier, name, note, tag): """Edit details of an image.""" image_mgr = SoftLayer.ImageManager(env.client) data = {} if name: data['name'] = name if note: data['note'] = note if tag: data['tag'] = tag image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image') if not image_mgr.edit(image_id, **data): raise exceptions.CLIAbort("Failed to Edit Image")
python
def cli(env, identifier, name, note, tag): """Edit details of an image.""" image_mgr = SoftLayer.ImageManager(env.client) data = {} if name: data['name'] = name if note: data['note'] = note if tag: data['tag'] = tag image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image') if not image_mgr.edit(image_id, **data): raise exceptions.CLIAbort("Failed to Edit Image")
[ "def", "cli", "(", "env", ",", "identifier", ",", "name", ",", "note", ",", "tag", ")", ":", "image_mgr", "=", "SoftLayer", ".", "ImageManager", "(", "env", ".", "client", ")", "data", "=", "{", "}", "if", "name", ":", "data", "[", "'name'", "]", "=", "name", "if", "note", ":", "data", "[", "'note'", "]", "=", "note", "if", "tag", ":", "data", "[", "'tag'", "]", "=", "tag", "image_id", "=", "helpers", ".", "resolve_id", "(", "image_mgr", ".", "resolve_ids", ",", "identifier", ",", "'image'", ")", "if", "not", "image_mgr", ".", "edit", "(", "image_id", ",", "*", "*", "data", ")", ":", "raise", "exceptions", ".", "CLIAbort", "(", "\"Failed to Edit Image\"", ")" ]
Edit details of an image.
[ "Edit", "details", "of", "an", "image", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/image/edit.py#L18-L31
train
234,498
softlayer/softlayer-python
SoftLayer/CLI/ticket/attach.py
cli
def cli(env, identifier, hardware_identifier, virtual_identifier): """Attach devices to a ticket.""" ticket_mgr = SoftLayer.TicketManager(env.client) if hardware_identifier and virtual_identifier: raise exceptions.ArgumentError("Cannot attach hardware and a virtual server at the same time") if hardware_identifier: hardware_mgr = SoftLayer.HardwareManager(env.client) hardware_id = helpers.resolve_id(hardware_mgr.resolve_ids, hardware_identifier, 'hardware') ticket_mgr.attach_hardware(identifier, hardware_id) elif virtual_identifier: vs_mgr = SoftLayer.VSManager(env.client) vs_id = helpers.resolve_id(vs_mgr.resolve_ids, virtual_identifier, 'VS') ticket_mgr.attach_virtual_server(identifier, vs_id) else: raise exceptions.ArgumentError("Must have a hardware or virtual server identifier to attach")
python
def cli(env, identifier, hardware_identifier, virtual_identifier): """Attach devices to a ticket.""" ticket_mgr = SoftLayer.TicketManager(env.client) if hardware_identifier and virtual_identifier: raise exceptions.ArgumentError("Cannot attach hardware and a virtual server at the same time") if hardware_identifier: hardware_mgr = SoftLayer.HardwareManager(env.client) hardware_id = helpers.resolve_id(hardware_mgr.resolve_ids, hardware_identifier, 'hardware') ticket_mgr.attach_hardware(identifier, hardware_id) elif virtual_identifier: vs_mgr = SoftLayer.VSManager(env.client) vs_id = helpers.resolve_id(vs_mgr.resolve_ids, virtual_identifier, 'VS') ticket_mgr.attach_virtual_server(identifier, vs_id) else: raise exceptions.ArgumentError("Must have a hardware or virtual server identifier to attach")
[ "def", "cli", "(", "env", ",", "identifier", ",", "hardware_identifier", ",", "virtual_identifier", ")", ":", "ticket_mgr", "=", "SoftLayer", ".", "TicketManager", "(", "env", ".", "client", ")", "if", "hardware_identifier", "and", "virtual_identifier", ":", "raise", "exceptions", ".", "ArgumentError", "(", "\"Cannot attach hardware and a virtual server at the same time\"", ")", "if", "hardware_identifier", ":", "hardware_mgr", "=", "SoftLayer", ".", "HardwareManager", "(", "env", ".", "client", ")", "hardware_id", "=", "helpers", ".", "resolve_id", "(", "hardware_mgr", ".", "resolve_ids", ",", "hardware_identifier", ",", "'hardware'", ")", "ticket_mgr", ".", "attach_hardware", "(", "identifier", ",", "hardware_id", ")", "elif", "virtual_identifier", ":", "vs_mgr", "=", "SoftLayer", ".", "VSManager", "(", "env", ".", "client", ")", "vs_id", "=", "helpers", ".", "resolve_id", "(", "vs_mgr", ".", "resolve_ids", ",", "virtual_identifier", ",", "'VS'", ")", "ticket_mgr", ".", "attach_virtual_server", "(", "identifier", ",", "vs_id", ")", "else", ":", "raise", "exceptions", ".", "ArgumentError", "(", "\"Must have a hardware or virtual server identifier to attach\"", ")" ]
Attach devices to a ticket.
[ "Attach", "devices", "to", "a", "ticket", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/ticket/attach.py#L19-L35
train
234,499