id
int32
0
252k
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
sequence
docstring
stringlengths
3
17.3k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
87
242
1,600
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
1,601
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
1,602
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
1,603
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
1,604
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
1,605
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
1,606
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
1,607
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
1,608
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
1,609
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
1,610
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
1,611
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
1,612
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
1,613
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
1,614
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
1,615
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
1,616
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
1,617
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
1,618
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
1,619
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
1,620
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
1,621
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
1,622
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
1,623
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
1,624
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
1,625
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
1,626
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
1,627
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
1,628
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
1,629
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
1,630
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
1,631
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
1,632
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
1,633
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
1,634
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
1,635
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
1,636
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
1,637
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
1,638
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
1,639
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
1,640
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
1,641
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
1,642
softlayer/softlayer-python
SoftLayer/managers/metadata.py
MetadataManager.get
def get(self, name, param=None): """Retreive a metadata attribute. :param string name: name of the attribute to retrieve. See `attribs` :param param: Required parameter for some attributes """ if name not in self.attribs: raise exceptions.SoftLayerError('Unknown metadata attribute.') call_details = self.attribs[name] if call_details.get('param_req'): if not param: raise exceptions.SoftLayerError( 'Parameter required to get this attribute.') params = tuple() if param is not None: params = (param,) try: return self.client.call('Resource_Metadata', self.attribs[name]['call'], *params) except exceptions.SoftLayerAPIError as ex: if ex.faultCode == 404: return None raise ex
python
def get(self, name, param=None): """Retreive a metadata attribute. :param string name: name of the attribute to retrieve. See `attribs` :param param: Required parameter for some attributes """ if name not in self.attribs: raise exceptions.SoftLayerError('Unknown metadata attribute.') call_details = self.attribs[name] if call_details.get('param_req'): if not param: raise exceptions.SoftLayerError( 'Parameter required to get this attribute.') params = tuple() if param is not None: params = (param,) try: return self.client.call('Resource_Metadata', self.attribs[name]['call'], *params) except exceptions.SoftLayerAPIError as ex: if ex.faultCode == 404: return None raise ex
[ "def", "get", "(", "self", ",", "name", ",", "param", "=", "None", ")", ":", "if", "name", "not", "in", "self", ".", "attribs", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "'Unknown metadata attribute.'", ")", "call_details", "=", "self", ".", "attribs", "[", "name", "]", "if", "call_details", ".", "get", "(", "'param_req'", ")", ":", "if", "not", "param", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "'Parameter required to get this attribute.'", ")", "params", "=", "tuple", "(", ")", "if", "param", "is", "not", "None", ":", "params", "=", "(", "param", ",", ")", "try", ":", "return", "self", ".", "client", ".", "call", "(", "'Resource_Metadata'", ",", "self", ".", "attribs", "[", "name", "]", "[", "'call'", "]", ",", "*", "params", ")", "except", "exceptions", ".", "SoftLayerAPIError", "as", "ex", ":", "if", "ex", ".", "faultCode", "==", "404", ":", "return", "None", "raise", "ex" ]
Retreive a metadata attribute. :param string name: name of the attribute to retrieve. See `attribs` :param param: Required parameter for some attributes
[ "Retreive", "a", "metadata", "attribute", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/metadata.py#L73-L100
1,643
softlayer/softlayer-python
SoftLayer/managers/metadata.py
MetadataManager._get_network
def _get_network(self, kind, router=True, vlans=True, vlan_ids=True): """Wrapper for getting details about networks. :param string kind: network kind. Typically 'public' or 'private' :param boolean router: flag to include router information :param boolean vlans: flag to include vlan information :param boolean vlan_ids: flag to include vlan_ids """ network = {} macs = self.get('%s_mac' % kind) network['mac_addresses'] = macs if len(macs) == 0: return network if router: network['router'] = self.get('router', macs[0]) if vlans: network['vlans'] = self.get('vlans', macs[0]) if vlan_ids: network['vlan_ids'] = self.get('vlan_ids', macs[0]) return network
python
def _get_network(self, kind, router=True, vlans=True, vlan_ids=True): """Wrapper for getting details about networks. :param string kind: network kind. Typically 'public' or 'private' :param boolean router: flag to include router information :param boolean vlans: flag to include vlan information :param boolean vlan_ids: flag to include vlan_ids """ network = {} macs = self.get('%s_mac' % kind) network['mac_addresses'] = macs if len(macs) == 0: return network if router: network['router'] = self.get('router', macs[0]) if vlans: network['vlans'] = self.get('vlans', macs[0]) if vlan_ids: network['vlan_ids'] = self.get('vlan_ids', macs[0]) return network
[ "def", "_get_network", "(", "self", ",", "kind", ",", "router", "=", "True", ",", "vlans", "=", "True", ",", "vlan_ids", "=", "True", ")", ":", "network", "=", "{", "}", "macs", "=", "self", ".", "get", "(", "'%s_mac'", "%", "kind", ")", "network", "[", "'mac_addresses'", "]", "=", "macs", "if", "len", "(", "macs", ")", "==", "0", ":", "return", "network", "if", "router", ":", "network", "[", "'router'", "]", "=", "self", ".", "get", "(", "'router'", ",", "macs", "[", "0", "]", ")", "if", "vlans", ":", "network", "[", "'vlans'", "]", "=", "self", ".", "get", "(", "'vlans'", ",", "macs", "[", "0", "]", ")", "if", "vlan_ids", ":", "network", "[", "'vlan_ids'", "]", "=", "self", ".", "get", "(", "'vlan_ids'", ",", "macs", "[", "0", "]", ")", "return", "network" ]
Wrapper for getting details about networks. :param string kind: network kind. Typically 'public' or 'private' :param boolean router: flag to include router information :param boolean vlans: flag to include vlan information :param boolean vlan_ids: flag to include vlan_ids
[ "Wrapper", "for", "getting", "details", "about", "networks", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/metadata.py#L102-L127
1,644
softlayer/softlayer-python
SoftLayer/shell/cmd_env.py
cli
def cli(env): """Print environment variables.""" filtered_vars = dict([(k, v) for k, v in env.vars.items() if not k.startswith('_')]) env.fout(formatting.iter_to_table(filtered_vars))
python
def cli(env): """Print environment variables.""" filtered_vars = dict([(k, v) for k, v in env.vars.items() if not k.startswith('_')]) env.fout(formatting.iter_to_table(filtered_vars))
[ "def", "cli", "(", "env", ")", ":", "filtered_vars", "=", "dict", "(", "[", "(", "k", ",", "v", ")", "for", "k", ",", "v", "in", "env", ".", "vars", ".", "items", "(", ")", "if", "not", "k", ".", "startswith", "(", "'_'", ")", "]", ")", "env", ".", "fout", "(", "formatting", ".", "iter_to_table", "(", "filtered_vars", ")", ")" ]
Print environment variables.
[ "Print", "environment", "variables", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/shell/cmd_env.py#L12-L17
1,645
softlayer/softlayer-python
SoftLayer/CLI/block/snapshot/restore.py
cli
def cli(env, volume_id, snapshot_id): """Restore block volume using a given snapshot""" block_manager = SoftLayer.BlockStorageManager(env.client) success = block_manager.restore_from_snapshot(volume_id, snapshot_id) if success: click.echo('Block volume %s is being restored using snapshot %s' % (volume_id, snapshot_id))
python
def cli(env, volume_id, snapshot_id): """Restore block volume using a given snapshot""" block_manager = SoftLayer.BlockStorageManager(env.client) success = block_manager.restore_from_snapshot(volume_id, snapshot_id) if success: click.echo('Block volume %s is being restored using snapshot %s' % (volume_id, snapshot_id))
[ "def", "cli", "(", "env", ",", "volume_id", ",", "snapshot_id", ")", ":", "block_manager", "=", "SoftLayer", ".", "BlockStorageManager", "(", "env", ".", "client", ")", "success", "=", "block_manager", ".", "restore_from_snapshot", "(", "volume_id", ",", "snapshot_id", ")", "if", "success", ":", "click", ".", "echo", "(", "'Block volume %s is being restored using snapshot %s'", "%", "(", "volume_id", ",", "snapshot_id", ")", ")" ]
Restore block volume using a given snapshot
[ "Restore", "block", "volume", "using", "a", "given", "snapshot" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/block/snapshot/restore.py#L15-L22
1,646
softlayer/softlayer-python
SoftLayer/CLI/ssl/add.py
cli
def cli(env, crt, csr, icc, key, notes): """Add and upload SSL certificate details.""" template = { 'intermediateCertificate': '', 'certificateSigningRequest': '', 'notes': notes, } template['certificate'] = open(crt).read() template['privateKey'] = open(key).read() if csr: body = open(csr).read() template['certificateSigningRequest'] = body if icc: body = open(icc).read() template['intermediateCertificate'] = body manager = SoftLayer.SSLManager(env.client) manager.add_certificate(template)
python
def cli(env, crt, csr, icc, key, notes): """Add and upload SSL certificate details.""" template = { 'intermediateCertificate': '', 'certificateSigningRequest': '', 'notes': notes, } template['certificate'] = open(crt).read() template['privateKey'] = open(key).read() if csr: body = open(csr).read() template['certificateSigningRequest'] = body if icc: body = open(icc).read() template['intermediateCertificate'] = body manager = SoftLayer.SSLManager(env.client) manager.add_certificate(template)
[ "def", "cli", "(", "env", ",", "crt", ",", "csr", ",", "icc", ",", "key", ",", "notes", ")", ":", "template", "=", "{", "'intermediateCertificate'", ":", "''", ",", "'certificateSigningRequest'", ":", "''", ",", "'notes'", ":", "notes", ",", "}", "template", "[", "'certificate'", "]", "=", "open", "(", "crt", ")", ".", "read", "(", ")", "template", "[", "'privateKey'", "]", "=", "open", "(", "key", ")", ".", "read", "(", ")", "if", "csr", ":", "body", "=", "open", "(", "csr", ")", ".", "read", "(", ")", "template", "[", "'certificateSigningRequest'", "]", "=", "body", "if", "icc", ":", "body", "=", "open", "(", "icc", ")", ".", "read", "(", ")", "template", "[", "'intermediateCertificate'", "]", "=", "body", "manager", "=", "SoftLayer", ".", "SSLManager", "(", "env", ".", "client", ")", "manager", ".", "add_certificate", "(", "template", ")" ]
Add and upload SSL certificate details.
[ "Add", "and", "upload", "SSL", "certificate", "details", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/ssl/add.py#L23-L42
1,647
softlayer/softlayer-python
SoftLayer/CLI/image/export.py
cli
def cli(env, identifier, uri, ibm_api_key): """Export an image to object storage. The URI for an object storage object (.vhd/.iso file) of the format: swift://<objectStorageAccount>@<cluster>/<container>/<objectPath> or cos://<regionName>/<bucketName>/<objectPath> if using IBM Cloud Object Storage """ image_mgr = SoftLayer.ImageManager(env.client) image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image') result = image_mgr.export_image_to_uri(image_id, uri, ibm_api_key) if not result: raise exceptions.CLIAbort("Failed to export Image")
python
def cli(env, identifier, uri, ibm_api_key): """Export an image to object storage. The URI for an object storage object (.vhd/.iso file) of the format: swift://<objectStorageAccount>@<cluster>/<container>/<objectPath> or cos://<regionName>/<bucketName>/<objectPath> if using IBM Cloud Object Storage """ image_mgr = SoftLayer.ImageManager(env.client) image_id = helpers.resolve_id(image_mgr.resolve_ids, identifier, 'image') result = image_mgr.export_image_to_uri(image_id, uri, ibm_api_key) if not result: raise exceptions.CLIAbort("Failed to export Image")
[ "def", "cli", "(", "env", ",", "identifier", ",", "uri", ",", "ibm_api_key", ")", ":", "image_mgr", "=", "SoftLayer", ".", "ImageManager", "(", "env", ".", "client", ")", "image_id", "=", "helpers", ".", "resolve_id", "(", "image_mgr", ".", "resolve_ids", ",", "identifier", ",", "'image'", ")", "result", "=", "image_mgr", ".", "export_image_to_uri", "(", "image_id", ",", "uri", ",", "ibm_api_key", ")", "if", "not", "result", ":", "raise", "exceptions", ".", "CLIAbort", "(", "\"Failed to export Image\"", ")" ]
Export an image to object storage. The URI for an object storage object (.vhd/.iso file) of the format: swift://<objectStorageAccount>@<cluster>/<container>/<objectPath> or cos://<regionName>/<bucketName>/<objectPath> if using IBM Cloud Object Storage
[ "Export", "an", "image", "to", "object", "storage", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/image/export.py#L22-L36
1,648
softlayer/softlayer-python
SoftLayer/CLI/virt/__init__.py
MemoryType.convert
def convert(self, value, param, ctx): # pylint: disable=inconsistent-return-statements """Validate memory argument. Returns the memory value in megabytes.""" matches = MEMORY_RE.match(value.lower()) if matches is None: self.fail('%s is not a valid value for memory amount' % value, param, ctx) amount_str, unit = matches.groups() amount = int(amount_str) if unit in [None, 'm', 'mb']: # Assume the user intends gigabytes if they specify a number < 1024 if amount < 1024: return amount * 1024 else: if amount % 1024 != 0: self.fail('%s is not an integer that is divisable by 1024' % value, param, ctx) return amount elif unit in ['g', 'gb']: return amount * 1024
python
def convert(self, value, param, ctx): # pylint: disable=inconsistent-return-statements """Validate memory argument. Returns the memory value in megabytes.""" matches = MEMORY_RE.match(value.lower()) if matches is None: self.fail('%s is not a valid value for memory amount' % value, param, ctx) amount_str, unit = matches.groups() amount = int(amount_str) if unit in [None, 'm', 'mb']: # Assume the user intends gigabytes if they specify a number < 1024 if amount < 1024: return amount * 1024 else: if amount % 1024 != 0: self.fail('%s is not an integer that is divisable by 1024' % value, param, ctx) return amount elif unit in ['g', 'gb']: return amount * 1024
[ "def", "convert", "(", "self", ",", "value", ",", "param", ",", "ctx", ")", ":", "# pylint: disable=inconsistent-return-statements", "matches", "=", "MEMORY_RE", ".", "match", "(", "value", ".", "lower", "(", ")", ")", "if", "matches", "is", "None", ":", "self", ".", "fail", "(", "'%s is not a valid value for memory amount'", "%", "value", ",", "param", ",", "ctx", ")", "amount_str", ",", "unit", "=", "matches", ".", "groups", "(", ")", "amount", "=", "int", "(", "amount_str", ")", "if", "unit", "in", "[", "None", ",", "'m'", ",", "'mb'", "]", ":", "# Assume the user intends gigabytes if they specify a number < 1024", "if", "amount", "<", "1024", ":", "return", "amount", "*", "1024", "else", ":", "if", "amount", "%", "1024", "!=", "0", ":", "self", ".", "fail", "(", "'%s is not an integer that is divisable by 1024'", "%", "value", ",", "param", ",", "ctx", ")", "return", "amount", "elif", "unit", "in", "[", "'g'", ",", "'gb'", "]", ":", "return", "amount", "*", "1024" ]
Validate memory argument. Returns the memory value in megabytes.
[ "Validate", "memory", "argument", ".", "Returns", "the", "memory", "value", "in", "megabytes", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/virt/__init__.py#L15-L31
1,649
softlayer/softlayer-python
SoftLayer/CLI/nas/credentials.py
cli
def cli(env, identifier): """List NAS account credentials.""" nw_mgr = SoftLayer.NetworkManager(env.client) result = nw_mgr.get_nas_credentials(identifier) table = formatting.Table(['username', 'password']) table.add_row([result.get('username', 'None'), result.get('password', 'None')]) env.fout(table)
python
def cli(env, identifier): """List NAS account credentials.""" nw_mgr = SoftLayer.NetworkManager(env.client) result = nw_mgr.get_nas_credentials(identifier) table = formatting.Table(['username', 'password']) table.add_row([result.get('username', 'None'), result.get('password', 'None')]) env.fout(table)
[ "def", "cli", "(", "env", ",", "identifier", ")", ":", "nw_mgr", "=", "SoftLayer", ".", "NetworkManager", "(", "env", ".", "client", ")", "result", "=", "nw_mgr", ".", "get_nas_credentials", "(", "identifier", ")", "table", "=", "formatting", ".", "Table", "(", "[", "'username'", ",", "'password'", "]", ")", "table", ".", "add_row", "(", "[", "result", ".", "get", "(", "'username'", ",", "'None'", ")", ",", "result", ".", "get", "(", "'password'", ",", "'None'", ")", "]", ")", "env", ".", "fout", "(", "table", ")" ]
List NAS account credentials.
[ "List", "NAS", "account", "credentials", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/nas/credentials.py#L14-L22
1,650
softlayer/softlayer-python
SoftLayer/CLI/firewall/detail.py
cli
def cli(env, identifier): """Detail firewall.""" mgr = SoftLayer.FirewallManager(env.client) firewall_type, firewall_id = firewall.parse_id(identifier) if firewall_type == 'vlan': rules = mgr.get_dedicated_fwl_rules(firewall_id) else: rules = mgr.get_standard_fwl_rules(firewall_id) env.fout(get_rules_table(rules))
python
def cli(env, identifier): """Detail firewall.""" mgr = SoftLayer.FirewallManager(env.client) firewall_type, firewall_id = firewall.parse_id(identifier) if firewall_type == 'vlan': rules = mgr.get_dedicated_fwl_rules(firewall_id) else: rules = mgr.get_standard_fwl_rules(firewall_id) env.fout(get_rules_table(rules))
[ "def", "cli", "(", "env", ",", "identifier", ")", ":", "mgr", "=", "SoftLayer", ".", "FirewallManager", "(", "env", ".", "client", ")", "firewall_type", ",", "firewall_id", "=", "firewall", ".", "parse_id", "(", "identifier", ")", "if", "firewall_type", "==", "'vlan'", ":", "rules", "=", "mgr", ".", "get_dedicated_fwl_rules", "(", "firewall_id", ")", "else", ":", "rules", "=", "mgr", ".", "get_standard_fwl_rules", "(", "firewall_id", ")", "env", ".", "fout", "(", "get_rules_table", "(", "rules", ")", ")" ]
Detail firewall.
[ "Detail", "firewall", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/firewall/detail.py#L16-L27
1,651
softlayer/softlayer-python
SoftLayer/CLI/firewall/detail.py
get_rules_table
def get_rules_table(rules): """Helper to format the rules into a table. :param list rules: A list containing the rules of the firewall :returns: a formatted table of the firewall rules """ table = formatting.Table(['#', 'action', 'protocol', 'src_ip', 'src_mask', 'dest', 'dest_mask']) table.sortby = '#' for rule in rules: table.add_row([ rule['orderValue'], rule['action'], rule['protocol'], rule['sourceIpAddress'], utils.lookup(rule, 'sourceIpSubnetMask'), '%s:%s-%s' % (rule['destinationIpAddress'], rule['destinationPortRangeStart'], rule['destinationPortRangeEnd']), utils.lookup(rule, 'destinationIpSubnetMask')]) return table
python
def get_rules_table(rules): """Helper to format the rules into a table. :param list rules: A list containing the rules of the firewall :returns: a formatted table of the firewall rules """ table = formatting.Table(['#', 'action', 'protocol', 'src_ip', 'src_mask', 'dest', 'dest_mask']) table.sortby = '#' for rule in rules: table.add_row([ rule['orderValue'], rule['action'], rule['protocol'], rule['sourceIpAddress'], utils.lookup(rule, 'sourceIpSubnetMask'), '%s:%s-%s' % (rule['destinationIpAddress'], rule['destinationPortRangeStart'], rule['destinationPortRangeEnd']), utils.lookup(rule, 'destinationIpSubnetMask')]) return table
[ "def", "get_rules_table", "(", "rules", ")", ":", "table", "=", "formatting", ".", "Table", "(", "[", "'#'", ",", "'action'", ",", "'protocol'", ",", "'src_ip'", ",", "'src_mask'", ",", "'dest'", ",", "'dest_mask'", "]", ")", "table", ".", "sortby", "=", "'#'", "for", "rule", "in", "rules", ":", "table", ".", "add_row", "(", "[", "rule", "[", "'orderValue'", "]", ",", "rule", "[", "'action'", "]", ",", "rule", "[", "'protocol'", "]", ",", "rule", "[", "'sourceIpAddress'", "]", ",", "utils", ".", "lookup", "(", "rule", ",", "'sourceIpSubnetMask'", ")", ",", "'%s:%s-%s'", "%", "(", "rule", "[", "'destinationIpAddress'", "]", ",", "rule", "[", "'destinationPortRangeStart'", "]", ",", "rule", "[", "'destinationPortRangeEnd'", "]", ")", ",", "utils", ".", "lookup", "(", "rule", ",", "'destinationIpSubnetMask'", ")", "]", ")", "return", "table" ]
Helper to format the rules into a table. :param list rules: A list containing the rules of the firewall :returns: a formatted table of the firewall rules
[ "Helper", "to", "format", "the", "rules", "into", "a", "table", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/firewall/detail.py#L30-L50
1,652
softlayer/softlayer-python
SoftLayer/managers/sshkey.py
SshKeyManager.add_key
def add_key(self, key, label, notes=None): """Adds a new SSH key to the account. :param string key: The SSH key to add :param string label: The label for the key :param string notes: Additional notes for the key :returns: A dictionary of the new key's information. """ order = { 'key': key, 'label': label, 'notes': notes, } return self.sshkey.createObject(order)
python
def add_key(self, key, label, notes=None): """Adds a new SSH key to the account. :param string key: The SSH key to add :param string label: The label for the key :param string notes: Additional notes for the key :returns: A dictionary of the new key's information. """ order = { 'key': key, 'label': label, 'notes': notes, } return self.sshkey.createObject(order)
[ "def", "add_key", "(", "self", ",", "key", ",", "label", ",", "notes", "=", "None", ")", ":", "order", "=", "{", "'key'", ":", "key", ",", "'label'", ":", "label", ",", "'notes'", ":", "notes", ",", "}", "return", "self", ".", "sshkey", ".", "createObject", "(", "order", ")" ]
Adds a new SSH key to the account. :param string key: The SSH key to add :param string label: The label for the key :param string notes: Additional notes for the key :returns: A dictionary of the new key's information.
[ "Adds", "a", "new", "SSH", "key", "to", "the", "account", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/sshkey.py#L26-L40
1,653
softlayer/softlayer-python
SoftLayer/managers/sshkey.py
SshKeyManager.edit_key
def edit_key(self, key_id, label=None, notes=None): """Edits information about an SSH key. :param int key_id: The ID of the key to edit :param string label: The new label for the key :param string notes: Notes to set or change on the key :returns: A Boolean indicating success or failure """ data = {} if label: data['label'] = label if notes: data['notes'] = notes return self.sshkey.editObject(data, id=key_id)
python
def edit_key(self, key_id, label=None, notes=None): """Edits information about an SSH key. :param int key_id: The ID of the key to edit :param string label: The new label for the key :param string notes: Notes to set or change on the key :returns: A Boolean indicating success or failure """ data = {} if label: data['label'] = label if notes: data['notes'] = notes return self.sshkey.editObject(data, id=key_id)
[ "def", "edit_key", "(", "self", ",", "key_id", ",", "label", "=", "None", ",", "notes", "=", "None", ")", ":", "data", "=", "{", "}", "if", "label", ":", "data", "[", "'label'", "]", "=", "label", "if", "notes", ":", "data", "[", "'notes'", "]", "=", "notes", "return", "self", ".", "sshkey", ".", "editObject", "(", "data", ",", "id", "=", "key_id", ")" ]
Edits information about an SSH key. :param int key_id: The ID of the key to edit :param string label: The new label for the key :param string notes: Notes to set or change on the key :returns: A Boolean indicating success or failure
[ "Edits", "information", "about", "an", "SSH", "key", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/sshkey.py#L50-L66
1,654
softlayer/softlayer-python
SoftLayer/managers/sshkey.py
SshKeyManager.list_keys
def list_keys(self, label=None): """Lists all SSH keys on the account. :param string label: Filter list based on SSH key label :returns: A list of dictionaries with information about each key """ _filter = utils.NestedDict({}) if label: _filter['sshKeys']['label'] = utils.query_filter(label) return self.client['Account'].getSshKeys(filter=_filter.to_dict())
python
def list_keys(self, label=None): """Lists all SSH keys on the account. :param string label: Filter list based on SSH key label :returns: A list of dictionaries with information about each key """ _filter = utils.NestedDict({}) if label: _filter['sshKeys']['label'] = utils.query_filter(label) return self.client['Account'].getSshKeys(filter=_filter.to_dict())
[ "def", "list_keys", "(", "self", ",", "label", "=", "None", ")", ":", "_filter", "=", "utils", ".", "NestedDict", "(", "{", "}", ")", "if", "label", ":", "_filter", "[", "'sshKeys'", "]", "[", "'label'", "]", "=", "utils", ".", "query_filter", "(", "label", ")", "return", "self", ".", "client", "[", "'Account'", "]", ".", "getSshKeys", "(", "filter", "=", "_filter", ".", "to_dict", "(", ")", ")" ]
Lists all SSH keys on the account. :param string label: Filter list based on SSH key label :returns: A list of dictionaries with information about each key
[ "Lists", "all", "SSH", "keys", "on", "the", "account", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/sshkey.py#L76-L86
1,655
softlayer/softlayer-python
SoftLayer/managers/sshkey.py
SshKeyManager._get_ids_from_label
def _get_ids_from_label(self, label): """Return sshkey IDs which match the given label.""" keys = self.list_keys() results = [] for key in keys: if key['label'] == label: results.append(key['id']) return results
python
def _get_ids_from_label(self, label): """Return sshkey IDs which match the given label.""" keys = self.list_keys() results = [] for key in keys: if key['label'] == label: results.append(key['id']) return results
[ "def", "_get_ids_from_label", "(", "self", ",", "label", ")", ":", "keys", "=", "self", ".", "list_keys", "(", ")", "results", "=", "[", "]", "for", "key", "in", "keys", ":", "if", "key", "[", "'label'", "]", "==", "label", ":", "results", ".", "append", "(", "key", "[", "'id'", "]", ")", "return", "results" ]
Return sshkey IDs which match the given label.
[ "Return", "sshkey", "IDs", "which", "match", "the", "given", "label", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/sshkey.py#L88-L95
1,656
softlayer/softlayer-python
SoftLayer/CLI/ssl/download.py
cli
def cli(env, identifier): """Download SSL certificate and key file.""" manager = SoftLayer.SSLManager(env.client) certificate = manager.get_certificate(identifier) write_cert(certificate['commonName'] + '.crt', certificate['certificate']) write_cert(certificate['commonName'] + '.key', certificate['privateKey']) if 'intermediateCertificate' in certificate: write_cert(certificate['commonName'] + '.icc', certificate['intermediateCertificate']) if 'certificateSigningRequest' in certificate: write_cert(certificate['commonName'] + '.csr', certificate['certificateSigningRequest'])
python
def cli(env, identifier): """Download SSL certificate and key file.""" manager = SoftLayer.SSLManager(env.client) certificate = manager.get_certificate(identifier) write_cert(certificate['commonName'] + '.crt', certificate['certificate']) write_cert(certificate['commonName'] + '.key', certificate['privateKey']) if 'intermediateCertificate' in certificate: write_cert(certificate['commonName'] + '.icc', certificate['intermediateCertificate']) if 'certificateSigningRequest' in certificate: write_cert(certificate['commonName'] + '.csr', certificate['certificateSigningRequest'])
[ "def", "cli", "(", "env", ",", "identifier", ")", ":", "manager", "=", "SoftLayer", ".", "SSLManager", "(", "env", ".", "client", ")", "certificate", "=", "manager", ".", "get_certificate", "(", "identifier", ")", "write_cert", "(", "certificate", "[", "'commonName'", "]", "+", "'.crt'", ",", "certificate", "[", "'certificate'", "]", ")", "write_cert", "(", "certificate", "[", "'commonName'", "]", "+", "'.key'", ",", "certificate", "[", "'privateKey'", "]", ")", "if", "'intermediateCertificate'", "in", "certificate", ":", "write_cert", "(", "certificate", "[", "'commonName'", "]", "+", "'.icc'", ",", "certificate", "[", "'intermediateCertificate'", "]", ")", "if", "'certificateSigningRequest'", "in", "certificate", ":", "write_cert", "(", "certificate", "[", "'commonName'", "]", "+", "'.csr'", ",", "certificate", "[", "'certificateSigningRequest'", "]", ")" ]
Download SSL certificate and key file.
[ "Download", "SSL", "certificate", "and", "key", "file", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/ssl/download.py#L13-L28
1,657
softlayer/softlayer-python
SoftLayer/CLI/virt/capture.py
cli
def cli(env, identifier, name, all, note): """Capture one or all disks from a virtual server to a SoftLayer image.""" vsi = SoftLayer.VSManager(env.client) vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS') capture = vsi.capture(vs_id, name, all, note) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['vs_id', capture['guestId']]) table.add_row(['date', capture['createDate'][:10]]) table.add_row(['time', capture['createDate'][11:19]]) table.add_row(['transaction', formatting.transaction_status(capture)]) table.add_row(['transaction_id', capture['id']]) table.add_row(['all_disks', all]) env.fout(table)
python
def cli(env, identifier, name, all, note): """Capture one or all disks from a virtual server to a SoftLayer image.""" vsi = SoftLayer.VSManager(env.client) vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS') capture = vsi.capture(vs_id, name, all, note) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['vs_id', capture['guestId']]) table.add_row(['date', capture['createDate'][:10]]) table.add_row(['time', capture['createDate'][11:19]]) table.add_row(['transaction', formatting.transaction_status(capture)]) table.add_row(['transaction_id', capture['id']]) table.add_row(['all_disks', all]) env.fout(table)
[ "def", "cli", "(", "env", ",", "identifier", ",", "name", ",", "all", ",", "note", ")", ":", "vsi", "=", "SoftLayer", ".", "VSManager", "(", "env", ".", "client", ")", "vs_id", "=", "helpers", ".", "resolve_id", "(", "vsi", ".", "resolve_ids", ",", "identifier", ",", "'VS'", ")", "capture", "=", "vsi", ".", "capture", "(", "vs_id", ",", "name", ",", "all", ",", "note", ")", "table", "=", "formatting", ".", "KeyValueTable", "(", "[", "'name'", ",", "'value'", "]", ")", "table", ".", "align", "[", "'name'", "]", "=", "'r'", "table", ".", "align", "[", "'value'", "]", "=", "'l'", "table", ".", "add_row", "(", "[", "'vs_id'", ",", "capture", "[", "'guestId'", "]", "]", ")", "table", ".", "add_row", "(", "[", "'date'", ",", "capture", "[", "'createDate'", "]", "[", ":", "10", "]", "]", ")", "table", ".", "add_row", "(", "[", "'time'", ",", "capture", "[", "'createDate'", "]", "[", "11", ":", "19", "]", "]", ")", "table", ".", "add_row", "(", "[", "'transaction'", ",", "formatting", ".", "transaction_status", "(", "capture", ")", "]", ")", "table", ".", "add_row", "(", "[", "'transaction_id'", ",", "capture", "[", "'id'", "]", "]", ")", "table", ".", "add_row", "(", "[", "'all_disks'", ",", "all", "]", ")", "env", ".", "fout", "(", "table", ")" ]
Capture one or all disks from a virtual server to a SoftLayer image.
[ "Capture", "one", "or", "all", "disks", "from", "a", "virtual", "server", "to", "a", "SoftLayer", "image", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/virt/capture.py#L20-L38
1,658
softlayer/softlayer-python
SoftLayer/managers/event_log.py
EventLogManager.get_event_logs
def get_event_logs(self, request_filter=None, log_limit=20, iterator=True): """Returns a list of event logs Example:: event_mgr = SoftLayer.EventLogManager(env.client) request_filter = event_mgr.build_filter(date_min="01/01/2019", date_max="02/01/2019") logs = event_mgr.get_event_logs(request_filter) for log in logs: print("Event Name: {}".format(log['eventName'])) :param dict request_filter: filter dict :param int log_limit: number of results to get in one API call :param bool iterator: False will only make one API call for log_limit results. True will keep making API calls until all logs have been retreived. There may be a lot of these. :returns: List of event logs. If iterator=True, will return a python generator object instead. """ if iterator: # Call iter_call directly as this returns the actual generator return self.client.iter_call('Event_Log', 'getAllObjects', filter=request_filter, limit=log_limit) return self.client.call('Event_Log', 'getAllObjects', filter=request_filter, limit=log_limit)
python
def get_event_logs(self, request_filter=None, log_limit=20, iterator=True): """Returns a list of event logs Example:: event_mgr = SoftLayer.EventLogManager(env.client) request_filter = event_mgr.build_filter(date_min="01/01/2019", date_max="02/01/2019") logs = event_mgr.get_event_logs(request_filter) for log in logs: print("Event Name: {}".format(log['eventName'])) :param dict request_filter: filter dict :param int log_limit: number of results to get in one API call :param bool iterator: False will only make one API call for log_limit results. True will keep making API calls until all logs have been retreived. There may be a lot of these. :returns: List of event logs. If iterator=True, will return a python generator object instead. """ if iterator: # Call iter_call directly as this returns the actual generator return self.client.iter_call('Event_Log', 'getAllObjects', filter=request_filter, limit=log_limit) return self.client.call('Event_Log', 'getAllObjects', filter=request_filter, limit=log_limit)
[ "def", "get_event_logs", "(", "self", ",", "request_filter", "=", "None", ",", "log_limit", "=", "20", ",", "iterator", "=", "True", ")", ":", "if", "iterator", ":", "# Call iter_call directly as this returns the actual generator", "return", "self", ".", "client", ".", "iter_call", "(", "'Event_Log'", ",", "'getAllObjects'", ",", "filter", "=", "request_filter", ",", "limit", "=", "log_limit", ")", "return", "self", ".", "client", ".", "call", "(", "'Event_Log'", ",", "'getAllObjects'", ",", "filter", "=", "request_filter", ",", "limit", "=", "log_limit", ")" ]
Returns a list of event logs Example:: event_mgr = SoftLayer.EventLogManager(env.client) request_filter = event_mgr.build_filter(date_min="01/01/2019", date_max="02/01/2019") logs = event_mgr.get_event_logs(request_filter) for log in logs: print("Event Name: {}".format(log['eventName'])) :param dict request_filter: filter dict :param int log_limit: number of results to get in one API call :param bool iterator: False will only make one API call for log_limit results. True will keep making API calls until all logs have been retreived. There may be a lot of these. :returns: List of event logs. If iterator=True, will return a python generator object instead.
[ "Returns", "a", "list", "of", "event", "logs" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/event_log.py#L23-L44
1,659
softlayer/softlayer-python
SoftLayer/managers/event_log.py
EventLogManager.build_filter
def build_filter(date_min=None, date_max=None, obj_event=None, obj_id=None, obj_type=None, utc_offset=None): """Returns a query filter that can be passed into EventLogManager.get_event_logs :param string date_min: Lower bound date in MM/DD/YYYY format :param string date_max: Upper bound date in MM/DD/YYYY format :param string obj_event: The name of the events we want to filter by :param int obj_id: The id of the event we want to filter by :param string obj_type: The type of event we want to filter by :param string utc_offset: The UTC offset we want to use when converting date_min and date_max. (default '+0000') :returns: dict: The generated query filter """ if not any([date_min, date_max, obj_event, obj_id, obj_type]): return {} request_filter = {} if date_min and date_max: request_filter['eventCreateDate'] = utils.event_log_filter_between_date(date_min, date_max, utc_offset) else: if date_min: request_filter['eventCreateDate'] = utils.event_log_filter_greater_than_date(date_min, utc_offset) elif date_max: request_filter['eventCreateDate'] = utils.event_log_filter_less_than_date(date_max, utc_offset) if obj_event: request_filter['eventName'] = {'operation': obj_event} if obj_id: request_filter['objectId'] = {'operation': obj_id} if obj_type: request_filter['objectName'] = {'operation': obj_type} return request_filter
python
def build_filter(date_min=None, date_max=None, obj_event=None, obj_id=None, obj_type=None, utc_offset=None): """Returns a query filter that can be passed into EventLogManager.get_event_logs :param string date_min: Lower bound date in MM/DD/YYYY format :param string date_max: Upper bound date in MM/DD/YYYY format :param string obj_event: The name of the events we want to filter by :param int obj_id: The id of the event we want to filter by :param string obj_type: The type of event we want to filter by :param string utc_offset: The UTC offset we want to use when converting date_min and date_max. (default '+0000') :returns: dict: The generated query filter """ if not any([date_min, date_max, obj_event, obj_id, obj_type]): return {} request_filter = {} if date_min and date_max: request_filter['eventCreateDate'] = utils.event_log_filter_between_date(date_min, date_max, utc_offset) else: if date_min: request_filter['eventCreateDate'] = utils.event_log_filter_greater_than_date(date_min, utc_offset) elif date_max: request_filter['eventCreateDate'] = utils.event_log_filter_less_than_date(date_max, utc_offset) if obj_event: request_filter['eventName'] = {'operation': obj_event} if obj_id: request_filter['objectId'] = {'operation': obj_id} if obj_type: request_filter['objectName'] = {'operation': obj_type} return request_filter
[ "def", "build_filter", "(", "date_min", "=", "None", ",", "date_max", "=", "None", ",", "obj_event", "=", "None", ",", "obj_id", "=", "None", ",", "obj_type", "=", "None", ",", "utc_offset", "=", "None", ")", ":", "if", "not", "any", "(", "[", "date_min", ",", "date_max", ",", "obj_event", ",", "obj_id", ",", "obj_type", "]", ")", ":", "return", "{", "}", "request_filter", "=", "{", "}", "if", "date_min", "and", "date_max", ":", "request_filter", "[", "'eventCreateDate'", "]", "=", "utils", ".", "event_log_filter_between_date", "(", "date_min", ",", "date_max", ",", "utc_offset", ")", "else", ":", "if", "date_min", ":", "request_filter", "[", "'eventCreateDate'", "]", "=", "utils", ".", "event_log_filter_greater_than_date", "(", "date_min", ",", "utc_offset", ")", "elif", "date_max", ":", "request_filter", "[", "'eventCreateDate'", "]", "=", "utils", ".", "event_log_filter_less_than_date", "(", "date_max", ",", "utc_offset", ")", "if", "obj_event", ":", "request_filter", "[", "'eventName'", "]", "=", "{", "'operation'", ":", "obj_event", "}", "if", "obj_id", ":", "request_filter", "[", "'objectId'", "]", "=", "{", "'operation'", ":", "obj_id", "}", "if", "obj_type", ":", "request_filter", "[", "'objectName'", "]", "=", "{", "'operation'", ":", "obj_type", "}", "return", "request_filter" ]
Returns a query filter that can be passed into EventLogManager.get_event_logs :param string date_min: Lower bound date in MM/DD/YYYY format :param string date_max: Upper bound date in MM/DD/YYYY format :param string obj_event: The name of the events we want to filter by :param int obj_id: The id of the event we want to filter by :param string obj_type: The type of event we want to filter by :param string utc_offset: The UTC offset we want to use when converting date_min and date_max. (default '+0000') :returns: dict: The generated query filter
[ "Returns", "a", "query", "filter", "that", "can", "be", "passed", "into", "EventLogManager", ".", "get_event_logs" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/event_log.py#L55-L91
1,660
softlayer/softlayer-python
SoftLayer/CLI/dns/record_list.py
cli
def cli(env, zone, data, record, ttl, type): """List all records in a zone.""" manager = SoftLayer.DNSManager(env.client) table = formatting.Table(['id', 'record', 'type', 'ttl', 'data']) table.align['ttl'] = 'l' table.align['record'] = 'r' table.align['data'] = 'l' zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone') records = manager.get_records(zone_id, record_type=type, host=record, ttl=ttl, data=data) for the_record in records: table.add_row([ the_record['id'], the_record['host'], the_record['type'].upper(), the_record['ttl'], the_record['data'] ]) env.fout(table)
python
def cli(env, zone, data, record, ttl, type): """List all records in a zone.""" manager = SoftLayer.DNSManager(env.client) table = formatting.Table(['id', 'record', 'type', 'ttl', 'data']) table.align['ttl'] = 'l' table.align['record'] = 'r' table.align['data'] = 'l' zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone') records = manager.get_records(zone_id, record_type=type, host=record, ttl=ttl, data=data) for the_record in records: table.add_row([ the_record['id'], the_record['host'], the_record['type'].upper(), the_record['ttl'], the_record['data'] ]) env.fout(table)
[ "def", "cli", "(", "env", ",", "zone", ",", "data", ",", "record", ",", "ttl", ",", "type", ")", ":", "manager", "=", "SoftLayer", ".", "DNSManager", "(", "env", ".", "client", ")", "table", "=", "formatting", ".", "Table", "(", "[", "'id'", ",", "'record'", ",", "'type'", ",", "'ttl'", ",", "'data'", "]", ")", "table", ".", "align", "[", "'ttl'", "]", "=", "'l'", "table", ".", "align", "[", "'record'", "]", "=", "'r'", "table", ".", "align", "[", "'data'", "]", "=", "'l'", "zone_id", "=", "helpers", ".", "resolve_id", "(", "manager", ".", "resolve_ids", ",", "zone", ",", "name", "=", "'zone'", ")", "records", "=", "manager", ".", "get_records", "(", "zone_id", ",", "record_type", "=", "type", ",", "host", "=", "record", ",", "ttl", "=", "ttl", ",", "data", "=", "data", ")", "for", "the_record", "in", "records", ":", "table", ".", "add_row", "(", "[", "the_record", "[", "'id'", "]", ",", "the_record", "[", "'host'", "]", ",", "the_record", "[", "'type'", "]", ".", "upper", "(", ")", ",", "the_record", "[", "'ttl'", "]", ",", "the_record", "[", "'data'", "]", "]", ")", "env", ".", "fout", "(", "table", ")" ]
List all records in a zone.
[ "List", "all", "records", "in", "a", "zone", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/dns/record_list.py#L22-L49
1,661
softlayer/softlayer-python
SoftLayer/CLI/ticket/subjects.py
cli
def cli(env): """List Subject IDs for ticket creation.""" ticket_mgr = SoftLayer.TicketManager(env.client) table = formatting.Table(['id', 'subject']) for subject in ticket_mgr.list_subjects(): table.add_row([subject['id'], subject['name']]) env.fout(table)
python
def cli(env): """List Subject IDs for ticket creation.""" ticket_mgr = SoftLayer.TicketManager(env.client) table = formatting.Table(['id', 'subject']) for subject in ticket_mgr.list_subjects(): table.add_row([subject['id'], subject['name']]) env.fout(table)
[ "def", "cli", "(", "env", ")", ":", "ticket_mgr", "=", "SoftLayer", ".", "TicketManager", "(", "env", ".", "client", ")", "table", "=", "formatting", ".", "Table", "(", "[", "'id'", ",", "'subject'", "]", ")", "for", "subject", "in", "ticket_mgr", ".", "list_subjects", "(", ")", ":", "table", ".", "add_row", "(", "[", "subject", "[", "'id'", "]", ",", "subject", "[", "'name'", "]", "]", ")", "env", ".", "fout", "(", "table", ")" ]
List Subject IDs for ticket creation.
[ "List", "Subject", "IDs", "for", "ticket", "creation", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/ticket/subjects.py#L13-L21
1,662
softlayer/softlayer-python
SoftLayer/CLI/virt/placementgroup/create.py
cli
def cli(env, **args): """Create a placement group.""" manager = PlacementManager(env.client) backend_router_id = helpers.resolve_id(manager.get_backend_router_id_from_hostname, args.get('backend_router'), 'backendRouter') rule_id = helpers.resolve_id(manager.get_rule_id_from_name, args.get('rule'), 'Rule') placement_object = { 'name': args.get('name'), 'backendRouterId': backend_router_id, 'ruleId': rule_id } result = manager.create(placement_object) click.secho("Successfully created placement group: ID: %s, Name: %s" % (result['id'], result['name']), fg='green')
python
def cli(env, **args): """Create a placement group.""" manager = PlacementManager(env.client) backend_router_id = helpers.resolve_id(manager.get_backend_router_id_from_hostname, args.get('backend_router'), 'backendRouter') rule_id = helpers.resolve_id(manager.get_rule_id_from_name, args.get('rule'), 'Rule') placement_object = { 'name': args.get('name'), 'backendRouterId': backend_router_id, 'ruleId': rule_id } result = manager.create(placement_object) click.secho("Successfully created placement group: ID: %s, Name: %s" % (result['id'], result['name']), fg='green')
[ "def", "cli", "(", "env", ",", "*", "*", "args", ")", ":", "manager", "=", "PlacementManager", "(", "env", ".", "client", ")", "backend_router_id", "=", "helpers", ".", "resolve_id", "(", "manager", ".", "get_backend_router_id_from_hostname", ",", "args", ".", "get", "(", "'backend_router'", ")", ",", "'backendRouter'", ")", "rule_id", "=", "helpers", ".", "resolve_id", "(", "manager", ".", "get_rule_id_from_name", ",", "args", ".", "get", "(", "'rule'", ")", ",", "'Rule'", ")", "placement_object", "=", "{", "'name'", ":", "args", ".", "get", "(", "'name'", ")", ",", "'backendRouterId'", ":", "backend_router_id", ",", "'ruleId'", ":", "rule_id", "}", "result", "=", "manager", ".", "create", "(", "placement_object", ")", "click", ".", "secho", "(", "\"Successfully created placement group: ID: %s, Name: %s\"", "%", "(", "result", "[", "'id'", "]", ",", "result", "[", "'name'", "]", ")", ",", "fg", "=", "'green'", ")" ]
Create a placement group.
[ "Create", "a", "placement", "group", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/virt/placementgroup/create.py#L17-L31
1,663
softlayer/softlayer-python
SoftLayer/CLI/user/detail.py
cli
def cli(env, identifier, keys, permissions, hardware, virtual, logins, events): """User details.""" mgr = SoftLayer.UserManager(env.client) user_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'username') object_mask = "userStatus[name], parent[id, username], apiAuthenticationKeys[authenticationKey], "\ "unsuccessfulLogins, successfulLogins" user = mgr.get_user(user_id, object_mask) env.fout(basic_info(user, keys)) if permissions: perms = mgr.get_user_permissions(user_id) env.fout(print_permissions(perms)) if hardware: mask = "id, hardware, dedicatedHosts" access = mgr.get_user(user_id, mask) env.fout(print_dedicated_access(access.get('dedicatedHosts', []))) env.fout(print_access(access.get('hardware', []), 'Hardware')) if virtual: mask = "id, virtualGuests" access = mgr.get_user(user_id, mask) env.fout(print_access(access.get('virtualGuests', []), 'Virtual Guests')) if logins: login_log = mgr.get_logins(user_id) env.fout(print_logins(login_log)) if events: event_log = mgr.get_events(user_id) env.fout(print_events(event_log))
python
def cli(env, identifier, keys, permissions, hardware, virtual, logins, events): """User details.""" mgr = SoftLayer.UserManager(env.client) user_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'username') object_mask = "userStatus[name], parent[id, username], apiAuthenticationKeys[authenticationKey], "\ "unsuccessfulLogins, successfulLogins" user = mgr.get_user(user_id, object_mask) env.fout(basic_info(user, keys)) if permissions: perms = mgr.get_user_permissions(user_id) env.fout(print_permissions(perms)) if hardware: mask = "id, hardware, dedicatedHosts" access = mgr.get_user(user_id, mask) env.fout(print_dedicated_access(access.get('dedicatedHosts', []))) env.fout(print_access(access.get('hardware', []), 'Hardware')) if virtual: mask = "id, virtualGuests" access = mgr.get_user(user_id, mask) env.fout(print_access(access.get('virtualGuests', []), 'Virtual Guests')) if logins: login_log = mgr.get_logins(user_id) env.fout(print_logins(login_log)) if events: event_log = mgr.get_events(user_id) env.fout(print_events(event_log))
[ "def", "cli", "(", "env", ",", "identifier", ",", "keys", ",", "permissions", ",", "hardware", ",", "virtual", ",", "logins", ",", "events", ")", ":", "mgr", "=", "SoftLayer", ".", "UserManager", "(", "env", ".", "client", ")", "user_id", "=", "helpers", ".", "resolve_id", "(", "mgr", ".", "resolve_ids", ",", "identifier", ",", "'username'", ")", "object_mask", "=", "\"userStatus[name], parent[id, username], apiAuthenticationKeys[authenticationKey], \"", "\"unsuccessfulLogins, successfulLogins\"", "user", "=", "mgr", ".", "get_user", "(", "user_id", ",", "object_mask", ")", "env", ".", "fout", "(", "basic_info", "(", "user", ",", "keys", ")", ")", "if", "permissions", ":", "perms", "=", "mgr", ".", "get_user_permissions", "(", "user_id", ")", "env", ".", "fout", "(", "print_permissions", "(", "perms", ")", ")", "if", "hardware", ":", "mask", "=", "\"id, hardware, dedicatedHosts\"", "access", "=", "mgr", ".", "get_user", "(", "user_id", ",", "mask", ")", "env", ".", "fout", "(", "print_dedicated_access", "(", "access", ".", "get", "(", "'dedicatedHosts'", ",", "[", "]", ")", ")", ")", "env", ".", "fout", "(", "print_access", "(", "access", ".", "get", "(", "'hardware'", ",", "[", "]", ")", ",", "'Hardware'", ")", ")", "if", "virtual", ":", "mask", "=", "\"id, virtualGuests\"", "access", "=", "mgr", ".", "get_user", "(", "user_id", ",", "mask", ")", "env", ".", "fout", "(", "print_access", "(", "access", ".", "get", "(", "'virtualGuests'", ",", "[", "]", ")", ",", "'Virtual Guests'", ")", ")", "if", "logins", ":", "login_log", "=", "mgr", ".", "get_logins", "(", "user_id", ")", "env", ".", "fout", "(", "print_logins", "(", "login_log", ")", ")", "if", "events", ":", "event_log", "=", "mgr", ".", "get_events", "(", "user_id", ")", "env", ".", "fout", "(", "print_events", "(", "event_log", ")", ")" ]
User details.
[ "User", "details", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/user/detail.py#L28-L56
1,664
softlayer/softlayer-python
SoftLayer/CLI/user/detail.py
basic_info
def basic_info(user, keys): """Prints a table of basic user information""" table = formatting.KeyValueTable(['Title', 'Basic Information']) table.align['Title'] = 'r' table.align['Basic Information'] = 'l' table.add_row(['Id', user.get('id', '-')]) table.add_row(['Username', user.get('username', '-')]) if keys: for key in user.get('apiAuthenticationKeys'): table.add_row(['APIKEY', key.get('authenticationKey')]) table.add_row(['Name', "%s %s" % (user.get('firstName', '-'), user.get('lastName', '-'))]) table.add_row(['Email', user.get('email')]) table.add_row(['OpenID', user.get('openIdConnectUserName')]) address = "%s %s %s %s %s %s" % ( user.get('address1'), user.get('address2'), user.get('city'), user.get('state'), user.get('country'), user.get('postalCode')) table.add_row(['Address', address]) table.add_row(['Company', user.get('companyName')]) table.add_row(['Created', user.get('createDate')]) table.add_row(['Phone Number', user.get('officePhone')]) if user.get('parentId', False): table.add_row(['Parent User', utils.lookup(user, 'parent', 'username')]) table.add_row(['Status', utils.lookup(user, 'userStatus', 'name')]) table.add_row(['PPTP VPN', user.get('pptpVpnAllowedFlag', 'No')]) table.add_row(['SSL VPN', user.get('sslVpnAllowedFlag', 'No')]) for login in user.get('unsuccessfulLogins', {}): login_string = "%s From: %s" % (login.get('createDate'), login.get('ipAddress')) table.add_row(['Last Failed Login', login_string]) break for login in user.get('successfulLogins', {}): login_string = "%s From: %s" % (login.get('createDate'), login.get('ipAddress')) table.add_row(['Last Login', login_string]) break return table
python
def basic_info(user, keys): """Prints a table of basic user information""" table = formatting.KeyValueTable(['Title', 'Basic Information']) table.align['Title'] = 'r' table.align['Basic Information'] = 'l' table.add_row(['Id', user.get('id', '-')]) table.add_row(['Username', user.get('username', '-')]) if keys: for key in user.get('apiAuthenticationKeys'): table.add_row(['APIKEY', key.get('authenticationKey')]) table.add_row(['Name', "%s %s" % (user.get('firstName', '-'), user.get('lastName', '-'))]) table.add_row(['Email', user.get('email')]) table.add_row(['OpenID', user.get('openIdConnectUserName')]) address = "%s %s %s %s %s %s" % ( user.get('address1'), user.get('address2'), user.get('city'), user.get('state'), user.get('country'), user.get('postalCode')) table.add_row(['Address', address]) table.add_row(['Company', user.get('companyName')]) table.add_row(['Created', user.get('createDate')]) table.add_row(['Phone Number', user.get('officePhone')]) if user.get('parentId', False): table.add_row(['Parent User', utils.lookup(user, 'parent', 'username')]) table.add_row(['Status', utils.lookup(user, 'userStatus', 'name')]) table.add_row(['PPTP VPN', user.get('pptpVpnAllowedFlag', 'No')]) table.add_row(['SSL VPN', user.get('sslVpnAllowedFlag', 'No')]) for login in user.get('unsuccessfulLogins', {}): login_string = "%s From: %s" % (login.get('createDate'), login.get('ipAddress')) table.add_row(['Last Failed Login', login_string]) break for login in user.get('successfulLogins', {}): login_string = "%s From: %s" % (login.get('createDate'), login.get('ipAddress')) table.add_row(['Last Login', login_string]) break return table
[ "def", "basic_info", "(", "user", ",", "keys", ")", ":", "table", "=", "formatting", ".", "KeyValueTable", "(", "[", "'Title'", ",", "'Basic Information'", "]", ")", "table", ".", "align", "[", "'Title'", "]", "=", "'r'", "table", ".", "align", "[", "'Basic Information'", "]", "=", "'l'", "table", ".", "add_row", "(", "[", "'Id'", ",", "user", ".", "get", "(", "'id'", ",", "'-'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'Username'", ",", "user", ".", "get", "(", "'username'", ",", "'-'", ")", "]", ")", "if", "keys", ":", "for", "key", "in", "user", ".", "get", "(", "'apiAuthenticationKeys'", ")", ":", "table", ".", "add_row", "(", "[", "'APIKEY'", ",", "key", ".", "get", "(", "'authenticationKey'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'Name'", ",", "\"%s %s\"", "%", "(", "user", ".", "get", "(", "'firstName'", ",", "'-'", ")", ",", "user", ".", "get", "(", "'lastName'", ",", "'-'", ")", ")", "]", ")", "table", ".", "add_row", "(", "[", "'Email'", ",", "user", ".", "get", "(", "'email'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'OpenID'", ",", "user", ".", "get", "(", "'openIdConnectUserName'", ")", "]", ")", "address", "=", "\"%s %s %s %s %s %s\"", "%", "(", "user", ".", "get", "(", "'address1'", ")", ",", "user", ".", "get", "(", "'address2'", ")", ",", "user", ".", "get", "(", "'city'", ")", ",", "user", ".", "get", "(", "'state'", ")", ",", "user", ".", "get", "(", "'country'", ")", ",", "user", ".", "get", "(", "'postalCode'", ")", ")", "table", ".", "add_row", "(", "[", "'Address'", ",", "address", "]", ")", "table", ".", "add_row", "(", "[", "'Company'", ",", "user", ".", "get", "(", "'companyName'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'Created'", ",", "user", ".", "get", "(", "'createDate'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'Phone Number'", ",", "user", ".", "get", "(", "'officePhone'", ")", "]", ")", "if", "user", ".", "get", "(", "'parentId'", ",", "False", ")", ":", "table", ".", "add_row", "(", "[", "'Parent User'", ",", "utils", ".", "lookup", "(", "user", ",", "'parent'", ",", "'username'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'Status'", ",", "utils", ".", "lookup", "(", "user", ",", "'userStatus'", ",", "'name'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'PPTP VPN'", ",", "user", ".", "get", "(", "'pptpVpnAllowedFlag'", ",", "'No'", ")", "]", ")", "table", ".", "add_row", "(", "[", "'SSL VPN'", ",", "user", ".", "get", "(", "'sslVpnAllowedFlag'", ",", "'No'", ")", "]", ")", "for", "login", "in", "user", ".", "get", "(", "'unsuccessfulLogins'", ",", "{", "}", ")", ":", "login_string", "=", "\"%s From: %s\"", "%", "(", "login", ".", "get", "(", "'createDate'", ")", ",", "login", ".", "get", "(", "'ipAddress'", ")", ")", "table", ".", "add_row", "(", "[", "'Last Failed Login'", ",", "login_string", "]", ")", "break", "for", "login", "in", "user", ".", "get", "(", "'successfulLogins'", ",", "{", "}", ")", ":", "login_string", "=", "\"%s From: %s\"", "%", "(", "login", ".", "get", "(", "'createDate'", ")", ",", "login", ".", "get", "(", "'ipAddress'", ")", ")", "table", ".", "add_row", "(", "[", "'Last Login'", ",", "login_string", "]", ")", "break", "return", "table" ]
Prints a table of basic user information
[ "Prints", "a", "table", "of", "basic", "user", "information" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/user/detail.py#L59-L95
1,665
softlayer/softlayer-python
SoftLayer/CLI/user/detail.py
print_permissions
def print_permissions(permissions): """Prints out a users permissions""" table = formatting.Table(['keyName', 'Description']) for perm in permissions: table.add_row([perm['keyName'], perm['name']]) return table
python
def print_permissions(permissions): """Prints out a users permissions""" table = formatting.Table(['keyName', 'Description']) for perm in permissions: table.add_row([perm['keyName'], perm['name']]) return table
[ "def", "print_permissions", "(", "permissions", ")", ":", "table", "=", "formatting", ".", "Table", "(", "[", "'keyName'", ",", "'Description'", "]", ")", "for", "perm", "in", "permissions", ":", "table", ".", "add_row", "(", "[", "perm", "[", "'keyName'", "]", ",", "perm", "[", "'name'", "]", "]", ")", "return", "table" ]
Prints out a users permissions
[ "Prints", "out", "a", "users", "permissions" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/user/detail.py#L98-L104
1,666
softlayer/softlayer-python
SoftLayer/CLI/user/detail.py
print_access
def print_access(access, title): """Prints out the hardware or virtual guests a user can access""" columns = ['id', 'hostname', 'Primary Public IP', 'Primary Private IP', 'Created'] table = formatting.Table(columns, title) for host in access: host_id = host.get('id') host_fqdn = host.get('fullyQualifiedDomainName', '-') host_primary = host.get('primaryIpAddress') host_private = host.get('primaryBackendIpAddress') host_created = host.get('provisionDate') table.add_row([host_id, host_fqdn, host_primary, host_private, host_created]) return table
python
def print_access(access, title): """Prints out the hardware or virtual guests a user can access""" columns = ['id', 'hostname', 'Primary Public IP', 'Primary Private IP', 'Created'] table = formatting.Table(columns, title) for host in access: host_id = host.get('id') host_fqdn = host.get('fullyQualifiedDomainName', '-') host_primary = host.get('primaryIpAddress') host_private = host.get('primaryBackendIpAddress') host_created = host.get('provisionDate') table.add_row([host_id, host_fqdn, host_primary, host_private, host_created]) return table
[ "def", "print_access", "(", "access", ",", "title", ")", ":", "columns", "=", "[", "'id'", ",", "'hostname'", ",", "'Primary Public IP'", ",", "'Primary Private IP'", ",", "'Created'", "]", "table", "=", "formatting", ".", "Table", "(", "columns", ",", "title", ")", "for", "host", "in", "access", ":", "host_id", "=", "host", ".", "get", "(", "'id'", ")", "host_fqdn", "=", "host", ".", "get", "(", "'fullyQualifiedDomainName'", ",", "'-'", ")", "host_primary", "=", "host", ".", "get", "(", "'primaryIpAddress'", ")", "host_private", "=", "host", ".", "get", "(", "'primaryBackendIpAddress'", ")", "host_created", "=", "host", ".", "get", "(", "'provisionDate'", ")", "table", ".", "add_row", "(", "[", "host_id", ",", "host_fqdn", ",", "host_primary", ",", "host_private", ",", "host_created", "]", ")", "return", "table" ]
Prints out the hardware or virtual guests a user can access
[ "Prints", "out", "the", "hardware", "or", "virtual", "guests", "a", "user", "can", "access" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/user/detail.py#L107-L120
1,667
softlayer/softlayer-python
SoftLayer/CLI/user/detail.py
print_dedicated_access
def print_dedicated_access(access): """Prints out the dedicated hosts a user can access""" table = formatting.Table(['id', 'Name', 'Cpus', 'Memory', 'Disk', 'Created'], 'Dedicated Access') for host in access: host_id = host.get('id') host_fqdn = host.get('name') host_cpu = host.get('cpuCount') host_mem = host.get('memoryCapacity') host_disk = host.get('diskCapacity') host_created = host.get('createDate') table.add_row([host_id, host_fqdn, host_cpu, host_mem, host_disk, host_created]) return table
python
def print_dedicated_access(access): """Prints out the dedicated hosts a user can access""" table = formatting.Table(['id', 'Name', 'Cpus', 'Memory', 'Disk', 'Created'], 'Dedicated Access') for host in access: host_id = host.get('id') host_fqdn = host.get('name') host_cpu = host.get('cpuCount') host_mem = host.get('memoryCapacity') host_disk = host.get('diskCapacity') host_created = host.get('createDate') table.add_row([host_id, host_fqdn, host_cpu, host_mem, host_disk, host_created]) return table
[ "def", "print_dedicated_access", "(", "access", ")", ":", "table", "=", "formatting", ".", "Table", "(", "[", "'id'", ",", "'Name'", ",", "'Cpus'", ",", "'Memory'", ",", "'Disk'", ",", "'Created'", "]", ",", "'Dedicated Access'", ")", "for", "host", "in", "access", ":", "host_id", "=", "host", ".", "get", "(", "'id'", ")", "host_fqdn", "=", "host", ".", "get", "(", "'name'", ")", "host_cpu", "=", "host", ".", "get", "(", "'cpuCount'", ")", "host_mem", "=", "host", ".", "get", "(", "'memoryCapacity'", ")", "host_disk", "=", "host", ".", "get", "(", "'diskCapacity'", ")", "host_created", "=", "host", ".", "get", "(", "'createDate'", ")", "table", ".", "add_row", "(", "[", "host_id", ",", "host_fqdn", ",", "host_cpu", ",", "host_mem", ",", "host_disk", ",", "host_created", "]", ")", "return", "table" ]
Prints out the dedicated hosts a user can access
[ "Prints", "out", "the", "dedicated", "hosts", "a", "user", "can", "access" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/user/detail.py#L123-L135
1,668
softlayer/softlayer-python
SoftLayer/CLI/user/detail.py
print_logins
def print_logins(logins): """Prints out the login history for a user""" table = formatting.Table(['Date', 'IP Address', 'Successufl Login?']) for login in logins: table.add_row([login.get('createDate'), login.get('ipAddress'), login.get('successFlag')]) return table
python
def print_logins(logins): """Prints out the login history for a user""" table = formatting.Table(['Date', 'IP Address', 'Successufl Login?']) for login in logins: table.add_row([login.get('createDate'), login.get('ipAddress'), login.get('successFlag')]) return table
[ "def", "print_logins", "(", "logins", ")", ":", "table", "=", "formatting", ".", "Table", "(", "[", "'Date'", ",", "'IP Address'", ",", "'Successufl Login?'", "]", ")", "for", "login", "in", "logins", ":", "table", ".", "add_row", "(", "[", "login", ".", "get", "(", "'createDate'", ")", ",", "login", ".", "get", "(", "'ipAddress'", ")", ",", "login", ".", "get", "(", "'successFlag'", ")", "]", ")", "return", "table" ]
Prints out the login history for a user
[ "Prints", "out", "the", "login", "history", "for", "a", "user" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/user/detail.py#L138-L143
1,669
softlayer/softlayer-python
SoftLayer/CLI/user/detail.py
print_events
def print_events(events): """Prints out the event log for a user""" columns = ['Date', 'Type', 'IP Address', 'label', 'username'] table = formatting.Table(columns) for event in events: table.add_row([event.get('eventCreateDate'), event.get('eventName'), event.get('ipAddress'), event.get('label'), event.get('username')]) return table
python
def print_events(events): """Prints out the event log for a user""" columns = ['Date', 'Type', 'IP Address', 'label', 'username'] table = formatting.Table(columns) for event in events: table.add_row([event.get('eventCreateDate'), event.get('eventName'), event.get('ipAddress'), event.get('label'), event.get('username')]) return table
[ "def", "print_events", "(", "events", ")", ":", "columns", "=", "[", "'Date'", ",", "'Type'", ",", "'IP Address'", ",", "'label'", ",", "'username'", "]", "table", "=", "formatting", ".", "Table", "(", "columns", ")", "for", "event", "in", "events", ":", "table", ".", "add_row", "(", "[", "event", ".", "get", "(", "'eventCreateDate'", ")", ",", "event", ".", "get", "(", "'eventName'", ")", ",", "event", ".", "get", "(", "'ipAddress'", ")", ",", "event", ".", "get", "(", "'label'", ")", ",", "event", ".", "get", "(", "'username'", ")", "]", ")", "return", "table" ]
Prints out the event log for a user
[ "Prints", "out", "the", "event", "log", "for", "a", "user" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/user/detail.py#L146-L153
1,670
softlayer/softlayer-python
SoftLayer/CLI/user/delete.py
cli
def cli(env, identifier): """Sets a user's status to CANCEL_PENDING, which will immediately disable the account, and will eventually be fully removed from the account by an automated internal process. Example: slcli user delete userId """ mgr = SoftLayer.UserManager(env.client) user_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'username') user_template = {'userStatusId': 1021} result = mgr.edit_user(user_id, user_template) if result: click.secho("%s deleted successfully" % identifier, fg='green') else: click.secho("Failed to delete %s" % identifier, fg='red')
python
def cli(env, identifier): """Sets a user's status to CANCEL_PENDING, which will immediately disable the account, and will eventually be fully removed from the account by an automated internal process. Example: slcli user delete userId """ mgr = SoftLayer.UserManager(env.client) user_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'username') user_template = {'userStatusId': 1021} result = mgr.edit_user(user_id, user_template) if result: click.secho("%s deleted successfully" % identifier, fg='green') else: click.secho("Failed to delete %s" % identifier, fg='red')
[ "def", "cli", "(", "env", ",", "identifier", ")", ":", "mgr", "=", "SoftLayer", ".", "UserManager", "(", "env", ".", "client", ")", "user_id", "=", "helpers", ".", "resolve_id", "(", "mgr", ".", "resolve_ids", ",", "identifier", ",", "'username'", ")", "user_template", "=", "{", "'userStatusId'", ":", "1021", "}", "result", "=", "mgr", ".", "edit_user", "(", "user_id", ",", "user_template", ")", "if", "result", ":", "click", ".", "secho", "(", "\"%s deleted successfully\"", "%", "identifier", ",", "fg", "=", "'green'", ")", "else", ":", "click", ".", "secho", "(", "\"Failed to delete %s\"", "%", "identifier", ",", "fg", "=", "'red'", ")" ]
Sets a user's status to CANCEL_PENDING, which will immediately disable the account, and will eventually be fully removed from the account by an automated internal process. Example: slcli user delete userId
[ "Sets", "a", "user", "s", "status", "to", "CANCEL_PENDING", "which", "will", "immediately", "disable", "the", "account" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/user/delete.py#L14-L32
1,671
softlayer/softlayer-python
SoftLayer/CLI/ssl/edit.py
cli
def cli(env, identifier, crt, csr, icc, key, notes): """Edit SSL certificate.""" template = {'id': identifier} if crt: template['certificate'] = open(crt).read() if key: template['privateKey'] = open(key).read() if csr: template['certificateSigningRequest'] = open(csr).read() if icc: template['intermediateCertificate'] = open(icc).read() if notes: template['notes'] = notes manager = SoftLayer.SSLManager(env.client) manager.edit_certificate(template)
python
def cli(env, identifier, crt, csr, icc, key, notes): """Edit SSL certificate.""" template = {'id': identifier} if crt: template['certificate'] = open(crt).read() if key: template['privateKey'] = open(key).read() if csr: template['certificateSigningRequest'] = open(csr).read() if icc: template['intermediateCertificate'] = open(icc).read() if notes: template['notes'] = notes manager = SoftLayer.SSLManager(env.client) manager.edit_certificate(template)
[ "def", "cli", "(", "env", ",", "identifier", ",", "crt", ",", "csr", ",", "icc", ",", "key", ",", "notes", ")", ":", "template", "=", "{", "'id'", ":", "identifier", "}", "if", "crt", ":", "template", "[", "'certificate'", "]", "=", "open", "(", "crt", ")", ".", "read", "(", ")", "if", "key", ":", "template", "[", "'privateKey'", "]", "=", "open", "(", "key", ")", ".", "read", "(", ")", "if", "csr", ":", "template", "[", "'certificateSigningRequest'", "]", "=", "open", "(", "csr", ")", ".", "read", "(", ")", "if", "icc", ":", "template", "[", "'intermediateCertificate'", "]", "=", "open", "(", "icc", ")", ".", "read", "(", ")", "if", "notes", ":", "template", "[", "'notes'", "]", "=", "notes", "manager", "=", "SoftLayer", ".", "SSLManager", "(", "env", ".", "client", ")", "manager", ".", "edit_certificate", "(", "template", ")" ]
Edit SSL certificate.
[ "Edit", "SSL", "certificate", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/ssl/edit.py#L24-L39
1,672
softlayer/softlayer-python
SoftLayer/CLI/cdn/origin_add.py
cli
def cli(env, account_id, content_url, type, cname): """Create an origin pull mapping.""" manager = SoftLayer.CDNManager(env.client) manager.add_origin(account_id, type, content_url, cname)
python
def cli(env, account_id, content_url, type, cname): """Create an origin pull mapping.""" manager = SoftLayer.CDNManager(env.client) manager.add_origin(account_id, type, content_url, cname)
[ "def", "cli", "(", "env", ",", "account_id", ",", "content_url", ",", "type", ",", "cname", ")", ":", "manager", "=", "SoftLayer", ".", "CDNManager", "(", "env", ".", "client", ")", "manager", ".", "add_origin", "(", "account_id", ",", "type", ",", "content_url", ",", "cname", ")" ]
Create an origin pull mapping.
[ "Create", "an", "origin", "pull", "mapping", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/cdn/origin_add.py#L22-L26
1,673
softlayer/softlayer-python
SoftLayer/CLI/template.py
export_to_template
def export_to_template(filename, args, exclude=None): """Exports given options to the given filename in INI format. :param filename: Filename to save options to :param dict args: Arguments to export :param list exclude (optional): Exclusion list for options that should not be exported """ exclude = exclude or [] exclude.append('config') exclude.append('really') exclude.append('format') exclude.append('debug') with open(filename, "w") as template_file: for k, val in args.items(): if val and k not in exclude: if isinstance(val, tuple): val = ','.join(val) if isinstance(val, list): val = ','.join(val) template_file.write('%s=%s\n' % (k, val))
python
def export_to_template(filename, args, exclude=None): """Exports given options to the given filename in INI format. :param filename: Filename to save options to :param dict args: Arguments to export :param list exclude (optional): Exclusion list for options that should not be exported """ exclude = exclude or [] exclude.append('config') exclude.append('really') exclude.append('format') exclude.append('debug') with open(filename, "w") as template_file: for k, val in args.items(): if val and k not in exclude: if isinstance(val, tuple): val = ','.join(val) if isinstance(val, list): val = ','.join(val) template_file.write('%s=%s\n' % (k, val))
[ "def", "export_to_template", "(", "filename", ",", "args", ",", "exclude", "=", "None", ")", ":", "exclude", "=", "exclude", "or", "[", "]", "exclude", ".", "append", "(", "'config'", ")", "exclude", ".", "append", "(", "'really'", ")", "exclude", ".", "append", "(", "'format'", ")", "exclude", ".", "append", "(", "'debug'", ")", "with", "open", "(", "filename", ",", "\"w\"", ")", "as", "template_file", ":", "for", "k", ",", "val", "in", "args", ".", "items", "(", ")", ":", "if", "val", "and", "k", "not", "in", "exclude", ":", "if", "isinstance", "(", "val", ",", "tuple", ")", ":", "val", "=", "','", ".", "join", "(", "val", ")", "if", "isinstance", "(", "val", ",", "list", ")", ":", "val", "=", "','", ".", "join", "(", "val", ")", "template_file", ".", "write", "(", "'%s=%s\\n'", "%", "(", "k", ",", "val", ")", ")" ]
Exports given options to the given filename in INI format. :param filename: Filename to save options to :param dict args: Arguments to export :param list exclude (optional): Exclusion list for options that should not be exported
[ "Exports", "given", "options", "to", "the", "given", "filename", "in", "INI", "format", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/template.py#L47-L68
1,674
softlayer/softlayer-python
SoftLayer/managers/vs_placement.py
PlacementManager.list
def list(self, mask=None): """List existing placement groups Calls SoftLayer_Account::getPlacementGroups """ if mask is None: mask = "mask[id, name, createDate, rule, guestCount, backendRouter[id, hostname]]" groups = self.client.call('Account', 'getPlacementGroups', mask=mask, iter=True) return groups
python
def list(self, mask=None): """List existing placement groups Calls SoftLayer_Account::getPlacementGroups """ if mask is None: mask = "mask[id, name, createDate, rule, guestCount, backendRouter[id, hostname]]" groups = self.client.call('Account', 'getPlacementGroups', mask=mask, iter=True) return groups
[ "def", "list", "(", "self", ",", "mask", "=", "None", ")", ":", "if", "mask", "is", "None", ":", "mask", "=", "\"mask[id, name, createDate, rule, guestCount, backendRouter[id, hostname]]\"", "groups", "=", "self", ".", "client", ".", "call", "(", "'Account'", ",", "'getPlacementGroups'", ",", "mask", "=", "mask", ",", "iter", "=", "True", ")", "return", "groups" ]
List existing placement groups Calls SoftLayer_Account::getPlacementGroups
[ "List", "existing", "placement", "groups" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs_placement.py#L40-L48
1,675
softlayer/softlayer-python
SoftLayer/managers/vs_placement.py
PlacementManager.get_object
def get_object(self, group_id, mask=None): """Returns a PlacementGroup Object https://softlayer.github.io/reference/services/SoftLayer_Virtual_PlacementGroup/getObject """ if mask is None: mask = "mask[id, name, createDate, rule, backendRouter[id, hostname]," \ "guests[activeTransaction[id,transactionStatus[name,friendlyName]]]]" return self.client.call('SoftLayer_Virtual_PlacementGroup', 'getObject', id=group_id, mask=mask)
python
def get_object(self, group_id, mask=None): """Returns a PlacementGroup Object https://softlayer.github.io/reference/services/SoftLayer_Virtual_PlacementGroup/getObject """ if mask is None: mask = "mask[id, name, createDate, rule, backendRouter[id, hostname]," \ "guests[activeTransaction[id,transactionStatus[name,friendlyName]]]]" return self.client.call('SoftLayer_Virtual_PlacementGroup', 'getObject', id=group_id, mask=mask)
[ "def", "get_object", "(", "self", ",", "group_id", ",", "mask", "=", "None", ")", ":", "if", "mask", "is", "None", ":", "mask", "=", "\"mask[id, name, createDate, rule, backendRouter[id, hostname],\"", "\"guests[activeTransaction[id,transactionStatus[name,friendlyName]]]]\"", "return", "self", ".", "client", ".", "call", "(", "'SoftLayer_Virtual_PlacementGroup'", ",", "'getObject'", ",", "id", "=", "group_id", ",", "mask", "=", "mask", ")" ]
Returns a PlacementGroup Object https://softlayer.github.io/reference/services/SoftLayer_Virtual_PlacementGroup/getObject
[ "Returns", "a", "PlacementGroup", "Object" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs_placement.py#L72-L80
1,676
softlayer/softlayer-python
SoftLayer/managers/vs_placement.py
PlacementManager.get_rule_id_from_name
def get_rule_id_from_name(self, name): """Finds the rule that matches name. SoftLayer_Virtual_PlacementGroup_Rule.getAllObjects doesn't support objectFilters. """ results = self.client.call('SoftLayer_Virtual_PlacementGroup_Rule', 'getAllObjects') return [result['id'] for result in results if result['keyName'] == name.upper()]
python
def get_rule_id_from_name(self, name): """Finds the rule that matches name. SoftLayer_Virtual_PlacementGroup_Rule.getAllObjects doesn't support objectFilters. """ results = self.client.call('SoftLayer_Virtual_PlacementGroup_Rule', 'getAllObjects') return [result['id'] for result in results if result['keyName'] == name.upper()]
[ "def", "get_rule_id_from_name", "(", "self", ",", "name", ")", ":", "results", "=", "self", ".", "client", ".", "call", "(", "'SoftLayer_Virtual_PlacementGroup_Rule'", ",", "'getAllObjects'", ")", "return", "[", "result", "[", "'id'", "]", "for", "result", "in", "results", "if", "result", "[", "'keyName'", "]", "==", "name", ".", "upper", "(", ")", "]" ]
Finds the rule that matches name. SoftLayer_Virtual_PlacementGroup_Rule.getAllObjects doesn't support objectFilters.
[ "Finds", "the", "rule", "that", "matches", "name", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs_placement.py#L94-L100
1,677
softlayer/softlayer-python
SoftLayer/managers/vs_placement.py
PlacementManager.get_backend_router_id_from_hostname
def get_backend_router_id_from_hostname(self, hostname): """Finds the backend router Id that matches the hostname given No way to use an objectFilter to find a backendRouter, so we have to search the hard way. """ results = self.client.call('SoftLayer_Network_Pod', 'getAllObjects') return [result['backendRouterId'] for result in results if result['backendRouterName'] == hostname.lower()]
python
def get_backend_router_id_from_hostname(self, hostname): """Finds the backend router Id that matches the hostname given No way to use an objectFilter to find a backendRouter, so we have to search the hard way. """ results = self.client.call('SoftLayer_Network_Pod', 'getAllObjects') return [result['backendRouterId'] for result in results if result['backendRouterName'] == hostname.lower()]
[ "def", "get_backend_router_id_from_hostname", "(", "self", ",", "hostname", ")", ":", "results", "=", "self", ".", "client", ".", "call", "(", "'SoftLayer_Network_Pod'", ",", "'getAllObjects'", ")", "return", "[", "result", "[", "'backendRouterId'", "]", "for", "result", "in", "results", "if", "result", "[", "'backendRouterName'", "]", "==", "hostname", ".", "lower", "(", ")", "]" ]
Finds the backend router Id that matches the hostname given No way to use an objectFilter to find a backendRouter, so we have to search the hard way.
[ "Finds", "the", "backend", "router", "Id", "that", "matches", "the", "hostname", "given" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs_placement.py#L102-L108
1,678
softlayer/softlayer-python
SoftLayer/managers/vs_placement.py
PlacementManager._get_id_from_name
def _get_id_from_name(self, name): """List placement group ids which match the given name.""" _filter = { 'placementGroups': { 'name': {'operation': name} } } mask = "mask[id, name]" results = self.client.call('Account', 'getPlacementGroups', filter=_filter, mask=mask) return [result['id'] for result in results]
python
def _get_id_from_name(self, name): """List placement group ids which match the given name.""" _filter = { 'placementGroups': { 'name': {'operation': name} } } mask = "mask[id, name]" results = self.client.call('Account', 'getPlacementGroups', filter=_filter, mask=mask) return [result['id'] for result in results]
[ "def", "_get_id_from_name", "(", "self", ",", "name", ")", ":", "_filter", "=", "{", "'placementGroups'", ":", "{", "'name'", ":", "{", "'operation'", ":", "name", "}", "}", "}", "mask", "=", "\"mask[id, name]\"", "results", "=", "self", ".", "client", ".", "call", "(", "'Account'", ",", "'getPlacementGroups'", ",", "filter", "=", "_filter", ",", "mask", "=", "mask", ")", "return", "[", "result", "[", "'id'", "]", "for", "result", "in", "results", "]" ]
List placement group ids which match the given name.
[ "List", "placement", "group", "ids", "which", "match", "the", "given", "name", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/vs_placement.py#L110-L119
1,679
softlayer/softlayer-python
SoftLayer/CLI/virt/capacity/create_options.py
cli
def cli(env): """List options for creating Reserved Capacity""" manager = CapacityManager(env.client) items = manager.get_create_options() items.sort(key=lambda term: int(term['capacity'])) table = formatting.Table(["KeyName", "Description", "Term", "Default Hourly Price Per Instance"], title="Reserved Capacity Options") table.align["Hourly Price"] = "l" table.align["Description"] = "l" table.align["KeyName"] = "l" for item in items: table.add_row([ item['keyName'], item['description'], item['capacity'], get_price(item) ]) env.fout(table) regions = manager.get_available_routers() location_table = formatting.Table(['Location', 'POD', 'BackendRouterId'], 'Orderable Locations') for region in regions: for location in region['locations']: for pod in location['location']['pods']: location_table.add_row([region['keyname'], pod['backendRouterName'], pod['backendRouterId']]) env.fout(location_table)
python
def cli(env): """List options for creating Reserved Capacity""" manager = CapacityManager(env.client) items = manager.get_create_options() items.sort(key=lambda term: int(term['capacity'])) table = formatting.Table(["KeyName", "Description", "Term", "Default Hourly Price Per Instance"], title="Reserved Capacity Options") table.align["Hourly Price"] = "l" table.align["Description"] = "l" table.align["KeyName"] = "l" for item in items: table.add_row([ item['keyName'], item['description'], item['capacity'], get_price(item) ]) env.fout(table) regions = manager.get_available_routers() location_table = formatting.Table(['Location', 'POD', 'BackendRouterId'], 'Orderable Locations') for region in regions: for location in region['locations']: for pod in location['location']['pods']: location_table.add_row([region['keyname'], pod['backendRouterName'], pod['backendRouterId']]) env.fout(location_table)
[ "def", "cli", "(", "env", ")", ":", "manager", "=", "CapacityManager", "(", "env", ".", "client", ")", "items", "=", "manager", ".", "get_create_options", "(", ")", "items", ".", "sort", "(", "key", "=", "lambda", "term", ":", "int", "(", "term", "[", "'capacity'", "]", ")", ")", "table", "=", "formatting", ".", "Table", "(", "[", "\"KeyName\"", ",", "\"Description\"", ",", "\"Term\"", ",", "\"Default Hourly Price Per Instance\"", "]", ",", "title", "=", "\"Reserved Capacity Options\"", ")", "table", ".", "align", "[", "\"Hourly Price\"", "]", "=", "\"l\"", "table", ".", "align", "[", "\"Description\"", "]", "=", "\"l\"", "table", ".", "align", "[", "\"KeyName\"", "]", "=", "\"l\"", "for", "item", "in", "items", ":", "table", ".", "add_row", "(", "[", "item", "[", "'keyName'", "]", ",", "item", "[", "'description'", "]", ",", "item", "[", "'capacity'", "]", ",", "get_price", "(", "item", ")", "]", ")", "env", ".", "fout", "(", "table", ")", "regions", "=", "manager", ".", "get_available_routers", "(", ")", "location_table", "=", "formatting", ".", "Table", "(", "[", "'Location'", ",", "'POD'", ",", "'BackendRouterId'", "]", ",", "'Orderable Locations'", ")", "for", "region", "in", "regions", ":", "for", "location", "in", "region", "[", "'locations'", "]", ":", "for", "pod", "in", "location", "[", "'location'", "]", "[", "'pods'", "]", ":", "location_table", ".", "add_row", "(", "[", "region", "[", "'keyname'", "]", ",", "pod", "[", "'backendRouterName'", "]", ",", "pod", "[", "'backendRouterId'", "]", "]", ")", "env", ".", "fout", "(", "location_table", ")" ]
List options for creating Reserved Capacity
[ "List", "options", "for", "creating", "Reserved", "Capacity" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/virt/capacity/create_options.py#L13-L36
1,680
softlayer/softlayer-python
SoftLayer/CLI/virt/capacity/create_options.py
get_price
def get_price(item): """Finds the price with the default locationGroupId""" the_price = "No Default Pricing" for price in item.get('prices', []): if not price.get('locationGroupId'): the_price = "%0.4f" % float(price['hourlyRecurringFee']) return the_price
python
def get_price(item): """Finds the price with the default locationGroupId""" the_price = "No Default Pricing" for price in item.get('prices', []): if not price.get('locationGroupId'): the_price = "%0.4f" % float(price['hourlyRecurringFee']) return the_price
[ "def", "get_price", "(", "item", ")", ":", "the_price", "=", "\"No Default Pricing\"", "for", "price", "in", "item", ".", "get", "(", "'prices'", ",", "[", "]", ")", ":", "if", "not", "price", ".", "get", "(", "'locationGroupId'", ")", ":", "the_price", "=", "\"%0.4f\"", "%", "float", "(", "price", "[", "'hourlyRecurringFee'", "]", ")", "return", "the_price" ]
Finds the price with the default locationGroupId
[ "Finds", "the", "price", "with", "the", "default", "locationGroupId" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/virt/capacity/create_options.py#L39-L45
1,681
softlayer/softlayer-python
SoftLayer/CLI/order/package_list.py
cli
def cli(env, keyword, package_type): """List packages that can be ordered via the placeOrder API. :: # List out all packages for ordering slcli order package-list # List out all packages with "server" in the name slcli order package-list --keyword server # Select only specifict package types slcli order package-list --package_type BARE_METAL_CPU """ manager = ordering.OrderingManager(env.client) table = formatting.Table(COLUMNS) _filter = {'type': {'keyName': {'operation': '!= BLUEMIX_SERVICE'}}} if keyword: _filter['name'] = {'operation': '*= %s' % keyword} if package_type: _filter['type'] = {'keyName': {'operation': package_type}} packages = manager.list_packages(filter=_filter) for package in packages: table.add_row([ package['id'], package['name'], package['keyName'], package['type']['keyName'] ]) env.fout(table)
python
def cli(env, keyword, package_type): """List packages that can be ordered via the placeOrder API. :: # List out all packages for ordering slcli order package-list # List out all packages with "server" in the name slcli order package-list --keyword server # Select only specifict package types slcli order package-list --package_type BARE_METAL_CPU """ manager = ordering.OrderingManager(env.client) table = formatting.Table(COLUMNS) _filter = {'type': {'keyName': {'operation': '!= BLUEMIX_SERVICE'}}} if keyword: _filter['name'] = {'operation': '*= %s' % keyword} if package_type: _filter['type'] = {'keyName': {'operation': package_type}} packages = manager.list_packages(filter=_filter) for package in packages: table.add_row([ package['id'], package['name'], package['keyName'], package['type']['keyName'] ]) env.fout(table)
[ "def", "cli", "(", "env", ",", "keyword", ",", "package_type", ")", ":", "manager", "=", "ordering", ".", "OrderingManager", "(", "env", ".", "client", ")", "table", "=", "formatting", ".", "Table", "(", "COLUMNS", ")", "_filter", "=", "{", "'type'", ":", "{", "'keyName'", ":", "{", "'operation'", ":", "'!= BLUEMIX_SERVICE'", "}", "}", "}", "if", "keyword", ":", "_filter", "[", "'name'", "]", "=", "{", "'operation'", ":", "'*= %s'", "%", "keyword", "}", "if", "package_type", ":", "_filter", "[", "'type'", "]", "=", "{", "'keyName'", ":", "{", "'operation'", ":", "package_type", "}", "}", "packages", "=", "manager", ".", "list_packages", "(", "filter", "=", "_filter", ")", "for", "package", "in", "packages", ":", "table", ".", "add_row", "(", "[", "package", "[", "'id'", "]", ",", "package", "[", "'name'", "]", ",", "package", "[", "'keyName'", "]", ",", "package", "[", "'type'", "]", "[", "'keyName'", "]", "]", ")", "env", ".", "fout", "(", "table", ")" ]
List packages that can be ordered via the placeOrder API. :: # List out all packages for ordering slcli order package-list # List out all packages with "server" in the name slcli order package-list --keyword server # Select only specifict package types slcli order package-list --package_type BARE_METAL_CPU
[ "List", "packages", "that", "can", "be", "ordered", "via", "the", "placeOrder", "API", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/order/package_list.py#L20-L53
1,682
softlayer/softlayer-python
SoftLayer/CLI/loadbal/list.py
cli
def cli(env): """List active load balancers.""" mgr = SoftLayer.LoadBalancerManager(env.client) load_balancers = mgr.get_local_lbs() table = formatting.Table(['ID', 'VIP Address', 'Location', 'SSL Offload', 'Connections/second', 'Type']) table.align['Connections/second'] = 'r' for load_balancer in load_balancers: ssl_support = 'Not Supported' if load_balancer['sslEnabledFlag']: if load_balancer['sslActiveFlag']: ssl_support = 'On' else: ssl_support = 'Off' lb_type = 'Standard' if load_balancer['dedicatedFlag']: lb_type = 'Dedicated' elif load_balancer['highAvailabilityFlag']: lb_type = 'HA' table.add_row([ 'local:%s' % load_balancer['id'], load_balancer['ipAddress']['ipAddress'], load_balancer['loadBalancerHardware'][0]['datacenter']['name'], ssl_support, load_balancer['connectionLimit'], lb_type ]) env.fout(table)
python
def cli(env): """List active load balancers.""" mgr = SoftLayer.LoadBalancerManager(env.client) load_balancers = mgr.get_local_lbs() table = formatting.Table(['ID', 'VIP Address', 'Location', 'SSL Offload', 'Connections/second', 'Type']) table.align['Connections/second'] = 'r' for load_balancer in load_balancers: ssl_support = 'Not Supported' if load_balancer['sslEnabledFlag']: if load_balancer['sslActiveFlag']: ssl_support = 'On' else: ssl_support = 'Off' lb_type = 'Standard' if load_balancer['dedicatedFlag']: lb_type = 'Dedicated' elif load_balancer['highAvailabilityFlag']: lb_type = 'HA' table.add_row([ 'local:%s' % load_balancer['id'], load_balancer['ipAddress']['ipAddress'], load_balancer['loadBalancerHardware'][0]['datacenter']['name'], ssl_support, load_balancer['connectionLimit'], lb_type ]) env.fout(table)
[ "def", "cli", "(", "env", ")", ":", "mgr", "=", "SoftLayer", ".", "LoadBalancerManager", "(", "env", ".", "client", ")", "load_balancers", "=", "mgr", ".", "get_local_lbs", "(", ")", "table", "=", "formatting", ".", "Table", "(", "[", "'ID'", ",", "'VIP Address'", ",", "'Location'", ",", "'SSL Offload'", ",", "'Connections/second'", ",", "'Type'", "]", ")", "table", ".", "align", "[", "'Connections/second'", "]", "=", "'r'", "for", "load_balancer", "in", "load_balancers", ":", "ssl_support", "=", "'Not Supported'", "if", "load_balancer", "[", "'sslEnabledFlag'", "]", ":", "if", "load_balancer", "[", "'sslActiveFlag'", "]", ":", "ssl_support", "=", "'On'", "else", ":", "ssl_support", "=", "'Off'", "lb_type", "=", "'Standard'", "if", "load_balancer", "[", "'dedicatedFlag'", "]", ":", "lb_type", "=", "'Dedicated'", "elif", "load_balancer", "[", "'highAvailabilityFlag'", "]", ":", "lb_type", "=", "'HA'", "table", ".", "add_row", "(", "[", "'local:%s'", "%", "load_balancer", "[", "'id'", "]", ",", "load_balancer", "[", "'ipAddress'", "]", "[", "'ipAddress'", "]", ",", "load_balancer", "[", "'loadBalancerHardware'", "]", "[", "0", "]", "[", "'datacenter'", "]", "[", "'name'", "]", ",", "ssl_support", ",", "load_balancer", "[", "'connectionLimit'", "]", ",", "lb_type", "]", ")", "env", ".", "fout", "(", "table", ")" ]
List active load balancers.
[ "List", "active", "load", "balancers", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/loadbal/list.py#L13-L49
1,683
softlayer/softlayer-python
SoftLayer/CLI/hardware/credentials.py
cli
def cli(env, identifier): """List server credentials.""" manager = SoftLayer.HardwareManager(env.client) hardware_id = helpers.resolve_id(manager.resolve_ids, identifier, 'hardware') instance = manager.get_hardware(hardware_id) table = formatting.Table(['username', 'password']) for item in instance['softwareComponents']: if 'passwords' not in item: raise exceptions.SoftLayerError("No passwords found in softwareComponents") for credentials in item['passwords']: table.add_row([credentials.get('username', 'None'), credentials.get('password', 'None')]) env.fout(table)
python
def cli(env, identifier): """List server credentials.""" manager = SoftLayer.HardwareManager(env.client) hardware_id = helpers.resolve_id(manager.resolve_ids, identifier, 'hardware') instance = manager.get_hardware(hardware_id) table = formatting.Table(['username', 'password']) for item in instance['softwareComponents']: if 'passwords' not in item: raise exceptions.SoftLayerError("No passwords found in softwareComponents") for credentials in item['passwords']: table.add_row([credentials.get('username', 'None'), credentials.get('password', 'None')]) env.fout(table)
[ "def", "cli", "(", "env", ",", "identifier", ")", ":", "manager", "=", "SoftLayer", ".", "HardwareManager", "(", "env", ".", "client", ")", "hardware_id", "=", "helpers", ".", "resolve_id", "(", "manager", ".", "resolve_ids", ",", "identifier", ",", "'hardware'", ")", "instance", "=", "manager", ".", "get_hardware", "(", "hardware_id", ")", "table", "=", "formatting", ".", "Table", "(", "[", "'username'", ",", "'password'", "]", ")", "for", "item", "in", "instance", "[", "'softwareComponents'", "]", ":", "if", "'passwords'", "not", "in", "item", ":", "raise", "exceptions", ".", "SoftLayerError", "(", "\"No passwords found in softwareComponents\"", ")", "for", "credentials", "in", "item", "[", "'passwords'", "]", ":", "table", ".", "add_row", "(", "[", "credentials", ".", "get", "(", "'username'", ",", "'None'", ")", ",", "credentials", ".", "get", "(", "'password'", ",", "'None'", ")", "]", ")", "env", ".", "fout", "(", "table", ")" ]
List server credentials.
[ "List", "server", "credentials", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/hardware/credentials.py#L16-L31
1,684
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
populate_host_templates
def populate_host_templates(host_templates, hardware_ids=None, virtual_guest_ids=None, ip_address_ids=None, subnet_ids=None): """Populate the given host_templates array with the IDs provided :param host_templates: The array to which host templates will be added :param hardware_ids: A List of SoftLayer_Hardware ids :param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids :param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids :param subnet_ids: A List of SoftLayer_Network_Subnet ids """ if hardware_ids is not None: for hardware_id in hardware_ids: host_templates.append({ 'objectType': 'SoftLayer_Hardware', 'id': hardware_id }) if virtual_guest_ids is not None: for virtual_guest_id in virtual_guest_ids: host_templates.append({ 'objectType': 'SoftLayer_Virtual_Guest', 'id': virtual_guest_id }) if ip_address_ids is not None: for ip_address_id in ip_address_ids: host_templates.append({ 'objectType': 'SoftLayer_Network_Subnet_IpAddress', 'id': ip_address_id }) if subnet_ids is not None: for subnet_id in subnet_ids: host_templates.append({ 'objectType': 'SoftLayer_Network_Subnet', 'id': subnet_id })
python
def populate_host_templates(host_templates, hardware_ids=None, virtual_guest_ids=None, ip_address_ids=None, subnet_ids=None): """Populate the given host_templates array with the IDs provided :param host_templates: The array to which host templates will be added :param hardware_ids: A List of SoftLayer_Hardware ids :param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids :param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids :param subnet_ids: A List of SoftLayer_Network_Subnet ids """ if hardware_ids is not None: for hardware_id in hardware_ids: host_templates.append({ 'objectType': 'SoftLayer_Hardware', 'id': hardware_id }) if virtual_guest_ids is not None: for virtual_guest_id in virtual_guest_ids: host_templates.append({ 'objectType': 'SoftLayer_Virtual_Guest', 'id': virtual_guest_id }) if ip_address_ids is not None: for ip_address_id in ip_address_ids: host_templates.append({ 'objectType': 'SoftLayer_Network_Subnet_IpAddress', 'id': ip_address_id }) if subnet_ids is not None: for subnet_id in subnet_ids: host_templates.append({ 'objectType': 'SoftLayer_Network_Subnet', 'id': subnet_id })
[ "def", "populate_host_templates", "(", "host_templates", ",", "hardware_ids", "=", "None", ",", "virtual_guest_ids", "=", "None", ",", "ip_address_ids", "=", "None", ",", "subnet_ids", "=", "None", ")", ":", "if", "hardware_ids", "is", "not", "None", ":", "for", "hardware_id", "in", "hardware_ids", ":", "host_templates", ".", "append", "(", "{", "'objectType'", ":", "'SoftLayer_Hardware'", ",", "'id'", ":", "hardware_id", "}", ")", "if", "virtual_guest_ids", "is", "not", "None", ":", "for", "virtual_guest_id", "in", "virtual_guest_ids", ":", "host_templates", ".", "append", "(", "{", "'objectType'", ":", "'SoftLayer_Virtual_Guest'", ",", "'id'", ":", "virtual_guest_id", "}", ")", "if", "ip_address_ids", "is", "not", "None", ":", "for", "ip_address_id", "in", "ip_address_ids", ":", "host_templates", ".", "append", "(", "{", "'objectType'", ":", "'SoftLayer_Network_Subnet_IpAddress'", ",", "'id'", ":", "ip_address_id", "}", ")", "if", "subnet_ids", "is", "not", "None", ":", "for", "subnet_id", "in", "subnet_ids", ":", "host_templates", ".", "append", "(", "{", "'objectType'", ":", "'SoftLayer_Network_Subnet'", ",", "'id'", ":", "subnet_id", "}", ")" ]
Populate the given host_templates array with the IDs provided :param host_templates: The array to which host templates will be added :param hardware_ids: A List of SoftLayer_Hardware ids :param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids :param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids :param subnet_ids: A List of SoftLayer_Network_Subnet ids
[ "Populate", "the", "given", "host_templates", "array", "with", "the", "IDs", "provided" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L22-L61
1,685
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
get_package
def get_package(manager, category_code): """Returns a product package based on type of storage. :param manager: The storage manager which calls this function. :param category_code: Category code of product package. :return: Returns a packaged based on type of storage. """ _filter = utils.NestedDict({}) _filter['categories']['categoryCode'] = ( utils.query_filter(category_code)) _filter['statusCode'] = (utils.query_filter('ACTIVE')) packages = manager.client.call( 'Product_Package', 'getAllObjects', filter=_filter.to_dict(), mask='id,name,items[prices[categories],attributes]' ) if len(packages) == 0: raise ValueError('No packages were found for %s' % category_code) if len(packages) > 1: raise ValueError('More than one package was found for %s' % category_code) return packages[0]
python
def get_package(manager, category_code): """Returns a product package based on type of storage. :param manager: The storage manager which calls this function. :param category_code: Category code of product package. :return: Returns a packaged based on type of storage. """ _filter = utils.NestedDict({}) _filter['categories']['categoryCode'] = ( utils.query_filter(category_code)) _filter['statusCode'] = (utils.query_filter('ACTIVE')) packages = manager.client.call( 'Product_Package', 'getAllObjects', filter=_filter.to_dict(), mask='id,name,items[prices[categories],attributes]' ) if len(packages) == 0: raise ValueError('No packages were found for %s' % category_code) if len(packages) > 1: raise ValueError('More than one package was found for %s' % category_code) return packages[0]
[ "def", "get_package", "(", "manager", ",", "category_code", ")", ":", "_filter", "=", "utils", ".", "NestedDict", "(", "{", "}", ")", "_filter", "[", "'categories'", "]", "[", "'categoryCode'", "]", "=", "(", "utils", ".", "query_filter", "(", "category_code", ")", ")", "_filter", "[", "'statusCode'", "]", "=", "(", "utils", ".", "query_filter", "(", "'ACTIVE'", ")", ")", "packages", "=", "manager", ".", "client", ".", "call", "(", "'Product_Package'", ",", "'getAllObjects'", ",", "filter", "=", "_filter", ".", "to_dict", "(", ")", ",", "mask", "=", "'id,name,items[prices[categories],attributes]'", ")", "if", "len", "(", "packages", ")", "==", "0", ":", "raise", "ValueError", "(", "'No packages were found for %s'", "%", "category_code", ")", "if", "len", "(", "packages", ")", ">", "1", ":", "raise", "ValueError", "(", "'More than one package was found for %s'", "%", "category_code", ")", "return", "packages", "[", "0", "]" ]
Returns a product package based on type of storage. :param manager: The storage manager which calls this function. :param category_code: Category code of product package. :return: Returns a packaged based on type of storage.
[ "Returns", "a", "product", "package", "based", "on", "type", "of", "storage", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L64-L88
1,686
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
get_location_id
def get_location_id(manager, location): """Returns location id :param manager: The storage manager which calls this function. :param location: Datacenter short name :return: Returns location id """ loc_svc = manager.client['Location_Datacenter'] datacenters = loc_svc.getDatacenters(mask='mask[longName,id,name]') for datacenter in datacenters: if datacenter['name'] == location: location = datacenter['id'] return location raise ValueError('Invalid datacenter name specified.')
python
def get_location_id(manager, location): """Returns location id :param manager: The storage manager which calls this function. :param location: Datacenter short name :return: Returns location id """ loc_svc = manager.client['Location_Datacenter'] datacenters = loc_svc.getDatacenters(mask='mask[longName,id,name]') for datacenter in datacenters: if datacenter['name'] == location: location = datacenter['id'] return location raise ValueError('Invalid datacenter name specified.')
[ "def", "get_location_id", "(", "manager", ",", "location", ")", ":", "loc_svc", "=", "manager", ".", "client", "[", "'Location_Datacenter'", "]", "datacenters", "=", "loc_svc", ".", "getDatacenters", "(", "mask", "=", "'mask[longName,id,name]'", ")", "for", "datacenter", "in", "datacenters", ":", "if", "datacenter", "[", "'name'", "]", "==", "location", ":", "location", "=", "datacenter", "[", "'id'", "]", "return", "location", "raise", "ValueError", "(", "'Invalid datacenter name specified.'", ")" ]
Returns location id :param manager: The storage manager which calls this function. :param location: Datacenter short name :return: Returns location id
[ "Returns", "location", "id" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L91-L104
1,687
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_price_by_category
def find_price_by_category(package, price_category): """Find the price in the given package that has the specified category :param package: The AsAService, Enterprise, or Performance product package :param price_category: The price category code to search for :return: Returns the price for the given category, or an error if not found """ for item in package['items']: price_id = _find_price_id(item['prices'], price_category) if price_id: return price_id raise ValueError("Could not find price with the category, %s" % price_category)
python
def find_price_by_category(package, price_category): """Find the price in the given package that has the specified category :param package: The AsAService, Enterprise, or Performance product package :param price_category: The price category code to search for :return: Returns the price for the given category, or an error if not found """ for item in package['items']: price_id = _find_price_id(item['prices'], price_category) if price_id: return price_id raise ValueError("Could not find price with the category, %s" % price_category)
[ "def", "find_price_by_category", "(", "package", ",", "price_category", ")", ":", "for", "item", "in", "package", "[", "'items'", "]", ":", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "price_category", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find price with the category, %s\"", "%", "price_category", ")" ]
Find the price in the given package that has the specified category :param package: The AsAService, Enterprise, or Performance product package :param price_category: The price category code to search for :return: Returns the price for the given category, or an error if not found
[ "Find", "the", "price", "in", "the", "given", "package", "that", "has", "the", "specified", "category" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L107-L119
1,688
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_ent_space_price
def find_ent_space_price(package, category, size, tier_level): """Find the space price for the given category, size, and tier :param package: The Enterprise (Endurance) product package :param category: The category of space (endurance, replication, snapshot) :param size: The size for which a price is desired :param tier_level: The endurance tier for which a price is desired :return: Returns the matching price, or an error if not found """ if category == 'snapshot': category_code = 'storage_snapshot_space' elif category == 'replication': category_code = 'performance_storage_replication' else: # category == 'endurance' category_code = 'performance_storage_space' level = ENDURANCE_TIERS.get(tier_level) for item in package['items']: if int(item['capacity']) != size: continue price_id = _find_price_id(item['prices'], category_code, 'STORAGE_TIER_LEVEL', level) if price_id: return price_id raise ValueError("Could not find price for %s storage space" % category)
python
def find_ent_space_price(package, category, size, tier_level): """Find the space price for the given category, size, and tier :param package: The Enterprise (Endurance) product package :param category: The category of space (endurance, replication, snapshot) :param size: The size for which a price is desired :param tier_level: The endurance tier for which a price is desired :return: Returns the matching price, or an error if not found """ if category == 'snapshot': category_code = 'storage_snapshot_space' elif category == 'replication': category_code = 'performance_storage_replication' else: # category == 'endurance' category_code = 'performance_storage_space' level = ENDURANCE_TIERS.get(tier_level) for item in package['items']: if int(item['capacity']) != size: continue price_id = _find_price_id(item['prices'], category_code, 'STORAGE_TIER_LEVEL', level) if price_id: return price_id raise ValueError("Could not find price for %s storage space" % category)
[ "def", "find_ent_space_price", "(", "package", ",", "category", ",", "size", ",", "tier_level", ")", ":", "if", "category", "==", "'snapshot'", ":", "category_code", "=", "'storage_snapshot_space'", "elif", "category", "==", "'replication'", ":", "category_code", "=", "'performance_storage_replication'", "else", ":", "# category == 'endurance'", "category_code", "=", "'performance_storage_space'", "level", "=", "ENDURANCE_TIERS", ".", "get", "(", "tier_level", ")", "for", "item", "in", "package", "[", "'items'", "]", ":", "if", "int", "(", "item", "[", "'capacity'", "]", ")", "!=", "size", ":", "continue", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "category_code", ",", "'STORAGE_TIER_LEVEL'", ",", "level", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find price for %s storage space\"", "%", "category", ")" ]
Find the space price for the given category, size, and tier :param package: The Enterprise (Endurance) product package :param category: The category of space (endurance, replication, snapshot) :param size: The size for which a price is desired :param tier_level: The endurance tier for which a price is desired :return: Returns the matching price, or an error if not found
[ "Find", "the", "space", "price", "for", "the", "given", "category", "size", "and", "tier" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L122-L147
1,689
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_ent_endurance_tier_price
def find_ent_endurance_tier_price(package, tier_level): """Find the price in the given package with the specified tier level :param package: The Enterprise (Endurance) product package :param tier_level: The endurance tier for which a price is desired :return: Returns the price for the given tier, or an error if not found """ for item in package['items']: for attribute in item.get('attributes', []): if int(attribute['value']) == ENDURANCE_TIERS.get(tier_level): break else: continue price_id = _find_price_id(item['prices'], 'storage_tier_level') if price_id: return price_id raise ValueError("Could not find price for endurance tier level")
python
def find_ent_endurance_tier_price(package, tier_level): """Find the price in the given package with the specified tier level :param package: The Enterprise (Endurance) product package :param tier_level: The endurance tier for which a price is desired :return: Returns the price for the given tier, or an error if not found """ for item in package['items']: for attribute in item.get('attributes', []): if int(attribute['value']) == ENDURANCE_TIERS.get(tier_level): break else: continue price_id = _find_price_id(item['prices'], 'storage_tier_level') if price_id: return price_id raise ValueError("Could not find price for endurance tier level")
[ "def", "find_ent_endurance_tier_price", "(", "package", ",", "tier_level", ")", ":", "for", "item", "in", "package", "[", "'items'", "]", ":", "for", "attribute", "in", "item", ".", "get", "(", "'attributes'", ",", "[", "]", ")", ":", "if", "int", "(", "attribute", "[", "'value'", "]", ")", "==", "ENDURANCE_TIERS", ".", "get", "(", "tier_level", ")", ":", "break", "else", ":", "continue", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "'storage_tier_level'", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find price for endurance tier level\"", ")" ]
Find the price in the given package with the specified tier level :param package: The Enterprise (Endurance) product package :param tier_level: The endurance tier for which a price is desired :return: Returns the price for the given tier, or an error if not found
[ "Find", "the", "price", "in", "the", "given", "package", "with", "the", "specified", "tier", "level" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L150-L168
1,690
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_perf_space_price
def find_perf_space_price(package, size): """Find the price in the given package with the specified size :param package: The Performance product package :param size: The storage space size for which a price is desired :return: Returns the price for the given size, or an error if not found """ for item in package['items']: if int(item['capacity']) != size: continue price_id = _find_price_id(item['prices'], 'performance_storage_space') if price_id: return price_id raise ValueError("Could not find performance space price for this volume")
python
def find_perf_space_price(package, size): """Find the price in the given package with the specified size :param package: The Performance product package :param size: The storage space size for which a price is desired :return: Returns the price for the given size, or an error if not found """ for item in package['items']: if int(item['capacity']) != size: continue price_id = _find_price_id(item['prices'], 'performance_storage_space') if price_id: return price_id raise ValueError("Could not find performance space price for this volume")
[ "def", "find_perf_space_price", "(", "package", ",", "size", ")", ":", "for", "item", "in", "package", "[", "'items'", "]", ":", "if", "int", "(", "item", "[", "'capacity'", "]", ")", "!=", "size", ":", "continue", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "'performance_storage_space'", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find performance space price for this volume\"", ")" ]
Find the price in the given package with the specified size :param package: The Performance product package :param size: The storage space size for which a price is desired :return: Returns the price for the given size, or an error if not found
[ "Find", "the", "price", "in", "the", "given", "package", "with", "the", "specified", "size" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L194-L209
1,691
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_perf_iops_price
def find_perf_iops_price(package, size, iops): """Find the price in the given package with the specified size and iops :param package: The Performance product package :param size: The size of storage space for which an IOPS price is desired :param iops: The number of IOPS for which a price is desired :return: Returns the price for the size and IOPS, or an error if not found """ for item in package['items']: if int(item['capacity']) != int(iops): continue price_id = _find_price_id(item['prices'], 'performance_storage_iops', 'STORAGE_SPACE', size) if price_id: return price_id raise ValueError("Could not find price for iops for the given volume")
python
def find_perf_iops_price(package, size, iops): """Find the price in the given package with the specified size and iops :param package: The Performance product package :param size: The size of storage space for which an IOPS price is desired :param iops: The number of IOPS for which a price is desired :return: Returns the price for the size and IOPS, or an error if not found """ for item in package['items']: if int(item['capacity']) != int(iops): continue price_id = _find_price_id(item['prices'], 'performance_storage_iops', 'STORAGE_SPACE', size) if price_id: return price_id raise ValueError("Could not find price for iops for the given volume")
[ "def", "find_perf_iops_price", "(", "package", ",", "size", ",", "iops", ")", ":", "for", "item", "in", "package", "[", "'items'", "]", ":", "if", "int", "(", "item", "[", "'capacity'", "]", ")", "!=", "int", "(", "iops", ")", ":", "continue", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "'performance_storage_iops'", ",", "'STORAGE_SPACE'", ",", "size", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find price for iops for the given volume\"", ")" ]
Find the price in the given package with the specified size and iops :param package: The Performance product package :param size: The size of storage space for which an IOPS price is desired :param iops: The number of IOPS for which a price is desired :return: Returns the price for the size and IOPS, or an error if not found
[ "Find", "the", "price", "in", "the", "given", "package", "with", "the", "specified", "size", "and", "iops" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L212-L228
1,692
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_saas_endurance_space_price
def find_saas_endurance_space_price(package, size, tier_level): """Find the SaaS endurance storage space price for the size and tier :param package: The Storage As A Service product package :param size: The volume size for which a price is desired :param tier_level: The endurance tier for which a price is desired :return: Returns the price for the size and tier, or an error if not found """ if tier_level != 0.25: tier_level = int(tier_level) key_name = 'STORAGE_SPACE_FOR_{0}_IOPS_PER_GB'.format(tier_level) key_name = key_name.replace(".", "_") for item in package['items']: if key_name not in item['keyName']: continue if 'capacityMinimum' not in item or 'capacityMaximum' not in item: continue capacity_minimum = int(item['capacityMinimum']) capacity_maximum = int(item['capacityMaximum']) if size < capacity_minimum or size > capacity_maximum: continue price_id = _find_price_id(item['prices'], 'performance_storage_space') if price_id: return price_id raise ValueError("Could not find price for endurance storage space")
python
def find_saas_endurance_space_price(package, size, tier_level): """Find the SaaS endurance storage space price for the size and tier :param package: The Storage As A Service product package :param size: The volume size for which a price is desired :param tier_level: The endurance tier for which a price is desired :return: Returns the price for the size and tier, or an error if not found """ if tier_level != 0.25: tier_level = int(tier_level) key_name = 'STORAGE_SPACE_FOR_{0}_IOPS_PER_GB'.format(tier_level) key_name = key_name.replace(".", "_") for item in package['items']: if key_name not in item['keyName']: continue if 'capacityMinimum' not in item or 'capacityMaximum' not in item: continue capacity_minimum = int(item['capacityMinimum']) capacity_maximum = int(item['capacityMaximum']) if size < capacity_minimum or size > capacity_maximum: continue price_id = _find_price_id(item['prices'], 'performance_storage_space') if price_id: return price_id raise ValueError("Could not find price for endurance storage space")
[ "def", "find_saas_endurance_space_price", "(", "package", ",", "size", ",", "tier_level", ")", ":", "if", "tier_level", "!=", "0.25", ":", "tier_level", "=", "int", "(", "tier_level", ")", "key_name", "=", "'STORAGE_SPACE_FOR_{0}_IOPS_PER_GB'", ".", "format", "(", "tier_level", ")", "key_name", "=", "key_name", ".", "replace", "(", "\".\"", ",", "\"_\"", ")", "for", "item", "in", "package", "[", "'items'", "]", ":", "if", "key_name", "not", "in", "item", "[", "'keyName'", "]", ":", "continue", "if", "'capacityMinimum'", "not", "in", "item", "or", "'capacityMaximum'", "not", "in", "item", ":", "continue", "capacity_minimum", "=", "int", "(", "item", "[", "'capacityMinimum'", "]", ")", "capacity_maximum", "=", "int", "(", "item", "[", "'capacityMaximum'", "]", ")", "if", "size", "<", "capacity_minimum", "or", "size", ">", "capacity_maximum", ":", "continue", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "'performance_storage_space'", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find price for endurance storage space\"", ")" ]
Find the SaaS endurance storage space price for the size and tier :param package: The Storage As A Service product package :param size: The volume size for which a price is desired :param tier_level: The endurance tier for which a price is desired :return: Returns the price for the size and tier, or an error if not found
[ "Find", "the", "SaaS", "endurance", "storage", "space", "price", "for", "the", "size", "and", "tier" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L231-L259
1,693
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_saas_endurance_tier_price
def find_saas_endurance_tier_price(package, tier_level): """Find the SaaS storage tier level price for the specified tier level :param package: The Storage As A Service product package :param tier_level: The endurance tier for which a price is desired :return: Returns the price for the given tier, or an error if not found """ target_capacity = ENDURANCE_TIERS.get(tier_level) for item in package['items']: if 'itemCategory' not in item\ or 'categoryCode' not in item['itemCategory']\ or item['itemCategory']['categoryCode']\ != 'storage_tier_level': continue if int(item['capacity']) != target_capacity: continue price_id = _find_price_id(item['prices'], 'storage_tier_level') if price_id: return price_id raise ValueError("Could not find price for endurance tier level")
python
def find_saas_endurance_tier_price(package, tier_level): """Find the SaaS storage tier level price for the specified tier level :param package: The Storage As A Service product package :param tier_level: The endurance tier for which a price is desired :return: Returns the price for the given tier, or an error if not found """ target_capacity = ENDURANCE_TIERS.get(tier_level) for item in package['items']: if 'itemCategory' not in item\ or 'categoryCode' not in item['itemCategory']\ or item['itemCategory']['categoryCode']\ != 'storage_tier_level': continue if int(item['capacity']) != target_capacity: continue price_id = _find_price_id(item['prices'], 'storage_tier_level') if price_id: return price_id raise ValueError("Could not find price for endurance tier level")
[ "def", "find_saas_endurance_tier_price", "(", "package", ",", "tier_level", ")", ":", "target_capacity", "=", "ENDURANCE_TIERS", ".", "get", "(", "tier_level", ")", "for", "item", "in", "package", "[", "'items'", "]", ":", "if", "'itemCategory'", "not", "in", "item", "or", "'categoryCode'", "not", "in", "item", "[", "'itemCategory'", "]", "or", "item", "[", "'itemCategory'", "]", "[", "'categoryCode'", "]", "!=", "'storage_tier_level'", ":", "continue", "if", "int", "(", "item", "[", "'capacity'", "]", ")", "!=", "target_capacity", ":", "continue", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "'storage_tier_level'", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find price for endurance tier level\"", ")" ]
Find the SaaS storage tier level price for the specified tier level :param package: The Storage As A Service product package :param tier_level: The endurance tier for which a price is desired :return: Returns the price for the given tier, or an error if not found
[ "Find", "the", "SaaS", "storage", "tier", "level", "price", "for", "the", "specified", "tier", "level" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L262-L284
1,694
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_saas_perform_space_price
def find_saas_perform_space_price(package, size): """Find the SaaS performance storage space price for the given size :param package: The Storage As A Service product package :param size: The volume size for which a price is desired :return: Returns the price for the size and tier, or an error if not found """ for item in package['items']: if 'itemCategory' not in item\ or 'categoryCode' not in item['itemCategory']\ or item['itemCategory']['categoryCode']\ != 'performance_storage_space': continue if 'capacityMinimum' not in item or 'capacityMaximum' not in item: continue capacity_minimum = int(item['capacityMinimum']) capacity_maximum = int(item['capacityMaximum']) if size < capacity_minimum or size > capacity_maximum: continue key_name = '{0}_{1}_GBS'.format(capacity_minimum, capacity_maximum) if item['keyName'] != key_name: continue price_id = _find_price_id(item['prices'], 'performance_storage_space') if price_id: return price_id raise ValueError("Could not find price for performance storage space")
python
def find_saas_perform_space_price(package, size): """Find the SaaS performance storage space price for the given size :param package: The Storage As A Service product package :param size: The volume size for which a price is desired :return: Returns the price for the size and tier, or an error if not found """ for item in package['items']: if 'itemCategory' not in item\ or 'categoryCode' not in item['itemCategory']\ or item['itemCategory']['categoryCode']\ != 'performance_storage_space': continue if 'capacityMinimum' not in item or 'capacityMaximum' not in item: continue capacity_minimum = int(item['capacityMinimum']) capacity_maximum = int(item['capacityMaximum']) if size < capacity_minimum or size > capacity_maximum: continue key_name = '{0}_{1}_GBS'.format(capacity_minimum, capacity_maximum) if item['keyName'] != key_name: continue price_id = _find_price_id(item['prices'], 'performance_storage_space') if price_id: return price_id raise ValueError("Could not find price for performance storage space")
[ "def", "find_saas_perform_space_price", "(", "package", ",", "size", ")", ":", "for", "item", "in", "package", "[", "'items'", "]", ":", "if", "'itemCategory'", "not", "in", "item", "or", "'categoryCode'", "not", "in", "item", "[", "'itemCategory'", "]", "or", "item", "[", "'itemCategory'", "]", "[", "'categoryCode'", "]", "!=", "'performance_storage_space'", ":", "continue", "if", "'capacityMinimum'", "not", "in", "item", "or", "'capacityMaximum'", "not", "in", "item", ":", "continue", "capacity_minimum", "=", "int", "(", "item", "[", "'capacityMinimum'", "]", ")", "capacity_maximum", "=", "int", "(", "item", "[", "'capacityMaximum'", "]", ")", "if", "size", "<", "capacity_minimum", "or", "size", ">", "capacity_maximum", ":", "continue", "key_name", "=", "'{0}_{1}_GBS'", ".", "format", "(", "capacity_minimum", ",", "capacity_maximum", ")", "if", "item", "[", "'keyName'", "]", "!=", "key_name", ":", "continue", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "'performance_storage_space'", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find price for performance storage space\"", ")" ]
Find the SaaS performance storage space price for the given size :param package: The Storage As A Service product package :param size: The volume size for which a price is desired :return: Returns the price for the size and tier, or an error if not found
[ "Find", "the", "SaaS", "performance", "storage", "space", "price", "for", "the", "given", "size" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L287-L316
1,695
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_saas_perform_iops_price
def find_saas_perform_iops_price(package, size, iops): """Find the SaaS IOPS price for the specified size and iops :param package: The Storage As A Service product package :param size: The volume size for which a price is desired :param iops: The number of IOPS for which a price is desired :return: Returns the price for the size and IOPS, or an error if not found """ for item in package['items']: if 'itemCategory' not in item\ or 'categoryCode' not in item['itemCategory']\ or item['itemCategory']['categoryCode']\ != 'performance_storage_iops': continue if 'capacityMinimum' not in item or 'capacityMaximum' not in item: continue capacity_minimum = int(item['capacityMinimum']) capacity_maximum = int(item['capacityMaximum']) if iops < capacity_minimum or iops > capacity_maximum: continue price_id = _find_price_id(item['prices'], 'performance_storage_iops', 'STORAGE_SPACE', size) if price_id: return price_id raise ValueError("Could not find price for iops for the given volume")
python
def find_saas_perform_iops_price(package, size, iops): """Find the SaaS IOPS price for the specified size and iops :param package: The Storage As A Service product package :param size: The volume size for which a price is desired :param iops: The number of IOPS for which a price is desired :return: Returns the price for the size and IOPS, or an error if not found """ for item in package['items']: if 'itemCategory' not in item\ or 'categoryCode' not in item['itemCategory']\ or item['itemCategory']['categoryCode']\ != 'performance_storage_iops': continue if 'capacityMinimum' not in item or 'capacityMaximum' not in item: continue capacity_minimum = int(item['capacityMinimum']) capacity_maximum = int(item['capacityMaximum']) if iops < capacity_minimum or iops > capacity_maximum: continue price_id = _find_price_id(item['prices'], 'performance_storage_iops', 'STORAGE_SPACE', size) if price_id: return price_id raise ValueError("Could not find price for iops for the given volume")
[ "def", "find_saas_perform_iops_price", "(", "package", ",", "size", ",", "iops", ")", ":", "for", "item", "in", "package", "[", "'items'", "]", ":", "if", "'itemCategory'", "not", "in", "item", "or", "'categoryCode'", "not", "in", "item", "[", "'itemCategory'", "]", "or", "item", "[", "'itemCategory'", "]", "[", "'categoryCode'", "]", "!=", "'performance_storage_iops'", ":", "continue", "if", "'capacityMinimum'", "not", "in", "item", "or", "'capacityMaximum'", "not", "in", "item", ":", "continue", "capacity_minimum", "=", "int", "(", "item", "[", "'capacityMinimum'", "]", ")", "capacity_maximum", "=", "int", "(", "item", "[", "'capacityMaximum'", "]", ")", "if", "iops", "<", "capacity_minimum", "or", "iops", ">", "capacity_maximum", ":", "continue", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "'performance_storage_iops'", ",", "'STORAGE_SPACE'", ",", "size", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find price for iops for the given volume\"", ")" ]
Find the SaaS IOPS price for the specified size and iops :param package: The Storage As A Service product package :param size: The volume size for which a price is desired :param iops: The number of IOPS for which a price is desired :return: Returns the price for the size and IOPS, or an error if not found
[ "Find", "the", "SaaS", "IOPS", "price", "for", "the", "specified", "size", "and", "iops" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L319-L346
1,696
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_saas_snapshot_space_price
def find_saas_snapshot_space_price(package, size, tier=None, iops=None): """Find the price in the SaaS package for the desired snapshot space size :param package: The product package of the endurance storage type :param size: The snapshot space size for which a price is desired :param tier: The tier of the volume for which space is being ordered :param iops: The IOPS of the volume for which space is being ordered :return: Returns the price for the given size, or an error if not found """ if tier is not None: target_value = ENDURANCE_TIERS.get(tier) target_restriction_type = 'STORAGE_TIER_LEVEL' else: target_value = iops target_restriction_type = 'IOPS' for item in package['items']: if int(item['capacity']) != size: continue price_id = _find_price_id(item['prices'], 'storage_snapshot_space', target_restriction_type, target_value) if price_id: return price_id raise ValueError("Could not find price for snapshot space")
python
def find_saas_snapshot_space_price(package, size, tier=None, iops=None): """Find the price in the SaaS package for the desired snapshot space size :param package: The product package of the endurance storage type :param size: The snapshot space size for which a price is desired :param tier: The tier of the volume for which space is being ordered :param iops: The IOPS of the volume for which space is being ordered :return: Returns the price for the given size, or an error if not found """ if tier is not None: target_value = ENDURANCE_TIERS.get(tier) target_restriction_type = 'STORAGE_TIER_LEVEL' else: target_value = iops target_restriction_type = 'IOPS' for item in package['items']: if int(item['capacity']) != size: continue price_id = _find_price_id(item['prices'], 'storage_snapshot_space', target_restriction_type, target_value) if price_id: return price_id raise ValueError("Could not find price for snapshot space")
[ "def", "find_saas_snapshot_space_price", "(", "package", ",", "size", ",", "tier", "=", "None", ",", "iops", "=", "None", ")", ":", "if", "tier", "is", "not", "None", ":", "target_value", "=", "ENDURANCE_TIERS", ".", "get", "(", "tier", ")", "target_restriction_type", "=", "'STORAGE_TIER_LEVEL'", "else", ":", "target_value", "=", "iops", "target_restriction_type", "=", "'IOPS'", "for", "item", "in", "package", "[", "'items'", "]", ":", "if", "int", "(", "item", "[", "'capacity'", "]", ")", "!=", "size", ":", "continue", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "'storage_snapshot_space'", ",", "target_restriction_type", ",", "target_value", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find price for snapshot space\"", ")" ]
Find the price in the SaaS package for the desired snapshot space size :param package: The product package of the endurance storage type :param size: The snapshot space size for which a price is desired :param tier: The tier of the volume for which space is being ordered :param iops: The IOPS of the volume for which space is being ordered :return: Returns the price for the given size, or an error if not found
[ "Find", "the", "price", "in", "the", "SaaS", "package", "for", "the", "desired", "snapshot", "space", "size" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L349-L373
1,697
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_saas_replication_price
def find_saas_replication_price(package, tier=None, iops=None): """Find the price in the given package for the desired replicant volume :param package: The product package of the endurance storage type :param tier: The tier of the primary storage volume :param iops: The IOPS of the primary storage volume :return: Returns the replication price, or an error if not found """ if tier is not None: target_value = ENDURANCE_TIERS.get(tier) target_item_keyname = 'REPLICATION_FOR_TIERBASED_PERFORMANCE' target_restriction_type = 'STORAGE_TIER_LEVEL' else: target_value = iops target_item_keyname = 'REPLICATION_FOR_IOPSBASED_PERFORMANCE' target_restriction_type = 'IOPS' for item in package['items']: if item['keyName'] != target_item_keyname: continue price_id = _find_price_id( item['prices'], 'performance_storage_replication', target_restriction_type, target_value ) if price_id: return price_id raise ValueError("Could not find price for replicant volume")
python
def find_saas_replication_price(package, tier=None, iops=None): """Find the price in the given package for the desired replicant volume :param package: The product package of the endurance storage type :param tier: The tier of the primary storage volume :param iops: The IOPS of the primary storage volume :return: Returns the replication price, or an error if not found """ if tier is not None: target_value = ENDURANCE_TIERS.get(tier) target_item_keyname = 'REPLICATION_FOR_TIERBASED_PERFORMANCE' target_restriction_type = 'STORAGE_TIER_LEVEL' else: target_value = iops target_item_keyname = 'REPLICATION_FOR_IOPSBASED_PERFORMANCE' target_restriction_type = 'IOPS' for item in package['items']: if item['keyName'] != target_item_keyname: continue price_id = _find_price_id( item['prices'], 'performance_storage_replication', target_restriction_type, target_value ) if price_id: return price_id raise ValueError("Could not find price for replicant volume")
[ "def", "find_saas_replication_price", "(", "package", ",", "tier", "=", "None", ",", "iops", "=", "None", ")", ":", "if", "tier", "is", "not", "None", ":", "target_value", "=", "ENDURANCE_TIERS", ".", "get", "(", "tier", ")", "target_item_keyname", "=", "'REPLICATION_FOR_TIERBASED_PERFORMANCE'", "target_restriction_type", "=", "'STORAGE_TIER_LEVEL'", "else", ":", "target_value", "=", "iops", "target_item_keyname", "=", "'REPLICATION_FOR_IOPSBASED_PERFORMANCE'", "target_restriction_type", "=", "'IOPS'", "for", "item", "in", "package", "[", "'items'", "]", ":", "if", "item", "[", "'keyName'", "]", "!=", "target_item_keyname", ":", "continue", "price_id", "=", "_find_price_id", "(", "item", "[", "'prices'", "]", ",", "'performance_storage_replication'", ",", "target_restriction_type", ",", "target_value", ")", "if", "price_id", ":", "return", "price_id", "raise", "ValueError", "(", "\"Could not find price for replicant volume\"", ")" ]
Find the price in the given package for the desired replicant volume :param package: The product package of the endurance storage type :param tier: The tier of the primary storage volume :param iops: The IOPS of the primary storage volume :return: Returns the replication price, or an error if not found
[ "Find", "the", "price", "in", "the", "given", "package", "for", "the", "desired", "replicant", "volume" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L376-L406
1,698
softlayer/softlayer-python
SoftLayer/managers/storage_utils.py
find_snapshot_schedule_id
def find_snapshot_schedule_id(volume, snapshot_schedule_keyname): """Find the snapshot schedule ID for the given volume and keyname :param volume: The volume for which the snapshot ID is desired :param snapshot_schedule_keyname: The keyname of the snapshot schedule :return: Returns an int value indicating the volume's snapshot schedule ID """ for schedule in volume['schedules']: if 'type' in schedule and 'keyname' in schedule['type']: if schedule['type']['keyname'] == snapshot_schedule_keyname: return schedule['id'] raise ValueError("The given snapshot schedule ID was not found for " "the given storage volume")
python
def find_snapshot_schedule_id(volume, snapshot_schedule_keyname): """Find the snapshot schedule ID for the given volume and keyname :param volume: The volume for which the snapshot ID is desired :param snapshot_schedule_keyname: The keyname of the snapshot schedule :return: Returns an int value indicating the volume's snapshot schedule ID """ for schedule in volume['schedules']: if 'type' in schedule and 'keyname' in schedule['type']: if schedule['type']['keyname'] == snapshot_schedule_keyname: return schedule['id'] raise ValueError("The given snapshot schedule ID was not found for " "the given storage volume")
[ "def", "find_snapshot_schedule_id", "(", "volume", ",", "snapshot_schedule_keyname", ")", ":", "for", "schedule", "in", "volume", "[", "'schedules'", "]", ":", "if", "'type'", "in", "schedule", "and", "'keyname'", "in", "schedule", "[", "'type'", "]", ":", "if", "schedule", "[", "'type'", "]", "[", "'keyname'", "]", "==", "snapshot_schedule_keyname", ":", "return", "schedule", "[", "'id'", "]", "raise", "ValueError", "(", "\"The given snapshot schedule ID was not found for \"", "\"the given storage volume\"", ")" ]
Find the snapshot schedule ID for the given volume and keyname :param volume: The volume for which the snapshot ID is desired :param snapshot_schedule_keyname: The keyname of the snapshot schedule :return: Returns an int value indicating the volume's snapshot schedule ID
[ "Find", "the", "snapshot", "schedule", "ID", "for", "the", "given", "volume", "and", "keyname" ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/managers/storage_utils.py#L409-L422
1,699
softlayer/softlayer-python
SoftLayer/CLI/file/snapshot/cancel.py
cli
def cli(env, volume_id, reason, immediate): """Cancel existing snapshot space for a given volume.""" file_storage_manager = SoftLayer.FileStorageManager(env.client) if not (env.skip_confirmations or formatting.no_going_back(volume_id)): raise exceptions.CLIAbort('Aborted') cancelled = file_storage_manager.cancel_snapshot_space( volume_id, reason, immediate) if cancelled: if immediate: click.echo('File volume with id %s has been marked' ' for immediate snapshot cancellation' % volume_id) else: click.echo('File volume with id %s has been marked' ' for snapshot cancellation' % volume_id) else: click.echo('Unable to cancel snapshot space for file volume %s' % volume_id)
python
def cli(env, volume_id, reason, immediate): """Cancel existing snapshot space for a given volume.""" file_storage_manager = SoftLayer.FileStorageManager(env.client) if not (env.skip_confirmations or formatting.no_going_back(volume_id)): raise exceptions.CLIAbort('Aborted') cancelled = file_storage_manager.cancel_snapshot_space( volume_id, reason, immediate) if cancelled: if immediate: click.echo('File volume with id %s has been marked' ' for immediate snapshot cancellation' % volume_id) else: click.echo('File volume with id %s has been marked' ' for snapshot cancellation' % volume_id) else: click.echo('Unable to cancel snapshot space for file volume %s' % volume_id)
[ "def", "cli", "(", "env", ",", "volume_id", ",", "reason", ",", "immediate", ")", ":", "file_storage_manager", "=", "SoftLayer", ".", "FileStorageManager", "(", "env", ".", "client", ")", "if", "not", "(", "env", ".", "skip_confirmations", "or", "formatting", ".", "no_going_back", "(", "volume_id", ")", ")", ":", "raise", "exceptions", ".", "CLIAbort", "(", "'Aborted'", ")", "cancelled", "=", "file_storage_manager", ".", "cancel_snapshot_space", "(", "volume_id", ",", "reason", ",", "immediate", ")", "if", "cancelled", ":", "if", "immediate", ":", "click", ".", "echo", "(", "'File volume with id %s has been marked'", "' for immediate snapshot cancellation'", "%", "volume_id", ")", "else", ":", "click", ".", "echo", "(", "'File volume with id %s has been marked'", "' for snapshot cancellation'", "%", "volume_id", ")", "else", ":", "click", ".", "echo", "(", "'Unable to cancel snapshot space for file volume %s'", "%", "volume_id", ")" ]
Cancel existing snapshot space for a given volume.
[ "Cancel", "existing", "snapshot", "space", "for", "a", "given", "volume", "." ]
9f181be08cc3668353b05a6de0cb324f52cff6fa
https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/file/snapshot/cancel.py#L20-L40