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,400 | def cli ( env , identifier , allocation , port , routing_type , routing_method ) : mgr = SoftLayer . LoadBalancerManager ( env . client ) loadbal_id , group_id = loadbal . parse_id ( identifier ) # check if any input is provided if not any ( [ allocation , port , routing_type , routing_method ] ) : raise exceptions . CLIAbort ( 'At least one property is required to be changed!' ) mgr . edit_service_group ( loadbal_id , group_id , allocation = allocation , port = port , routing_type = routing_type , routing_method = routing_method ) env . fout ( 'Load balancer service group %s is being updated!' % identifier ) | Edit an existing load balancer service group . | 162 | 9 |
233,401 | def cli ( env , identifier , ack ) : # Print a list of all on going maintenance manager = AccountManager ( env . client ) event = manager . get_event ( identifier ) if ack : manager . ack_event ( identifier ) env . fout ( basic_event_table ( event ) ) env . fout ( impacted_table ( event ) ) env . fout ( update_table ( event ) ) | Details of a specific event and ability to acknowledge event . | 91 | 11 |
233,402 | def basic_event_table ( event ) : table = formatting . Table ( [ "Id" , "Status" , "Type" , "Start" , "End" ] , title = utils . clean_splitlines ( event . get ( 'subject' ) ) ) table . add_row ( [ event . get ( 'id' ) , utils . lookup ( event , 'statusCode' , 'name' ) , utils . lookup ( event , 'notificationOccurrenceEventType' , 'keyName' ) , utils . clean_time ( event . get ( 'startDate' ) ) , utils . clean_time ( event . get ( 'endDate' ) ) ] ) return table | Formats a basic event table | 152 | 6 |
233,403 | def impacted_table ( event ) : table = formatting . Table ( [ "Type" , "Id" , "Hostname" , "PrivateIp" , "Label" ] ) for item in event . get ( 'impactedResources' , [ ] ) : table . add_row ( [ item . get ( 'resourceType' ) , item . get ( 'resourceTableId' ) , item . get ( 'hostname' ) , item . get ( 'privateIp' ) , item . get ( 'filterLabel' ) ] ) return table | Formats a basic impacted resources table | 118 | 7 |
233,404 | def update_table ( event ) : update_number = 0 for update in event . get ( 'updates' , [ ] ) : header = "======= Update #%s on %s =======" % ( update_number , utils . clean_time ( update . get ( 'startDate' ) ) ) click . secho ( header , fg = 'green' ) update_number = update_number + 1 text = update . get ( 'contents' ) # deals with all the \r\n from the API click . secho ( utils . clean_splitlines ( text ) ) | Formats a basic event update table | 130 | 7 |
233,405 | def cli ( env , sortby , columns , datacenter , username , storage_type ) : block_manager = SoftLayer . BlockStorageManager ( env . client ) block_volumes = block_manager . list_block_volumes ( datacenter = datacenter , username = username , storage_type = storage_type , mask = columns . mask ( ) ) table = formatting . Table ( columns . columns ) table . sortby = sortby for block_volume in block_volumes : table . add_row ( [ value or formatting . blank ( ) for value in columns . row ( block_volume ) ] ) env . fout ( table ) | List block storage . | 142 | 4 |
233,406 | def cli ( env ) : mgr = SoftLayer . ObjectStorageManager ( env . client ) endpoints = mgr . list_endpoints ( ) table = formatting . Table ( [ 'datacenter' , 'public' , 'private' ] ) for endpoint in endpoints : table . add_row ( [ endpoint [ 'datacenter' ] [ 'name' ] , endpoint [ 'public' ] , endpoint [ 'private' ] , ] ) env . fout ( table ) | List object storage endpoints . | 105 | 6 |
233,407 | def cli ( env , identifier ) : vsi = SoftLayer . VSManager ( env . client ) vs_id = helpers . resolve_id ( vsi . resolve_ids , identifier , 'VS' ) if not ( env . skip_confirmations or formatting . no_going_back ( vs_id ) ) : raise exceptions . CLIAbort ( 'Aborted' ) vsi . cancel_instance ( vs_id ) | Cancel virtual servers . | 94 | 5 |
233,408 | def cli ( env , identifier ) : mgr = SoftLayer . HardwareManager ( env . client ) hw_id = helpers . resolve_id ( mgr . resolve_ids , identifier , 'hardware' ) if not ( env . skip_confirmations or formatting . confirm ( 'This will power off the server with id %s and ' 'reflash device firmware. Continue?' % hw_id ) ) : raise exceptions . CLIAbort ( 'Aborted.' ) mgr . reflash_firmware ( hw_id ) | Reflash server firmware . | 119 | 5 |
233,409 | def cli ( env , volume_id ) : file_manager = SoftLayer . FileStorageManager ( env . client ) snapshot_schedules = file_manager . list_volume_schedules ( volume_id ) table = formatting . Table ( [ 'id' , 'active' , 'type' , 'replication' , 'date_created' , 'minute' , 'hour' , 'day' , 'week' , 'day_of_week' , 'date_of_month' , 'month_of_year' , 'maximum_snapshots' ] ) for schedule in snapshot_schedules : if 'REPLICATION' in schedule [ 'type' ] [ 'keyname' ] : replication = '*' else : replication = formatting . blank ( ) file_schedule_type = schedule [ 'type' ] [ 'keyname' ] . replace ( 'REPLICATION_' , '' ) file_schedule_type = file_schedule_type . replace ( 'SNAPSHOT_' , '' ) property_list = [ 'MINUTE' , 'HOUR' , 'DAY' , 'WEEK' , 'DAY_OF_WEEK' , 'DAY_OF_MONTH' , 'MONTH_OF_YEAR' , 'SNAPSHOT_LIMIT' ] schedule_properties = [ ] for prop_key in property_list : item = formatting . blank ( ) for schedule_property in schedule . get ( 'properties' , [ ] ) : if schedule_property [ 'type' ] [ 'keyname' ] == prop_key : if schedule_property [ 'value' ] == '-1' : item = '*' else : item = schedule_property [ 'value' ] break schedule_properties . append ( item ) table_row = [ schedule [ 'id' ] , '*' if schedule . get ( 'active' , '' ) else '' , file_schedule_type , replication , schedule . get ( 'createDate' , '' ) ] table_row . extend ( schedule_properties ) table . add_row ( table_row ) env . fout ( table ) | Lists snapshot schedules for a given volume | 469 | 8 |
233,410 | def cli ( env ) : mgr = SoftLayer . FirewallManager ( env . client ) table = formatting . Table ( [ 'firewall id' , 'type' , 'features' , 'server/vlan id' ] ) fwvlans = mgr . get_firewalls ( ) dedicated_firewalls = [ firewall for firewall in fwvlans if firewall [ 'dedicatedFirewallFlag' ] ] for vlan in dedicated_firewalls : features = [ ] if vlan [ 'highAvailabilityFirewallFlag' ] : features . append ( 'HA' ) if features : feature_list = formatting . listing ( features , separator = ',' ) else : feature_list = formatting . blank ( ) table . add_row ( [ 'vlan:%s' % vlan [ 'networkVlanFirewall' ] [ 'id' ] , 'VLAN - dedicated' , feature_list , vlan [ 'id' ] ] ) shared_vlan = [ firewall for firewall in fwvlans if not firewall [ 'dedicatedFirewallFlag' ] ] for vlan in shared_vlan : vs_firewalls = [ guest for guest in vlan [ 'firewallGuestNetworkComponents' ] if has_firewall_component ( guest ) ] for firewall in vs_firewalls : table . add_row ( [ 'vs:%s' % firewall [ 'id' ] , 'Virtual Server - standard' , '-' , firewall [ 'guestNetworkComponent' ] [ 'guest' ] [ 'id' ] ] ) server_firewalls = [ server for server in vlan [ 'firewallNetworkComponents' ] if has_firewall_component ( server ) ] for firewall in server_firewalls : table . add_row ( [ 'server:%s' % firewall [ 'id' ] , 'Server - standard' , '-' , utils . lookup ( firewall , 'networkComponent' , 'downlinkComponent' , 'hardwareId' ) ] ) env . fout ( table ) | List firewalls . | 447 | 5 |
233,411 | def cli ( env , identifier ) : mgr = SoftLayer . NetworkManager ( env . client ) subnet_id = helpers . resolve_id ( mgr . resolve_subnet_ids , identifier , name = 'subnet' ) if not ( env . skip_confirmations or formatting . no_going_back ( subnet_id ) ) : raise exceptions . CLIAbort ( 'Aborted' ) mgr . cancel_subnet ( subnet_id ) | Cancel a subnet . | 104 | 6 |
233,412 | def get_settings_from_client ( client ) : settings = { 'username' : '' , 'api_key' : '' , 'timeout' : '' , 'endpoint_url' : '' , } try : settings [ 'username' ] = client . auth . username settings [ 'api_key' ] = client . auth . api_key except AttributeError : pass transport = _resolve_transport ( client . transport ) try : settings [ 'timeout' ] = transport . timeout settings [ 'endpoint_url' ] = transport . endpoint_url except AttributeError : pass return settings | Pull out settings from a SoftLayer . BaseClient instance . | 129 | 12 |
233,413 | def config_table ( settings ) : table = formatting . KeyValueTable ( [ 'name' , 'value' ] ) table . align [ 'name' ] = 'r' table . align [ 'value' ] = 'l' table . add_row ( [ 'Username' , settings [ 'username' ] or 'not set' ] ) table . add_row ( [ 'API Key' , settings [ 'api_key' ] or 'not set' ] ) table . add_row ( [ 'Endpoint URL' , settings [ 'endpoint_url' ] or 'not set' ] ) table . add_row ( [ 'Timeout' , settings [ 'timeout' ] or 'not set' ] ) return table | Returns a config table . | 157 | 5 |
233,414 | def cli ( env , name , backend_router_id , flavor , instances , test = False ) : manager = CapacityManager ( env . client ) result = manager . create ( name = name , backend_router_id = backend_router_id , flavor = flavor , instances = instances , test = test ) if test : table = formatting . Table ( [ 'Name' , 'Value' ] , "Test Order" ) container = result [ 'orderContainers' ] [ 0 ] table . add_row ( [ 'Name' , container [ 'name' ] ] ) table . add_row ( [ 'Location' , container [ 'locationObject' ] [ 'longName' ] ] ) for price in container [ 'prices' ] : table . add_row ( [ 'Contract' , price [ 'item' ] [ 'description' ] ] ) table . add_row ( [ 'Hourly Total' , result [ 'postTaxRecurring' ] ] ) else : table = formatting . Table ( [ 'Name' , 'Value' ] , "Reciept" ) table . add_row ( [ 'Order Date' , result [ 'orderDate' ] ] ) table . add_row ( [ 'Order ID' , result [ 'orderId' ] ] ) table . add_row ( [ 'status' , result [ 'placedOrder' ] [ 'status' ] ] ) table . add_row ( [ 'Hourly Total' , result [ 'orderDetails' ] [ 'postTaxRecurring' ] ] ) env . fout ( table ) | Create a Reserved Capacity instance . | 338 | 6 |
233,415 | def cli ( env , account_id ) : manager = SoftLayer . CDNManager ( env . client ) origins = manager . get_origins ( account_id ) table = formatting . Table ( [ 'id' , 'media_type' , 'cname' , 'origin_url' ] ) for origin in origins : table . add_row ( [ origin [ 'id' ] , origin [ 'mediaType' ] , origin . get ( 'cname' , formatting . blank ( ) ) , origin [ 'originUrl' ] ] ) env . fout ( table ) | List origin pull mappings . | 125 | 6 |
233,416 | def cli ( env ) : manager = PlacementManager ( env . client ) routers = manager . get_routers ( ) env . fout ( get_router_table ( routers ) ) rules = manager . get_all_rules ( ) env . fout ( get_rule_table ( rules ) ) | List options for creating a placement group . | 67 | 8 |
233,417 | def get_router_table ( routers ) : table = formatting . Table ( [ 'Datacenter' , 'Hostname' , 'Backend Router Id' ] , "Available Routers" ) for router in routers : datacenter = router [ 'topLevelLocation' ] [ 'longName' ] table . add_row ( [ datacenter , router [ 'hostname' ] , router [ 'id' ] ] ) return table | Formats output from _get_routers and returns a table . | 95 | 14 |
233,418 | def get_rule_table ( rules ) : table = formatting . Table ( [ 'Id' , 'KeyName' ] , "Rules" ) for rule in rules : table . add_row ( [ rule [ 'id' ] , rule [ 'keyName' ] ] ) return table | Formats output from get_all_rules and returns a table . | 61 | 14 |
233,419 | def _cli_helper_dedicated_host ( env , result , table ) : dedicated_host_id = utils . lookup ( result , 'dedicatedHost' , 'id' ) if dedicated_host_id : table . add_row ( [ 'dedicated_host_id' , dedicated_host_id ] ) # Try to find name of dedicated host try : dedicated_host = env . client . call ( 'Virtual_DedicatedHost' , 'getObject' , id = dedicated_host_id ) except SoftLayer . SoftLayerAPIError : LOGGER . error ( 'Unable to get dedicated host id %s' , dedicated_host_id ) dedicated_host = { } table . add_row ( [ 'dedicated_host' , dedicated_host . get ( 'name' ) or formatting . blank ( ) ] ) | Get details on dedicated host for a virtual server . | 184 | 10 |
233,420 | def cli ( env , identifier , wait ) : vsi = SoftLayer . VSManager ( env . client ) vs_id = helpers . resolve_id ( vsi . resolve_ids , identifier , 'VS' ) ready = vsi . wait_for_ready ( vs_id , wait ) if ready : env . fout ( "READY" ) else : raise exceptions . CLIAbort ( "Instance %s not ready" % vs_id ) | Check if a virtual server is ready . | 99 | 8 |
233,421 | def cli ( env , volume_id , replicant_id , immediate ) : block_storage_manager = SoftLayer . BlockStorageManager ( env . client ) success = block_storage_manager . failover_to_replicant ( volume_id , replicant_id , immediate ) if success : click . echo ( "Failover to replicant is now in progress." ) else : click . echo ( "Failover operation could not be initiated." ) | Failover a block volume to the given replicant volume . | 101 | 13 |
233,422 | def cli ( env , identifier ) : mgr = SoftLayer . DedicatedHostManager ( env . client ) host_id = helpers . resolve_id ( mgr . resolve_ids , identifier , 'dedicated host' ) if not ( env . skip_confirmations or formatting . no_going_back ( host_id ) ) : raise exceptions . CLIAbort ( 'Aborted' ) mgr . cancel_host ( host_id ) click . secho ( 'Dedicated Host %s was cancelled' % host_id , fg = 'green' ) | Cancel a dedicated host server immediately | 125 | 7 |
233,423 | def get_image ( self , image_id , * * kwargs ) : if 'mask' not in kwargs : kwargs [ 'mask' ] = IMAGE_MASK return self . vgbdtg . getObject ( id = image_id , * * kwargs ) | Get details about an image . | 65 | 6 |
233,424 | def list_private_images ( self , guid = None , name = None , * * kwargs ) : if 'mask' not in kwargs : kwargs [ 'mask' ] = IMAGE_MASK _filter = utils . NestedDict ( kwargs . get ( 'filter' ) or { } ) if name : _filter [ 'privateBlockDeviceTemplateGroups' ] [ 'name' ] = ( utils . query_filter ( name ) ) if guid : _filter [ 'privateBlockDeviceTemplateGroups' ] [ 'globalIdentifier' ] = ( utils . query_filter ( guid ) ) kwargs [ 'filter' ] = _filter . to_dict ( ) account = self . client [ 'Account' ] return account . getPrivateBlockDeviceTemplateGroups ( * * kwargs ) | List all private images . | 183 | 5 |
233,425 | def list_public_images ( self , guid = None , name = None , * * kwargs ) : if 'mask' not in kwargs : kwargs [ 'mask' ] = IMAGE_MASK _filter = utils . NestedDict ( kwargs . get ( 'filter' ) or { } ) if name : _filter [ 'name' ] = utils . query_filter ( name ) if guid : _filter [ 'globalIdentifier' ] = utils . query_filter ( guid ) kwargs [ 'filter' ] = _filter . to_dict ( ) return self . vgbdtg . getPublicImages ( * * kwargs ) | List all public images . | 150 | 5 |
233,426 | def _get_ids_from_name_public ( self , name ) : results = self . list_public_images ( name = name ) return [ result [ 'id' ] for result in results ] | Get public images which match the given name . | 44 | 9 |
233,427 | def _get_ids_from_name_private ( self , name ) : results = self . list_private_images ( name = name ) return [ result [ 'id' ] for result in results ] | Get private images which match the given name . | 44 | 9 |
233,428 | def edit ( self , image_id , name = None , note = None , tag = None ) : obj = { } if name : obj [ 'name' ] = name if note : obj [ 'note' ] = note if obj : self . vgbdtg . editObject ( obj , id = image_id ) if tag : self . vgbdtg . setTags ( str ( tag ) , id = image_id ) return bool ( name or note or tag ) | Edit image related details . | 102 | 5 |
233,429 | def import_image_from_uri ( self , name , uri , os_code = None , note = None , ibm_api_key = None , root_key_crn = None , wrapped_dek = None , cloud_init = False , byol = False , is_encrypted = False ) : if 'cos://' in uri : return self . vgbdtg . createFromIcos ( { 'name' : name , 'note' : note , 'operatingSystemReferenceCode' : os_code , 'uri' : uri , 'ibmApiKey' : ibm_api_key , 'crkCrn' : root_key_crn , 'wrappedDek' : wrapped_dek , 'cloudInit' : cloud_init , 'byol' : byol , 'isEncrypted' : is_encrypted } ) else : return self . vgbdtg . createFromExternalSource ( { 'name' : name , 'note' : note , 'operatingSystemReferenceCode' : os_code , 'uri' : uri , } ) | Import a new image from object storage . | 240 | 8 |
233,430 | def export_image_to_uri ( self , image_id , uri , ibm_api_key = None ) : if 'cos://' in uri : return self . vgbdtg . copyToIcos ( { 'uri' : uri , 'ibmApiKey' : ibm_api_key } , id = image_id ) else : return self . vgbdtg . copyToExternalSource ( { 'uri' : uri } , id = image_id ) | Export image into the given object storage | 109 | 7 |
233,431 | def cli ( env , identifier , credential_id ) : mgr = SoftLayer . ObjectStorageManager ( env . client ) credential = mgr . delete_credential ( identifier , credential_id = credential_id ) env . fout ( credential ) | Delete the credential of an Object Storage Account . | 55 | 9 |
233,432 | def list ( self ) : mask = """mask[availableInstanceCount, occupiedInstanceCount, instances[id, billingItem[description, hourlyRecurringFee]], instanceCount, backendRouter[datacenter]]""" results = self . client . call ( 'Account' , 'getReservedCapacityGroups' , mask = mask ) return results | List Reserved Capacities | 75 | 5 |
233,433 | def get_object ( self , identifier , mask = None ) : if mask is None : mask = "mask[instances[billingItem[item[keyName],category], guest], backendRouter[datacenter]]" result = self . client . call ( self . rcg_service , 'getObject' , id = identifier , mask = mask ) return result | Get a Reserved Capacity Group | 79 | 5 |
233,434 | def get_create_options ( self ) : mask = "mask[attributes,prices[pricingLocationGroup]]" results = self . ordering_manager . list_items ( self . capacity_package , mask = mask ) return results | List available reserved capacity plans | 51 | 5 |
233,435 | def get_available_routers ( self , dc = None ) : mask = "mask[locations]" # Step 1, get the package id package = self . ordering_manager . get_package_by_key ( self . capacity_package , mask = "id" ) # Step 2, get the regions this package is orderable in regions = self . client . call ( 'Product_Package' , 'getRegions' , id = package [ 'id' ] , mask = mask , iter = True ) _filter = None routers = { } if dc is not None : _filter = { 'datacenterName' : { 'operation' : dc } } # Step 3, for each location in each region, get the pod details, which contains the router id pods = self . client . call ( 'Network_Pod' , 'getAllObjects' , filter = _filter , iter = True ) for region in regions : routers [ region [ 'keyname' ] ] = [ ] for location in region [ 'locations' ] : location [ 'location' ] [ 'pods' ] = list ( ) for pod in pods : if pod [ 'datacenterName' ] == location [ 'location' ] [ 'name' ] : location [ 'location' ] [ 'pods' ] . append ( pod ) # Step 4, return the data. return regions | Pulls down all backendRouterIds that are available | 294 | 12 |
233,436 | def create ( self , name , backend_router_id , flavor , instances , test = False ) : # Since orderManger needs a DC id, just send in 0, the API will ignore it args = ( self . capacity_package , 0 , [ flavor ] ) extras = { "backendRouterId" : backend_router_id , "name" : name } kwargs = { 'extras' : extras , 'quantity' : instances , 'complex_type' : 'SoftLayer_Container_Product_Order_Virtual_ReservedCapacity' , 'hourly' : True } if test : receipt = self . ordering_manager . verify_order ( * args , * * kwargs ) else : receipt = self . ordering_manager . place_order ( * args , * * kwargs ) return receipt | Orders a Virtual_ReservedCapacityGroup | 181 | 10 |
233,437 | def create_guest ( self , capacity_id , test , guest_object ) : vs_manager = VSManager ( self . client ) mask = "mask[instances[id, billingItem[id, item[id,keyName]]], backendRouter[id, datacenter[name]]]" capacity = self . get_object ( capacity_id , mask = mask ) try : capacity_flavor = capacity [ 'instances' ] [ 0 ] [ 'billingItem' ] [ 'item' ] [ 'keyName' ] flavor = _flavor_string ( capacity_flavor , guest_object [ 'primary_disk' ] ) except KeyError : raise SoftLayer . SoftLayerError ( "Unable to find capacity Flavor." ) guest_object [ 'flavor' ] = flavor guest_object [ 'datacenter' ] = capacity [ 'backendRouter' ] [ 'datacenter' ] [ 'name' ] # Reserved capacity only supports SAN as of 20181008 guest_object [ 'local_disk' ] = False template = vs_manager . verify_create_instance ( * * guest_object ) template [ 'reservedCapacityId' ] = capacity_id if guest_object . get ( 'ipv6' ) : ipv6_price = self . ordering_manager . get_price_id_list ( 'PUBLIC_CLOUD_SERVER' , [ '1_IPV6_ADDRESS' ] ) template [ 'prices' ] . append ( { 'id' : ipv6_price [ 0 ] } ) if test : result = self . client . call ( 'Product_Order' , 'verifyOrder' , template ) else : result = self . client . call ( 'Product_Order' , 'placeOrder' , template ) return result | Turns an empty Reserve Capacity into a real Virtual Guest | 395 | 11 |
233,438 | def cli ( env ) : manager = CapacityManager ( env . client ) result = manager . list ( ) table = formatting . Table ( [ "ID" , "Name" , "Capacity" , "Flavor" , "Location" , "Created" ] , title = "Reserved Capacity" ) for r_c in result : occupied_string = "#" * int ( r_c . get ( 'occupiedInstanceCount' , 0 ) ) available_string = "-" * int ( r_c . get ( 'availableInstanceCount' , 0 ) ) try : flavor = r_c [ 'instances' ] [ 0 ] [ 'billingItem' ] [ 'description' ] # cost = float(r_c['instances'][0]['billingItem']['hourlyRecurringFee']) except KeyError : flavor = "Unknown Billing Item" location = r_c [ 'backendRouter' ] [ 'hostname' ] capacity = "%s%s" % ( occupied_string , available_string ) table . add_row ( [ r_c [ 'id' ] , r_c [ 'name' ] , capacity , flavor , location , r_c [ 'createDate' ] ] ) env . fout ( table ) | List Reserved Capacity groups . | 275 | 5 |
233,439 | def cli ( env , package_keyname , location , preset , name , send_email , complex_type , extras , order_items ) : manager = ordering . OrderingManager ( env . client ) if extras : try : extras = json . loads ( extras ) except ValueError as err : raise exceptions . CLIAbort ( "There was an error when parsing the --extras value: {}" . format ( err ) ) args = ( package_keyname , location , order_items ) kwargs = { 'preset_keyname' : preset , 'extras' : extras , 'quantity' : 1 , 'quote_name' : name , 'send_email' : send_email , 'complex_type' : complex_type } order = manager . place_quote ( * args , * * kwargs ) table = formatting . KeyValueTable ( [ 'name' , 'value' ] ) table . align [ 'name' ] = 'r' table . align [ 'value' ] = 'l' table . add_row ( [ 'id' , order [ 'quote' ] [ 'id' ] ] ) table . add_row ( [ 'name' , order [ 'quote' ] [ 'name' ] ] ) table . add_row ( [ 'created' , order [ 'orderDate' ] ] ) table . add_row ( [ 'expires' , order [ 'quote' ] [ 'expirationDate' ] ] ) table . add_row ( [ 'status' , order [ 'quote' ] [ 'status' ] ] ) env . fout ( table ) | Place a quote . | 351 | 4 |
233,440 | def cli ( env ) : table = formatting . Table ( [ 'Id' , 'Name' , 'Created' , 'Expiration' , 'Status' , 'Package Name' , 'Package Id' ] ) table . align [ 'Name' ] = 'l' table . align [ 'Package Name' ] = 'r' table . align [ 'Package Id' ] = 'l' manager = ordering . OrderingManager ( env . client ) items = manager . get_quotes ( ) for item in items : package = item [ 'order' ] [ 'items' ] [ 0 ] [ 'package' ] table . add_row ( [ item . get ( 'id' ) , item . get ( 'name' ) , clean_time ( item . get ( 'createDate' ) ) , clean_time ( item . get ( 'modifyDate' ) ) , item . get ( 'status' ) , package . get ( 'keyName' ) , package . get ( 'id' ) ] ) env . fout ( table ) | List all active quotes on an account | 224 | 7 |
233,441 | def cli ( env , identifier ) : image_mgr = SoftLayer . ImageManager ( env . client ) image_id = helpers . resolve_id ( image_mgr . resolve_ids , identifier , 'image' ) image_mgr . delete_image ( image_id ) | Delete an image . | 62 | 4 |
233,442 | def cli ( env , identifier , enabled , port , weight , healthcheck_type , ip_address ) : mgr = SoftLayer . LoadBalancerManager ( env . client ) loadbal_id , group_id = loadbal . parse_id ( identifier ) # check if the IP is valid ip_address_id = None if ip_address : ip_service = env . client [ 'Network_Subnet_IpAddress' ] ip_record = ip_service . getByIpAddress ( ip_address ) if len ( ip_record ) > 0 : ip_address_id = ip_record [ 'id' ] mgr . add_service ( loadbal_id , group_id , ip_address_id = ip_address_id , enabled = enabled , port = port , weight = weight , hc_type = healthcheck_type ) env . fout ( 'Load balancer service is being added!' ) | Adds a new load balancer service . | 202 | 8 |
233,443 | def cli ( ctx , env ) : # Set up the environment env = copy . deepcopy ( env ) env . load_modules_from_python ( routes . ALL_ROUTES ) env . aliases . update ( routes . ALL_ALIASES ) env . vars [ 'global_args' ] = ctx . parent . params env . vars [ 'is_shell' ] = True env . vars [ 'last_exit_code' ] = 0 # Set up prompt_toolkit settings app_path = click . get_app_dir ( 'softlayer_shell' ) if not os . path . exists ( app_path ) : os . makedirs ( app_path ) complete = completer . ShellCompleter ( core . cli ) while True : try : line = p_shortcuts . prompt ( completer = complete , complete_while_typing = True , auto_suggest = p_auto_suggest . AutoSuggestFromHistory ( ) , ) # Parse arguments try : args = shlex . split ( line ) except ValueError as ex : print ( "Invalid Command: %s" % ex ) continue if not args : continue # Run Command try : # Reset client so that the client gets refreshed env . client = None core . main ( args = list ( get_env_args ( env ) ) + args , obj = env , prog_name = "" , reraise_exceptions = True ) except SystemExit as ex : env . vars [ 'last_exit_code' ] = ex . code except EOFError : return except ShellExit : return except Exception as ex : env . vars [ 'last_exit_code' ] = 1 traceback . print_exc ( file = sys . stderr ) except KeyboardInterrupt : env . vars [ 'last_exit_code' ] = 130 | Enters a shell for slcli . | 398 | 8 |
233,444 | def get_env_args ( env ) : for arg , val in env . vars . get ( 'global_args' , { } ) . items ( ) : if val is True : yield '--%s' % arg elif isinstance ( val , int ) : for _ in range ( val ) : yield '--%s' % arg elif val is None : continue else : yield '--%s=%s' % ( arg , val ) | Yield options to inject into the slcli command from the environment . | 99 | 14 |
233,445 | def cli ( env , identifier , purge ) : manager = PlacementManager ( env . client ) group_id = helpers . resolve_id ( manager . resolve_ids , identifier , 'placement_group' ) if purge : placement_group = manager . get_object ( group_id ) guest_list = ', ' . join ( [ guest [ 'fullyQualifiedDomainName' ] for guest in placement_group [ 'guests' ] ] ) if len ( placement_group [ 'guests' ] ) < 1 : raise exceptions . CLIAbort ( 'No virtual servers were found in placement group %s' % identifier ) click . secho ( "You are about to delete the following guests!\n%s" % guest_list , fg = 'red' ) if not ( env . skip_confirmations or formatting . confirm ( "This action will cancel all guests! Continue?" ) ) : raise exceptions . CLIAbort ( 'Aborting virtual server order.' ) vm_manager = VSManager ( env . client ) for guest in placement_group [ 'guests' ] : click . secho ( "Deleting %s..." % guest [ 'fullyQualifiedDomainName' ] ) vm_manager . cancel_instance ( guest [ 'id' ] ) return click . secho ( "You are about to delete the following placement group! %s" % identifier , fg = 'red' ) if not ( env . skip_confirmations or formatting . confirm ( "This action will cancel the placement group! Continue?" ) ) : raise exceptions . CLIAbort ( 'Aborting virtual server order.' ) cancel_result = manager . delete ( group_id ) if cancel_result : click . secho ( "Placement Group %s has been canceld." % identifier , fg = 'green' ) | Delete a placement group . | 393 | 5 |
233,446 | def cli ( env , context_id , translation_id , static_ip , remote_ip , note ) : manager = SoftLayer . IPSECManager ( env . client ) succeeded = manager . update_translation ( context_id , translation_id , static_ip = static_ip , remote_ip = remote_ip , notes = note ) if succeeded : env . out ( 'Updated translation #{}' . format ( translation_id ) ) else : raise CLIHalt ( 'Failed to update translation #{}' . format ( translation_id ) ) | Update an address translation for an IPSEC tunnel context . | 121 | 11 |
233,447 | def cli ( ctx , env ) : env . out ( "Welcome to the SoftLayer shell." ) env . out ( "" ) formatter = formatting . HelpFormatter ( ) commands = [ ] shell_commands = [ ] for name in cli_core . cli . list_commands ( ctx ) : command = cli_core . cli . get_command ( ctx , name ) if command . short_help is None : command . short_help = command . help details = ( name , command . short_help ) if name in dict ( routes . ALL_ROUTES ) : shell_commands . append ( details ) else : commands . append ( details ) with formatter . section ( 'Shell Commands' ) : formatter . write_dl ( shell_commands ) with formatter . section ( 'Commands' ) : formatter . write_dl ( commands ) for line in formatter . buffer : env . out ( line , newline = False ) | Print shell help text . | 213 | 5 |
233,448 | def cli ( env , identifier , postinstall , key ) : hardware = SoftLayer . HardwareManager ( env . client ) hardware_id = helpers . resolve_id ( hardware . resolve_ids , identifier , 'hardware' ) key_list = [ ] if key : for single_key in key : resolver = SoftLayer . SshKeyManager ( env . client ) . resolve_ids key_id = helpers . resolve_id ( resolver , single_key , 'SshKey' ) key_list . append ( key_id ) if not ( env . skip_confirmations or formatting . no_going_back ( hardware_id ) ) : raise exceptions . CLIAbort ( 'Aborted' ) hardware . reload ( hardware_id , postinstall , key_list ) | Reload operating system on a server . | 170 | 8 |
233,449 | def cli ( env , identifier , enabled , port , weight , healthcheck_type , ip_address ) : mgr = SoftLayer . LoadBalancerManager ( env . client ) loadbal_id , service_id = loadbal . parse_id ( identifier ) # check if any input is provided if ( ( not any ( [ ip_address , weight , port , healthcheck_type ] ) ) and enabled is None ) : raise exceptions . CLIAbort ( 'At least one property is required to be changed!' ) # check if the IP is valid ip_address_id = None if ip_address : ip_service = env . client [ 'Network_Subnet_IpAddress' ] ip_record = ip_service . getByIpAddress ( ip_address ) ip_address_id = ip_record [ 'id' ] mgr . edit_service ( loadbal_id , service_id , ip_address_id = ip_address_id , enabled = enabled , port = port , weight = weight , hc_type = healthcheck_type ) env . fout ( 'Load balancer service %s is being modified!' % identifier ) | Edit the properties of a service group . | 251 | 8 |
233,450 | def cli ( env , sortby , datacenter , identifier , subnet_type , network_space , ipv4 , ipv6 ) : mgr = SoftLayer . NetworkManager ( env . client ) table = formatting . Table ( [ 'id' , 'identifier' , 'type' , 'network_space' , 'datacenter' , 'vlan_id' , 'IPs' , 'hardware' , 'vs' , ] ) table . sortby = sortby version = 0 if ipv4 : version = 4 elif ipv6 : version = 6 subnets = mgr . list_subnets ( datacenter = datacenter , version = version , identifier = identifier , subnet_type = subnet_type , network_space = network_space , ) for subnet in subnets : table . add_row ( [ subnet [ 'id' ] , '%s/%s' % ( subnet [ 'networkIdentifier' ] , str ( subnet [ 'cidr' ] ) ) , subnet . get ( 'subnetType' , formatting . blank ( ) ) , utils . lookup ( subnet , 'networkVlan' , 'networkSpace' ) or formatting . blank ( ) , utils . lookup ( subnet , 'datacenter' , 'name' , ) or formatting . blank ( ) , subnet [ 'networkVlanId' ] , subnet [ 'ipAddressCount' ] , len ( subnet [ 'hardware' ] ) , len ( subnet [ 'virtualGuests' ] ) , ] ) env . fout ( table ) | List subnets . | 354 | 4 |
233,451 | def cli ( env , target , firewall_type , high_availability ) : mgr = SoftLayer . FirewallManager ( env . client ) if not env . skip_confirmations : if firewall_type == 'vlan' : pkg = mgr . get_dedicated_package ( ha_enabled = high_availability ) elif firewall_type == 'vs' : pkg = mgr . get_standard_package ( target , is_virt = True ) elif firewall_type == 'server' : pkg = mgr . get_standard_package ( target , is_virt = False ) if not pkg : exceptions . CLIAbort ( "Unable to add firewall - Is network public enabled?" ) env . out ( "******************" ) env . out ( "Product: %s" % pkg [ 0 ] [ 'description' ] ) env . out ( "Price: $%s monthly" % pkg [ 0 ] [ 'prices' ] [ 0 ] [ 'recurringFee' ] ) env . out ( "******************" ) if not formatting . confirm ( "This action will incur charges on your " "account. Continue?" ) : raise exceptions . CLIAbort ( 'Aborted.' ) if firewall_type == 'vlan' : mgr . add_vlan_firewall ( target , ha_enabled = high_availability ) elif firewall_type == 'vs' : mgr . add_standard_firewall ( target , is_virt = True ) elif firewall_type == 'server' : mgr . add_standard_firewall ( target , is_virt = False ) env . fout ( "Firewall is being created!" ) | Create new firewall . | 368 | 4 |
233,452 | def cli ( env , account_id , content_url ) : manager = SoftLayer . CDNManager ( env . client ) content_list = manager . purge_content ( account_id , content_url ) table = formatting . Table ( [ 'url' , 'status' ] ) for content in content_list : table . add_row ( [ content [ 'url' ] , content [ 'statusCode' ] ] ) env . fout ( table ) | Purge cached files from all edge nodes . | 99 | 9 |
233,453 | def cli ( env , package_keyname ) : manager = ordering . OrderingManager ( env . client ) table = formatting . Table ( COLUMNS ) locations = manager . package_locations ( package_keyname ) for region in locations : for datacenter in region [ 'locations' ] : table . add_row ( [ datacenter [ 'location' ] [ 'id' ] , datacenter [ 'location' ] [ 'name' ] , region [ 'description' ] , region [ 'keyname' ] ] ) env . fout ( table ) | List Datacenters a package can be ordered in . | 127 | 11 |
233,454 | def cli ( env , abuse , address1 , address2 , city , company , country , firstname , lastname , postal , public , state ) : mgr = SoftLayer . NetworkManager ( env . client ) update = { 'abuse_email' : abuse , 'address1' : address1 , 'address2' : address2 , 'company_name' : company , 'city' : city , 'country' : country , 'first_name' : firstname , 'last_name' : lastname , 'postal_code' : postal , 'state' : state , 'private_residence' : public , } if public is True : update [ 'private_residence' ] = False elif public is False : update [ 'private_residence' ] = True check = [ x for x in update . values ( ) if x is not None ] if not check : raise exceptions . CLIAbort ( "You must specify at least one field to update." ) mgr . edit_rwhois ( * * update ) | Edit the RWhois data on the account . | 224 | 10 |
233,455 | def cli ( env , quote , * * args ) : table = formatting . Table ( [ 'Id' , 'Name' , 'Created' , 'Expiration' , 'Status' ] ) create_args = _parse_create_args ( env . client , args ) manager = ordering . OrderingManager ( env . client ) quote_details = manager . get_quote_details ( quote ) package = quote_details [ 'order' ] [ 'items' ] [ 0 ] [ 'package' ] create_args [ 'packageId' ] = package [ 'id' ] if args . get ( 'verify' ) : result = manager . verify_quote ( quote , create_args ) verify_table = formatting . Table ( [ 'keyName' , 'description' , 'cost' ] ) verify_table . align [ 'keyName' ] = 'l' verify_table . align [ 'description' ] = 'l' for price in result [ 'prices' ] : cost_key = 'hourlyRecurringFee' if result [ 'useHourlyPricing' ] is True else 'recurringFee' verify_table . add_row ( [ price [ 'item' ] [ 'keyName' ] , price [ 'item' ] [ 'description' ] , price [ cost_key ] if cost_key in price else formatting . blank ( ) ] ) env . fout ( verify_table ) else : result = manager . order_quote ( quote , create_args ) table = formatting . KeyValueTable ( [ 'name' , 'value' ] ) table . align [ 'name' ] = 'r' table . align [ 'value' ] = 'l' table . add_row ( [ 'id' , result [ 'orderId' ] ] ) table . add_row ( [ 'created' , result [ 'orderDate' ] ] ) table . add_row ( [ 'status' , result [ 'placedOrder' ] [ 'status' ] ] ) env . fout ( table ) | View and Order a quote | 438 | 5 |
233,456 | def authorize_host_to_volume ( self , volume_id , hardware_ids = None , virtual_guest_ids = None , ip_address_ids = None , * * kwargs ) : host_templates = [ ] storage_utils . populate_host_templates ( host_templates , hardware_ids , virtual_guest_ids , ip_address_ids , None ) return self . client . call ( 'Network_Storage' , 'allowAccessFromHostList' , host_templates , id = volume_id , * * kwargs ) | Authorizes hosts to Block Storage Volumes | 125 | 8 |
233,457 | def order_replicant_volume ( self , volume_id , snapshot_schedule , location , tier = None , os_type = None ) : block_mask = 'billingItem[activeChildren,hourlyFlag],' 'storageTierLevel,osType,staasVersion,' 'hasEncryptionAtRest,snapshotCapacityGb,schedules,' 'intervalSchedule,hourlySchedule,dailySchedule,' 'weeklySchedule,storageType[keyName],provisionedIops' block_volume = self . get_block_volume_details ( volume_id , mask = block_mask ) if os_type is None : if isinstance ( utils . lookup ( block_volume , 'osType' , 'keyName' ) , str ) : os_type = block_volume [ 'osType' ] [ 'keyName' ] else : raise exceptions . SoftLayerError ( "Cannot find primary volume's os-type " "automatically; must specify manually" ) order = storage_utils . prepare_replicant_order_object ( self , snapshot_schedule , location , tier , block_volume , 'block' ) order [ 'osFormatType' ] = { 'keyName' : os_type } return self . client . call ( 'Product_Order' , 'placeOrder' , order ) | Places an order for a replicant block volume . | 292 | 12 |
233,458 | def order_duplicate_volume ( self , origin_volume_id , origin_snapshot_id = None , duplicate_size = None , duplicate_iops = None , duplicate_tier_level = None , duplicate_snapshot_size = None , hourly_billing_flag = False ) : block_mask = 'id,billingItem[location,hourlyFlag],snapshotCapacityGb,' 'storageType[keyName],capacityGb,originalVolumeSize,' 'provisionedIops,storageTierLevel,osType[keyName],' 'staasVersion,hasEncryptionAtRest' origin_volume = self . get_block_volume_details ( origin_volume_id , mask = block_mask ) if isinstance ( utils . lookup ( origin_volume , 'osType' , 'keyName' ) , str ) : os_type = origin_volume [ 'osType' ] [ 'keyName' ] else : raise exceptions . SoftLayerError ( "Cannot find origin volume's os-type" ) order = storage_utils . prepare_duplicate_order_object ( self , origin_volume , duplicate_iops , duplicate_tier_level , duplicate_size , duplicate_snapshot_size , 'block' , hourly_billing_flag ) order [ 'osFormatType' ] = { 'keyName' : os_type } if origin_snapshot_id is not None : order [ 'duplicateOriginSnapshotId' ] = origin_snapshot_id return self . client . call ( 'Product_Order' , 'placeOrder' , order ) | Places an order for a duplicate block volume . | 349 | 10 |
233,459 | def order_modified_volume ( self , volume_id , new_size = None , new_iops = None , new_tier_level = None ) : mask_items = [ 'id' , 'billingItem' , 'storageType[keyName]' , 'capacityGb' , 'provisionedIops' , 'storageTierLevel' , 'staasVersion' , 'hasEncryptionAtRest' , ] block_mask = ',' . join ( mask_items ) volume = self . get_block_volume_details ( volume_id , mask = block_mask ) order = storage_utils . prepare_modify_order_object ( self , volume , new_iops , new_tier_level , new_size ) return self . client . call ( 'Product_Order' , 'placeOrder' , order ) | Places an order for modifying an existing block volume . | 181 | 11 |
233,460 | def order_block_volume ( self , storage_type , location , size , os_type , iops = None , tier_level = None , snapshot_size = None , service_offering = 'storage_as_a_service' , hourly_billing_flag = False ) : order = storage_utils . prepare_volume_order_object ( self , storage_type , location , size , iops , tier_level , snapshot_size , service_offering , 'block' , hourly_billing_flag ) order [ 'osFormatType' ] = { 'keyName' : os_type } return self . client . call ( 'Product_Order' , 'placeOrder' , order ) | Places an order for a block volume . | 153 | 9 |
233,461 | def create_snapshot ( self , volume_id , notes = '' , * * kwargs ) : return self . client . call ( 'Network_Storage' , 'createSnapshot' , notes , id = volume_id , * * kwargs ) | Creates a snapshot on the given block volume . | 56 | 10 |
233,462 | def order_snapshot_space ( self , volume_id , capacity , tier , upgrade , * * kwargs ) : block_mask = 'id,billingItem[location,hourlyFlag],' 'storageType[keyName],storageTierLevel,provisionedIops,' 'staasVersion,hasEncryptionAtRest' block_volume = self . get_block_volume_details ( volume_id , mask = block_mask , * * kwargs ) order = storage_utils . prepare_snapshot_order_object ( self , block_volume , capacity , tier , upgrade ) return self . client . call ( 'Product_Order' , 'placeOrder' , order ) | Orders snapshot space for the given block volume . | 150 | 10 |
233,463 | def enable_snapshots ( self , volume_id , schedule_type , retention_count , minute , hour , day_of_week , * * kwargs ) : return self . client . call ( 'Network_Storage' , 'enableSnapshots' , schedule_type , retention_count , minute , hour , day_of_week , id = volume_id , * * kwargs ) | Enables snapshots for a specific block volume at a given schedule | 86 | 12 |
233,464 | def disable_snapshots ( self , volume_id , schedule_type ) : return self . client . call ( 'Network_Storage' , 'disableSnapshots' , schedule_type , id = volume_id ) | Disables snapshots for a specific block volume at a given schedule | 46 | 12 |
233,465 | def list_volume_schedules ( self , volume_id ) : volume_detail = self . client . call ( 'Network_Storage' , 'getObject' , id = volume_id , mask = 'schedules[type,properties[type]]' ) return utils . lookup ( volume_detail , 'schedules' ) | Lists schedules for a given volume | 74 | 7 |
233,466 | def restore_from_snapshot ( self , volume_id , snapshot_id ) : return self . client . call ( 'Network_Storage' , 'restoreFromSnapshot' , snapshot_id , id = volume_id ) | Restores a specific volume from a snapshot | 50 | 8 |
233,467 | def cancel_block_volume ( self , volume_id , reason = 'No longer needed' , immediate = False ) : block_volume = self . get_block_volume_details ( volume_id , mask = 'mask[id,billingItem[id,hourlyFlag]]' ) if 'billingItem' not in block_volume : raise exceptions . SoftLayerError ( "Block Storage was already cancelled" ) billing_item_id = block_volume [ 'billingItem' ] [ 'id' ] if utils . lookup ( block_volume , 'billingItem' , 'hourlyFlag' ) : immediate = True return self . client [ 'Billing_Item' ] . cancelItem ( immediate , True , reason , id = billing_item_id ) | Cancels the given block storage volume . | 167 | 9 |
233,468 | def failover_to_replicant ( self , volume_id , replicant_id , immediate = False ) : return self . client . call ( 'Network_Storage' , 'failoverToReplicant' , replicant_id , immediate , id = volume_id ) | Failover to a volume replicant . | 63 | 9 |
233,469 | def failback_from_replicant ( self , volume_id , replicant_id ) : return self . client . call ( 'Network_Storage' , 'failbackFromReplicant' , replicant_id , id = volume_id ) | Failback from a volume replicant . | 57 | 9 |
233,470 | def set_credential_password ( self , access_id , password ) : return self . client . call ( 'Network_Storage_Allowed_Host' , 'setCredentialPassword' , password , id = access_id ) | Sets the password for an access host | 52 | 8 |
233,471 | def create_or_update_lun_id ( self , volume_id , lun_id ) : return self . client . call ( 'Network_Storage' , 'createOrUpdateLunId' , lun_id , id = volume_id ) | Set the LUN ID on a volume . | 55 | 9 |
233,472 | def cli ( env , sortby ) : mgr = SoftLayer . NetworkManager ( env . client ) datacenters = mgr . summary_by_datacenter ( ) table = formatting . Table ( COLUMNS ) table . sortby = sortby for name , datacenter in datacenters . items ( ) : table . add_row ( [ name , datacenter [ 'hardware_count' ] , datacenter [ 'virtual_guest_count' ] , datacenter [ 'vlan_count' ] , datacenter [ 'subnet_count' ] , datacenter [ 'public_ip_count' ] , ] ) env . fout ( table ) | Account summary . | 152 | 3 |
233,473 | def get_packages_of_type ( self , package_types , mask = None ) : _filter = { 'type' : { 'keyName' : { 'operation' : 'in' , 'options' : [ { 'name' : 'data' , 'value' : package_types } ] , } , } , } packages = self . package_svc . getAllObjects ( mask = mask , filter = _filter ) packages = self . filter_outlet_packages ( packages ) return packages | Get packages that match a certain type . | 110 | 8 |
233,474 | def filter_outlet_packages ( packages ) : non_outlet_packages = [ ] for package in packages : if all ( [ 'OUTLET' not in package . get ( 'description' , '' ) . upper ( ) , 'OUTLET' not in package . get ( 'name' , '' ) . upper ( ) ] ) : non_outlet_packages . append ( package ) return non_outlet_packages | Remove packages designated as OUTLET . | 91 | 7 |
233,475 | def get_only_active_packages ( packages ) : active_packages = [ ] for package in packages : if package [ 'isActive' ] : active_packages . append ( package ) return active_packages | Return only active packages . | 44 | 5 |
233,476 | def get_package_by_type ( self , package_type , mask = None ) : packages = self . get_packages_of_type ( [ package_type ] , mask ) if len ( packages ) == 0 : return None else : return packages . pop ( ) | Get a single package of a given type . | 58 | 9 |
233,477 | def get_package_id_by_type ( self , package_type ) : mask = "mask[id, name, description, isActive, type[keyName]]" package = self . get_package_by_type ( package_type , mask ) if package : return package [ 'id' ] else : raise ValueError ( "No package found for type: " + package_type ) | Return the package ID of a Product Package with a given type . | 85 | 13 |
233,478 | def get_quotes ( self ) : mask = "mask[order[id,items[id,package[id,keyName]]]]" quotes = self . client [ 'Account' ] . getActiveQuotes ( mask = mask ) return quotes | Retrieve a list of active quotes . | 52 | 8 |
233,479 | def get_quote_details ( self , quote_id ) : mask = "mask[order[id,items[package[id,keyName]]]]" quote = self . client [ 'Billing_Order_Quote' ] . getObject ( id = quote_id , mask = mask ) return quote | Retrieve quote details . | 65 | 5 |
233,480 | def get_order_container ( self , quote_id ) : quote = self . client [ 'Billing_Order_Quote' ] container = quote . getRecalculatedOrderContainer ( id = quote_id ) return container | Generate an order container from a quote object . | 48 | 10 |
233,481 | def generate_order_template ( self , quote_id , extra , quantity = 1 ) : if not isinstance ( extra , dict ) : raise ValueError ( "extra is not formatted properly" ) container = self . get_order_container ( quote_id ) container [ 'quantity' ] = quantity for key in extra . keys ( ) : container [ key ] = extra [ key ] return container | Generate a complete order template . | 85 | 7 |
233,482 | def verify_quote ( self , quote_id , extra ) : container = self . generate_order_template ( quote_id , extra ) clean_container = { } # There are a few fields that wil cause exceptions in the XML endpoing if you send in '' # reservedCapacityId and hostId specifically. But we clean all just to be safe. # This for some reason is only a problem on verify_quote. for key in container . keys ( ) : if container . get ( key ) != '' : clean_container [ key ] = container [ key ] return self . client . call ( 'SoftLayer_Billing_Order_Quote' , 'verifyOrder' , clean_container , id = quote_id ) | Verifies that a quote order is valid . | 155 | 9 |
233,483 | def order_quote ( self , quote_id , extra ) : container = self . generate_order_template ( quote_id , extra ) return self . client . call ( 'SoftLayer_Billing_Order_Quote' , 'placeOrder' , container , id = quote_id ) | Places an order using a quote | 62 | 7 |
233,484 | def get_package_by_key ( self , package_keyname , mask = None ) : _filter = { 'keyName' : { 'operation' : package_keyname } } packages = self . package_svc . getAllObjects ( mask = mask , filter = _filter ) if len ( packages ) == 0 : raise exceptions . SoftLayerError ( "Package {} does not exist" . format ( package_keyname ) ) return packages . pop ( ) | Get a single package with a given key . | 104 | 9 |
233,485 | def list_categories ( self , package_keyname , * * kwargs ) : get_kwargs = { } get_kwargs [ 'mask' ] = kwargs . get ( 'mask' , CATEGORY_MASK ) if 'filter' in kwargs : get_kwargs [ 'filter' ] = kwargs [ 'filter' ] package = self . get_package_by_key ( package_keyname , mask = 'id' ) categories = self . package_svc . getConfiguration ( id = package [ 'id' ] , * * get_kwargs ) return categories | List the categories for the given package . | 137 | 8 |
233,486 | def list_items ( self , package_keyname , * * kwargs ) : get_kwargs = { } get_kwargs [ 'mask' ] = kwargs . get ( 'mask' , ITEM_MASK ) if 'filter' in kwargs : get_kwargs [ 'filter' ] = kwargs [ 'filter' ] package = self . get_package_by_key ( package_keyname , mask = 'id' ) items = self . package_svc . getItems ( id = package [ 'id' ] , * * get_kwargs ) return items | List the items for the given package . | 134 | 8 |
233,487 | def list_packages ( self , * * kwargs ) : get_kwargs = { } get_kwargs [ 'mask' ] = kwargs . get ( 'mask' , PACKAGE_MASK ) if 'filter' in kwargs : get_kwargs [ 'filter' ] = kwargs [ 'filter' ] packages = self . package_svc . getAllObjects ( * * get_kwargs ) return [ package for package in packages if package [ 'isActive' ] ] | List active packages . | 111 | 4 |
233,488 | def list_presets ( self , package_keyname , * * kwargs ) : get_kwargs = { } get_kwargs [ 'mask' ] = kwargs . get ( 'mask' , PRESET_MASK ) if 'filter' in kwargs : get_kwargs [ 'filter' ] = kwargs [ 'filter' ] package = self . get_package_by_key ( package_keyname , mask = 'id' ) acc_presets = self . package_svc . getAccountRestrictedActivePresets ( id = package [ 'id' ] , * * get_kwargs ) active_presets = self . package_svc . getActivePresets ( id = package [ 'id' ] , * * get_kwargs ) return active_presets + acc_presets | Gets active presets for the given package . | 184 | 9 |
233,489 | def get_preset_by_key ( self , package_keyname , preset_keyname , mask = None ) : preset_operation = '_= %s' % preset_keyname _filter = { 'activePresets' : { 'keyName' : { 'operation' : preset_operation } } , 'accountRestrictedActivePresets' : { 'keyName' : { 'operation' : preset_operation } } } presets = self . list_presets ( package_keyname , mask = mask , filter = _filter ) if len ( presets ) == 0 : raise exceptions . SoftLayerError ( "Preset {} does not exist in package {}" . format ( preset_keyname , package_keyname ) ) return presets [ 0 ] | Gets a single preset with the given key . | 169 | 10 |
233,490 | def get_price_id_list ( self , package_keyname , item_keynames , core = None ) : mask = 'id, itemCategory, keyName, prices[categories]' items = self . list_items ( package_keyname , mask = mask ) prices = [ ] category_dict = { "gpu0" : - 1 , "pcie_slot0" : - 1 } for item_keyname in item_keynames : try : # Need to find the item in the package that has a matching # keyName with the current item we are searching for matching_item = [ i for i in items if i [ 'keyName' ] == item_keyname ] [ 0 ] except IndexError : raise exceptions . SoftLayerError ( "Item {} does not exist for package {}" . format ( item_keyname , package_keyname ) ) # we want to get the price ID that has no location attached to it, # because that is the most generic price. verifyOrder/placeOrder # can take that ID and create the proper price for us in the location # in which the order is made item_category = matching_item [ 'itemCategory' ] [ 'categoryCode' ] if item_category not in category_dict : price_id = self . get_item_price_id ( core , matching_item [ 'prices' ] ) else : # GPU and PCIe items has two generic prices and they are added to the list # according to the number of items in the order. category_dict [ item_category ] += 1 category_code = item_category [ : - 1 ] + str ( category_dict [ item_category ] ) price_id = [ p [ 'id' ] for p in matching_item [ 'prices' ] if not p [ 'locationGroupId' ] and p [ 'categories' ] [ 0 ] [ 'categoryCode' ] == category_code ] [ 0 ] prices . append ( price_id ) return prices | Converts a list of item keynames to a list of price IDs . | 432 | 15 |
233,491 | def get_item_price_id ( core , prices ) : price_id = None for price in prices : if not price [ 'locationGroupId' ] : capacity_min = int ( price . get ( 'capacityRestrictionMinimum' , - 1 ) ) capacity_max = int ( price . get ( 'capacityRestrictionMaximum' , - 1 ) ) # return first match if no restirction, or no core to check if capacity_min == - 1 or core is None : price_id = price [ 'id' ] # this check is mostly to work nicely with preset configs elif capacity_min <= int ( core ) <= capacity_max : price_id = price [ 'id' ] return price_id | get item price id | 155 | 4 |
233,492 | def get_preset_prices ( self , preset ) : mask = 'mask[prices[item]]' prices = self . package_preset . getObject ( id = preset , mask = mask ) return prices | Get preset item prices . | 47 | 5 |
233,493 | def get_item_prices ( self , package_id ) : mask = 'mask[pricingLocationGroup[locations]]' prices = self . package_svc . getItemPrices ( id = package_id , mask = mask ) return prices | Get item prices . | 55 | 4 |
233,494 | def verify_order ( self , package_keyname , location , item_keynames , complex_type = None , hourly = True , preset_keyname = None , extras = None , quantity = 1 ) : order = self . generate_order ( package_keyname , location , item_keynames , complex_type = complex_type , hourly = hourly , preset_keyname = preset_keyname , extras = extras , quantity = quantity ) return self . order_svc . verifyOrder ( order ) | Verifies an order with the given package and prices . | 115 | 11 |
233,495 | def place_order ( self , package_keyname , location , item_keynames , complex_type = None , hourly = True , preset_keyname = None , extras = None , quantity = 1 ) : order = self . generate_order ( package_keyname , location , item_keynames , complex_type = complex_type , hourly = hourly , preset_keyname = preset_keyname , extras = extras , quantity = quantity ) return self . order_svc . placeOrder ( order ) | Places an order with the given package and prices . | 115 | 11 |
233,496 | def place_quote ( self , package_keyname , location , item_keynames , complex_type = None , preset_keyname = None , extras = None , quantity = 1 , quote_name = None , send_email = False ) : order = self . generate_order ( package_keyname , location , item_keynames , complex_type = complex_type , hourly = False , preset_keyname = preset_keyname , extras = extras , quantity = quantity ) order [ 'quoteName' ] = quote_name order [ 'sendQuoteEmailFlag' ] = send_email return self . order_svc . placeQuote ( order ) | Place a quote with the given package and prices . | 147 | 10 |
233,497 | def generate_order ( self , package_keyname , location , item_keynames , complex_type = None , hourly = True , preset_keyname = None , extras = None , quantity = 1 ) : container = { } order = { } extras = extras or { } package = self . get_package_by_key ( package_keyname , mask = 'id' ) # if there was extra data given for the order, add it to the order # example: VSIs require hostname and domain set on the order, so # extras will be {'virtualGuests': [{'hostname': 'test', # 'domain': 'softlayer.com'}]} order . update ( extras ) order [ 'packageId' ] = package [ 'id' ] order [ 'quantity' ] = quantity order [ 'location' ] = self . get_location_id ( location ) order [ 'useHourlyPricing' ] = hourly preset_core = None if preset_keyname : preset_id = self . get_preset_by_key ( package_keyname , preset_keyname ) [ 'id' ] preset_items = self . get_preset_prices ( preset_id ) for item in preset_items [ 'prices' ] : if item [ 'item' ] [ 'itemCategory' ] [ 'categoryCode' ] == "guest_core" : preset_core = item [ 'item' ] [ 'capacity' ] order [ 'presetId' ] = preset_id if not complex_type : raise exceptions . SoftLayerError ( "A complex type must be specified with the order" ) order [ 'complexType' ] = complex_type price_ids = self . get_price_id_list ( package_keyname , item_keynames , preset_core ) order [ 'prices' ] = [ { 'id' : price_id } for price_id in price_ids ] container [ 'orderContainers' ] = [ order ] return container | Generates an order with the given package and prices . | 444 | 11 |
233,498 | def package_locations ( self , package_keyname ) : mask = "mask[description, keyname, locations]" package = self . get_package_by_key ( package_keyname , mask = 'id' ) regions = self . package_svc . getRegions ( id = package [ 'id' ] , mask = mask ) return regions | List datacenter locations for a package keyname | 79 | 10 |
233,499 | def get_location_id ( self , location ) : if isinstance ( location , int ) : return location mask = "mask[id,name,regions[keyname]]" if match ( r'[a-zA-Z]{3}[0-9]{2}' , location ) is not None : search = { 'name' : { 'operation' : location } } else : search = { 'regions' : { 'keyname' : { 'operation' : location } } } datacenter = self . client . call ( 'SoftLayer_Location' , 'getDatacenters' , mask = mask , filter = search ) if len ( datacenter ) != 1 : raise exceptions . SoftLayerError ( "Unable to find location: %s" % location ) return datacenter [ 0 ] [ 'id' ] | Finds the location ID of a given datacenter | 187 | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.