idx
int64
0
251k
question
stringlengths
53
3.53k
target
stringlengths
5
1.23k
len_question
int64
20
893
len_target
int64
3
238
233,500
def add_global_ip ( self , version = 4 , test_order = False ) : # This method is here to improve the public interface from a user's # perspective since ordering a single global IP through the subnet # interface is not intuitive. return self . add_subnet ( 'global' , version = version , test_order = test_order )
Adds a global IP address to the account .
76
9
233,501
def add_securitygroup_rule ( self , group_id , remote_ip = None , remote_group = None , direction = None , ethertype = None , port_max = None , port_min = None , protocol = None ) : rule = { 'direction' : direction } if ethertype is not None : rule [ 'ethertype' ] = ethertype if port_max is not None : rule [ 'portRangeMax' ] = port_max if port_min is not None : rule [ 'portRangeMin' ] = port_min if protocol is not None : rule [ 'protocol' ] = protocol if remote_ip is not None : rule [ 'remoteIp' ] = remote_ip if remote_group is not None : rule [ 'remoteGroupId' ] = remote_group return self . add_securitygroup_rules ( group_id , [ rule ] )
Add a rule to a security group
191
7
233,502
def add_securitygroup_rules ( self , group_id , rules ) : if not isinstance ( rules , list ) : raise TypeError ( "The rules provided must be a list of dictionaries" ) return self . security_group . addRules ( rules , id = group_id )
Add rules to a security group
62
6
233,503
def add_subnet ( self , subnet_type , quantity = None , vlan_id = None , version = 4 , test_order = False ) : package = self . client [ 'Product_Package' ] category = 'sov_sec_ip_addresses_priv' desc = '' if version == 4 : if subnet_type == 'global' : quantity = 0 category = 'global_ipv4' elif subnet_type == 'public' : category = 'sov_sec_ip_addresses_pub' else : category = 'static_ipv6_addresses' if subnet_type == 'global' : quantity = 0 category = 'global_ipv6' desc = 'Global' elif subnet_type == 'public' : desc = 'Portable' # In the API, every non-server item is contained within package ID 0. # This means that we need to get all of the items and loop through them # looking for the items we need based upon the category, quantity, and # item description. price_id = None quantity_str = str ( quantity ) for item in package . getItems ( id = 0 , mask = 'itemCategory' ) : category_code = utils . lookup ( item , 'itemCategory' , 'categoryCode' ) if all ( [ category_code == category , item . get ( 'capacity' ) == quantity_str , version == 4 or ( version == 6 and desc in item [ 'description' ] ) ] ) : price_id = item [ 'prices' ] [ 0 ] [ 'id' ] break order = { 'packageId' : 0 , 'prices' : [ { 'id' : price_id } ] , 'quantity' : 1 , # This is necessary in order for the XML-RPC endpoint to select the # correct order container 'complexType' : 'SoftLayer_Container_Product_Order_Network_Subnet' , } if subnet_type != 'global' : order [ 'endPointVlanId' ] = vlan_id if test_order : return self . client [ 'Product_Order' ] . verifyOrder ( order ) else : return self . client [ 'Product_Order' ] . placeOrder ( order )
Orders a new subnet
486
6
233,504
def assign_global_ip ( self , global_ip_id , target ) : return self . client [ 'Network_Subnet_IpAddress_Global' ] . route ( target , id = global_ip_id )
Assigns a global IP address to a specified target .
49
12
233,505
def attach_securitygroup_components ( self , group_id , component_ids ) : return self . security_group . attachNetworkComponents ( component_ids , id = group_id )
Attaches network components to a security group .
42
9
233,506
def cancel_global_ip ( self , global_ip_id ) : service = self . client [ 'Network_Subnet_IpAddress_Global' ] ip_address = service . getObject ( id = global_ip_id , mask = 'billingItem' ) billing_id = ip_address [ 'billingItem' ] [ 'id' ] return self . client [ 'Billing_Item' ] . cancelService ( id = billing_id )
Cancels the specified global IP address .
101
9
233,507
def cancel_subnet ( self , subnet_id ) : subnet = self . get_subnet ( subnet_id , mask = 'id, billingItem.id' ) if "billingItem" not in subnet : raise exceptions . SoftLayerError ( "subnet %s can not be cancelled" " " % subnet_id ) billing_id = subnet [ 'billingItem' ] [ 'id' ] return self . client [ 'Billing_Item' ] . cancelService ( id = billing_id )
Cancels the specified subnet .
116
8
233,508
def create_securitygroup ( self , name = None , description = None ) : create_dict = { 'name' : name , 'description' : description } return self . security_group . createObject ( create_dict )
Creates a security group .
48
6
233,509
def detach_securitygroup_components ( self , group_id , component_ids ) : return self . security_group . detachNetworkComponents ( component_ids , id = group_id )
Detaches network components from a security group .
42
9
233,510
def edit_rwhois ( self , abuse_email = None , address1 = None , address2 = None , city = None , company_name = None , country = None , first_name = None , last_name = None , postal_code = None , private_residence = None , state = None ) : update = { } for key , value in [ ( 'abuseEmail' , abuse_email ) , ( 'address1' , address1 ) , ( 'address2' , address2 ) , ( 'city' , city ) , ( 'companyName' , company_name ) , ( 'country' , country ) , ( 'firstName' , first_name ) , ( 'lastName' , last_name ) , ( 'privateResidenceFlag' , private_residence ) , ( 'state' , state ) , ( 'postalCode' , postal_code ) ] : if value is not None : update [ key ] = value # If there's anything to update, update it if update : rwhois = self . get_rwhois ( ) return self . client [ 'Network_Subnet_Rwhois_Data' ] . editObject ( update , id = rwhois [ 'id' ] ) return True
Edit rwhois record .
269
6
233,511
def edit_securitygroup ( self , group_id , name = None , description = None ) : successful = False obj = { } if name : obj [ 'name' ] = name if description : obj [ 'description' ] = description if obj : successful = self . security_group . editObject ( obj , id = group_id ) return successful
Edit security group details .
74
5
233,512
def edit_securitygroup_rule ( self , group_id , rule_id , remote_ip = None , remote_group = None , direction = None , ethertype = None , port_max = None , port_min = None , protocol = None ) : successful = False obj = { } if remote_ip is not None : obj [ 'remoteIp' ] = remote_ip if remote_group is not None : obj [ 'remoteGroupId' ] = remote_group if direction is not None : obj [ 'direction' ] = direction if ethertype is not None : obj [ 'ethertype' ] = ethertype if port_max is not None : obj [ 'portRangeMax' ] = port_max if port_min is not None : obj [ 'portRangeMin' ] = port_min if protocol is not None : obj [ 'protocol' ] = protocol if obj : obj [ 'id' ] = rule_id successful = self . security_group . editRules ( [ obj ] , id = group_id ) return successful
Edit a security group rule .
225
6
233,513
def ip_lookup ( self , ip_address ) : obj = self . client [ 'Network_Subnet_IpAddress' ] return obj . getByIpAddress ( ip_address , mask = 'hardware, virtualGuest' )
Looks up an IP address and returns network information about it .
53
12
233,514
def get_securitygroup ( self , group_id , * * kwargs ) : if 'mask' not in kwargs : kwargs [ 'mask' ] = ( 'id,' 'name,' 'description,' '''rules[id, remoteIp, remoteGroupId, direction, ethertype, portRangeMin, portRangeMax, protocol, createDate, modifyDate],''' '''networkComponentBindings[ networkComponent[ id, port, guest[ id, hostname, primaryBackendIpAddress, primaryIpAddress ] ] ]''' ) return self . security_group . getObject ( id = group_id , * * kwargs )
Returns the information about the given security group .
145
9
233,515
def get_subnet ( self , subnet_id , * * kwargs ) : if 'mask' not in kwargs : kwargs [ 'mask' ] = DEFAULT_SUBNET_MASK return self . subnet . getObject ( id = subnet_id , * * kwargs )
Returns information about a single subnet .
70
8
233,516
def get_vlan ( self , vlan_id ) : return self . vlan . getObject ( id = vlan_id , mask = DEFAULT_GET_VLAN_MASK )
Returns information about a single VLAN .
43
8
233,517
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 .
217
13
233,518
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 .
360
11
233,519
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 .
242
12
233,520
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 .
35
10
233,521
def remove_securitygroup_rules ( self , group_id , rules ) : return self . security_group . removeRules ( rules , id = group_id )
Remove rules from a security group .
35
7
233,522
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
158
10
233,523
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 .
276
12
233,524
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 .
51
13
233,525
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 .
63
13
233,526
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 .
142
11
233,527
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 .
532
6
233,528
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 .
331
15
233,529
def list_tickets ( self , open_status = True , closed_status = True ) : 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 )
List all tickets .
145
4
233,530
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 .
121
5
233,531
def update_ticket ( self , ticket_id = None , body = None ) : return self . ticket . addUpdate ( { 'entry' : body } , id = ticket_id )
Update a ticket .
40
4
233,532
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 .
100
7
233,533
def attach_hardware ( self , ticket_id = None , hardware_id = None ) : return self . ticket . addAttachedHardware ( hardware_id , id = ticket_id )
Attach hardware to a ticket .
41
6
233,534
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 .
43
8
233,535
def detach_hardware ( self , ticket_id = None , hardware_id = None ) : return self . ticket . removeAttachedHardware ( hardware_id , id = ticket_id )
Detach hardware from a ticket .
41
7
233,536
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 .
43
9
233,537
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 .
674
5
233,538
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 .
412
10
233,539
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 .
402
12
233,540
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 .
165
5
233,541
def cli ( env , zone ) : manager = SoftLayer . DNSManager ( env . client ) manager . create_zone ( zone )
Create a zone .
29
4
233,542
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 .
100
14
233,543
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 .
77
9
233,544
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 .
159
8
233,545
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 .
93
13
233,546
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 .
113
12
233,547
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 .
144
8
233,548
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 .
82
7
233,549
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 .
149
10
233,550
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 .
169
10
233,551
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 .
381
10
233,552
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 .
90
12
233,553
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 .
54
8
233,554
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 .
236
7
233,555
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 .
71
7
233,556
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 .
126
6
233,557
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 .
220
6
233,558
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 .
153
7
233,559
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 .
160
8
233,560
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 .
66
4
233,561
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
82
8
233,562
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 .
156
7
233,563
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 .
108
7
233,564
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 .
185
13
233,565
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 .
100
5
233,566
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 .
102
4
233,567
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 .
190
9
233,568
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 .
49
9
233,569
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 .
63
8
233,570
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 .
78
9
233,571
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 .
56
10
233,572
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 .
156
7
233,573
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 .
250
15
233,574
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
108
6
233,575
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
285
19
233,576
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 .
225
7
233,577
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 .
82
7
233,578
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 .
204
5
233,579
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 .
366
3
233,580
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
669
8
233,581
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
56
6
233,582
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
164
12
233,583
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
173
10
233,584
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
80
9
233,585
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
104
9
233,586
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
124
20
233,587
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 .
150
4
233,588
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 .
52
6
233,589
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 .
145
13
233,590
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
72
4
233,591
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
97
6
233,592
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 .
71
8
233,593
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
81
12
233,594
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 .
91
11
233,595
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
300
6
233,596
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
75
10
233,597
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 .
190
12
233,598
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 .
302
6
233,599
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 .
163
4