idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
45,600
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' ] 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 .
45,601
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 .
45,602
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 .
45,603
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 .
45,604
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' ) ] ) updates = ticket . get ( 'updates' , [ ] ) count = min ( len ( updates ) , update_count ) count_offset = len ( updates ) - count + 1 for i , update in enumerate ( updates [ - count : ] ) : wrapped_entry = "" 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' ) ) 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 .
45,605
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 .
45,606
def list_tickets ( self , open_status = True , closed_status = True ) : mask = 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 .
45,607
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 .
45,608
def update_ticket ( self , ticket_id = None , body = None ) : return self . ticket . addUpdate ( { 'entry' : body } , id = ticket_id )
Update a ticket .
45,609
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 .
45,610
def attach_hardware ( self , ticket_id = None , hardware_id = None ) : return self . ticket . addAttachedHardware ( hardware_id , id = ticket_id )
Attach hardware to a ticket .
45,611
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 .
45,612
def detach_hardware ( self , ticket_id = None , hardware_id = None ) : return self . ticket . removeAttachedHardware ( hardware_id , id = ticket_id )
Detach hardware from a ticket .
45,613
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 .
45,614
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 .
45,615
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 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' ) ) 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 .
45,616
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' ) if name is None : name = "@" ttl = record_search . group ( 'ttl' ) record_type = record_search . group ( 'type' ) . upper ( ) data = record_search . group ( 'data' ) if record_type == "MX" : record_search = re . search ( r'(?P<weight>\d+)\s+(?P<data>.*)' , data ) data = record_search . group ( 'data' ) 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 .
45,617
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 .
45,618
def cli ( env , zone ) : manager = SoftLayer . DNSManager ( env . client ) manager . create_zone ( zone )
Create a zone .
45,619
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 .
45,620
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 .
45,621
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 .
45,622
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 .
45,623
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 .
45,624
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 .
45,625
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 .
45,626
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 .
45,627
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 .
45,628
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 ] group_speeds = [ ] for group in grouped : group_speed = 0 for interface in group : group_speed += interface [ 'maxSpeed' ] group_speeds . append ( group_speed ) 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 .
45,629
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 .
45,630
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 .
45,631
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 .
45,632
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 .
45,633
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 .
45,634
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 .
45,635
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 .
45,636
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 .
45,637
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 .
45,638
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
45,639
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 .
45,640
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 .
45,641
def convert ( self , value , param , ctx ) : 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' ] : 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 .
45,642
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 .
45,643
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 .
45,644
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 .
45,645
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 .
45,646
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 .
45,647
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 .
45,648
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 .
45,649
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 .
45,650
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 .
45,651
def get_event_logs ( self , request_filter = None , log_limit = 20 , iterator = True ) : if iterator : 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
45,652
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
45,653
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 .
45,654
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 .
45,655
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 .
45,656
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 .
45,657
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
45,658
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
45,659
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
45,660
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
45,661
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
45,662
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
45,663
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
45,664
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 .
45,665
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 .
45,666
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 .
45,667
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
45,668
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
45,669
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 .
45,670
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
45,671
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 .
45,672
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
45,673
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
45,674
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 .
45,675
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 .
45,676
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 .
45,677
def populate_host_templates ( host_templates , hardware_ids = None , virtual_guest_ids = None , ip_address_ids = None , subnet_ids = None ) : if hardware_ids is not None : for hardware_id in hardware_ids : host_templates . append ( { 'objectType' : 'SoftLayer_Hardware' , 'id' : hardware_id } ) if virtual_guest_ids is not None : for virtual_guest_id in virtual_guest_ids : host_templates . append ( { 'objectType' : 'SoftLayer_Virtual_Guest' , 'id' : virtual_guest_id } ) if ip_address_ids is not None : for ip_address_id in ip_address_ids : host_templates . append ( { 'objectType' : 'SoftLayer_Network_Subnet_IpAddress' , 'id' : ip_address_id } ) if subnet_ids is not None : for subnet_id in subnet_ids : host_templates . append ( { 'objectType' : 'SoftLayer_Network_Subnet' , 'id' : subnet_id } )
Populate the given host_templates array with the IDs provided
45,678
def get_package ( manager , category_code ) : _filter = utils . NestedDict ( { } ) _filter [ 'categories' ] [ 'categoryCode' ] = ( utils . query_filter ( category_code ) ) _filter [ 'statusCode' ] = ( utils . query_filter ( 'ACTIVE' ) ) packages = manager . client . call ( 'Product_Package' , 'getAllObjects' , filter = _filter . to_dict ( ) , mask = 'id,name,items[prices[categories],attributes]' ) if len ( packages ) == 0 : raise ValueError ( 'No packages were found for %s' % category_code ) if len ( packages ) > 1 : raise ValueError ( 'More than one package was found for %s' % category_code ) return packages [ 0 ]
Returns a product package based on type of storage .
45,679
def get_location_id ( manager , location ) : loc_svc = manager . client [ 'Location_Datacenter' ] datacenters = loc_svc . getDatacenters ( mask = 'mask[longName,id,name]' ) for datacenter in datacenters : if datacenter [ 'name' ] == location : location = datacenter [ 'id' ] return location raise ValueError ( 'Invalid datacenter name specified.' )
Returns location id
45,680
def find_price_by_category ( package , price_category ) : for item in package [ 'items' ] : price_id = _find_price_id ( item [ 'prices' ] , price_category ) if price_id : return price_id raise ValueError ( "Could not find price with the category, %s" % price_category )
Find the price in the given package that has the specified category
45,681
def find_ent_space_price ( package , category , size , tier_level ) : if category == 'snapshot' : category_code = 'storage_snapshot_space' elif category == 'replication' : category_code = 'performance_storage_replication' else : category_code = 'performance_storage_space' level = ENDURANCE_TIERS . get ( tier_level ) for item in package [ 'items' ] : if int ( item [ 'capacity' ] ) != size : continue price_id = _find_price_id ( item [ 'prices' ] , category_code , 'STORAGE_TIER_LEVEL' , level ) if price_id : return price_id raise ValueError ( "Could not find price for %s storage space" % category )
Find the space price for the given category size and tier
45,682
def find_ent_endurance_tier_price ( package , tier_level ) : for item in package [ 'items' ] : for attribute in item . get ( 'attributes' , [ ] ) : if int ( attribute [ 'value' ] ) == ENDURANCE_TIERS . get ( tier_level ) : break else : continue price_id = _find_price_id ( item [ 'prices' ] , 'storage_tier_level' ) if price_id : return price_id raise ValueError ( "Could not find price for endurance tier level" )
Find the price in the given package with the specified tier level
45,683
def find_perf_space_price ( package , size ) : for item in package [ 'items' ] : if int ( item [ 'capacity' ] ) != size : continue price_id = _find_price_id ( item [ 'prices' ] , 'performance_storage_space' ) if price_id : return price_id raise ValueError ( "Could not find performance space price for this volume" )
Find the price in the given package with the specified size
45,684
def find_perf_iops_price ( package , size , iops ) : for item in package [ 'items' ] : if int ( item [ 'capacity' ] ) != int ( iops ) : continue price_id = _find_price_id ( item [ 'prices' ] , 'performance_storage_iops' , 'STORAGE_SPACE' , size ) if price_id : return price_id raise ValueError ( "Could not find price for iops for the given volume" )
Find the price in the given package with the specified size and iops
45,685
def find_saas_endurance_space_price ( package , size , tier_level ) : if tier_level != 0.25 : tier_level = int ( tier_level ) key_name = 'STORAGE_SPACE_FOR_{0}_IOPS_PER_GB' . format ( tier_level ) key_name = key_name . replace ( "." , "_" ) for item in package [ 'items' ] : if key_name not in item [ 'keyName' ] : continue if 'capacityMinimum' not in item or 'capacityMaximum' not in item : continue capacity_minimum = int ( item [ 'capacityMinimum' ] ) capacity_maximum = int ( item [ 'capacityMaximum' ] ) if size < capacity_minimum or size > capacity_maximum : continue price_id = _find_price_id ( item [ 'prices' ] , 'performance_storage_space' ) if price_id : return price_id raise ValueError ( "Could not find price for endurance storage space" )
Find the SaaS endurance storage space price for the size and tier
45,686
def find_saas_endurance_tier_price ( package , tier_level ) : target_capacity = ENDURANCE_TIERS . get ( tier_level ) for item in package [ 'items' ] : if 'itemCategory' not in item or 'categoryCode' not in item [ 'itemCategory' ] or item [ 'itemCategory' ] [ 'categoryCode' ] != 'storage_tier_level' : continue if int ( item [ 'capacity' ] ) != target_capacity : continue price_id = _find_price_id ( item [ 'prices' ] , 'storage_tier_level' ) if price_id : return price_id raise ValueError ( "Could not find price for endurance tier level" )
Find the SaaS storage tier level price for the specified tier level
45,687
def find_saas_perform_space_price ( package , size ) : for item in package [ 'items' ] : if 'itemCategory' not in item or 'categoryCode' not in item [ 'itemCategory' ] or item [ 'itemCategory' ] [ 'categoryCode' ] != 'performance_storage_space' : continue if 'capacityMinimum' not in item or 'capacityMaximum' not in item : continue capacity_minimum = int ( item [ 'capacityMinimum' ] ) capacity_maximum = int ( item [ 'capacityMaximum' ] ) if size < capacity_minimum or size > capacity_maximum : continue key_name = '{0}_{1}_GBS' . format ( capacity_minimum , capacity_maximum ) if item [ 'keyName' ] != key_name : continue price_id = _find_price_id ( item [ 'prices' ] , 'performance_storage_space' ) if price_id : return price_id raise ValueError ( "Could not find price for performance storage space" )
Find the SaaS performance storage space price for the given size
45,688
def find_saas_perform_iops_price ( package , size , iops ) : for item in package [ 'items' ] : if 'itemCategory' not in item or 'categoryCode' not in item [ 'itemCategory' ] or item [ 'itemCategory' ] [ 'categoryCode' ] != 'performance_storage_iops' : continue if 'capacityMinimum' not in item or 'capacityMaximum' not in item : continue capacity_minimum = int ( item [ 'capacityMinimum' ] ) capacity_maximum = int ( item [ 'capacityMaximum' ] ) if iops < capacity_minimum or iops > capacity_maximum : continue price_id = _find_price_id ( item [ 'prices' ] , 'performance_storage_iops' , 'STORAGE_SPACE' , size ) if price_id : return price_id raise ValueError ( "Could not find price for iops for the given volume" )
Find the SaaS IOPS price for the specified size and iops
45,689
def find_saas_snapshot_space_price ( package , size , tier = None , iops = None ) : if tier is not None : target_value = ENDURANCE_TIERS . get ( tier ) target_restriction_type = 'STORAGE_TIER_LEVEL' else : target_value = iops target_restriction_type = 'IOPS' for item in package [ 'items' ] : if int ( item [ 'capacity' ] ) != size : continue price_id = _find_price_id ( item [ 'prices' ] , 'storage_snapshot_space' , target_restriction_type , target_value ) if price_id : return price_id raise ValueError ( "Could not find price for snapshot space" )
Find the price in the SaaS package for the desired snapshot space size
45,690
def find_saas_replication_price ( package , tier = None , iops = None ) : if tier is not None : target_value = ENDURANCE_TIERS . get ( tier ) target_item_keyname = 'REPLICATION_FOR_TIERBASED_PERFORMANCE' target_restriction_type = 'STORAGE_TIER_LEVEL' else : target_value = iops target_item_keyname = 'REPLICATION_FOR_IOPSBASED_PERFORMANCE' target_restriction_type = 'IOPS' for item in package [ 'items' ] : if item [ 'keyName' ] != target_item_keyname : continue price_id = _find_price_id ( item [ 'prices' ] , 'performance_storage_replication' , target_restriction_type , target_value ) if price_id : return price_id raise ValueError ( "Could not find price for replicant volume" )
Find the price in the given package for the desired replicant volume
45,691
def find_snapshot_schedule_id ( volume , snapshot_schedule_keyname ) : for schedule in volume [ 'schedules' ] : if 'type' in schedule and 'keyname' in schedule [ 'type' ] : if schedule [ 'type' ] [ 'keyname' ] == snapshot_schedule_keyname : return schedule [ 'id' ] raise ValueError ( "The given snapshot schedule ID was not found for " "the given storage volume" )
Find the snapshot schedule ID for the given volume and keyname
45,692
def cli ( env , volume_id , reason , immediate ) : file_storage_manager = SoftLayer . FileStorageManager ( env . client ) if not ( env . skip_confirmations or formatting . no_going_back ( volume_id ) ) : raise exceptions . CLIAbort ( 'Aborted' ) cancelled = file_storage_manager . cancel_snapshot_space ( volume_id , reason , immediate ) if cancelled : if immediate : click . echo ( 'File volume with id %s has been marked' ' for immediate snapshot cancellation' % volume_id ) else : click . echo ( 'File volume with id %s has been marked' ' for snapshot cancellation' % volume_id ) else : click . echo ( 'Unable to cancel snapshot space for file volume %s' % volume_id )
Cancel existing snapshot space for a given volume .
45,693
def get_by_request_id ( env , request_id ) : mgr = SoftLayer . NetworkManager ( env . client ) logs = mgr . get_event_logs_by_request_id ( request_id ) table = formatting . Table ( COLUMNS ) table . align [ 'metadata' ] = "l" for log in logs : metadata = json . dumps ( json . loads ( log [ 'metaData' ] ) , indent = 4 , sort_keys = True ) table . add_row ( [ log [ 'eventName' ] , log [ 'label' ] , log [ 'eventCreateDate' ] , metadata ] ) env . fout ( table )
Search for event logs by request id
45,694
def cli ( env , title , subject_id , body , hardware_identifier , virtual_identifier , priority ) : ticket_mgr = SoftLayer . TicketManager ( env . client ) if body is None : body = click . edit ( '\n\n' + ticket . TEMPLATE_MSG ) created_ticket = ticket_mgr . create_ticket ( title = title , body = body , subject = subject_id , priority = priority ) 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 ( created_ticket [ 'id' ] , hardware_id ) if 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 ( created_ticket [ 'id' ] , vs_id ) env . fout ( ticket . get_ticket_results ( ticket_mgr , created_ticket [ 'id' ] ) )
Create a support ticket .
45,695
def cli ( env , volume_id , replicant_id ) : file_storage_manager = SoftLayer . FileStorageManager ( env . client ) success = file_storage_manager . failback_from_replicant ( volume_id , replicant_id ) if success : click . echo ( "Failback from replicant is now in progress." ) else : click . echo ( "Failback operation could not be initiated." )
Failback a file volume from the given replicant volume .
45,696
def cli ( env , volume_id , snapshot_id ) : file_manager = SoftLayer . FileStorageManager ( env . client ) success = file_manager . restore_from_snapshot ( volume_id , snapshot_id ) if success : click . echo ( 'File volume %s is being restored using snapshot %s' % ( volume_id , snapshot_id ) )
Restore file volume using a given snapshot
45,697
def cli ( env ) : settings = config . get_settings_from_client ( env . client ) env . fout ( config . config_table ( settings ) )
Show current configuration .
45,698
def cli ( env , storage_type , size , iops , tier , location , snapshot_size , service_offering , billing ) : file_manager = SoftLayer . FileStorageManager ( env . client ) storage_type = storage_type . lower ( ) hourly_billing_flag = False if billing . lower ( ) == "hourly" : hourly_billing_flag = True if service_offering != 'storage_as_a_service' : click . secho ( '{} is a legacy storage offering' . format ( service_offering ) , fg = 'red' ) if hourly_billing_flag : raise exceptions . CLIAbort ( 'Hourly billing is only available for the storage_as_a_service service offering' ) if storage_type == 'performance' : if iops is None : raise exceptions . CLIAbort ( 'Option --iops required with Performance' ) if service_offering == 'performance' and snapshot_size is not None : raise exceptions . CLIAbort ( '--snapshot-size is not available for performance service offerings. ' 'Use --service-offering storage_as_a_service' ) try : order = file_manager . order_file_volume ( storage_type = storage_type , location = location , size = size , iops = iops , snapshot_size = snapshot_size , service_offering = service_offering , hourly_billing_flag = hourly_billing_flag ) except ValueError as ex : raise exceptions . ArgumentError ( str ( ex ) ) if storage_type == 'endurance' : if tier is None : raise exceptions . CLIAbort ( 'Option --tier required with Endurance in IOPS/GB [0.25,2,4,10]' ) try : order = file_manager . order_file_volume ( storage_type = storage_type , location = location , size = size , tier_level = float ( tier ) , snapshot_size = snapshot_size , service_offering = service_offering , hourly_billing_flag = hourly_billing_flag ) except ValueError as ex : raise exceptions . ArgumentError ( str ( ex ) ) if 'placedOrder' in order . keys ( ) : click . echo ( "Order #{0} placed successfully!" . format ( order [ 'placedOrder' ] [ 'id' ] ) ) for item in order [ 'placedOrder' ] [ 'items' ] : click . echo ( " > %s" % item [ 'description' ] ) else : click . echo ( "Order could not be placed! Please verify your options and try again." )
Order a file storage volume .
45,699
def cli ( env , ** args ) : create_args = _parse_create_args ( env . client , args ) create_args [ 'primary_disk' ] = args . get ( 'primary_disk' ) manager = CapacityManager ( env . client ) capacity_id = args . get ( 'capacity_id' ) test = args . get ( 'test' ) result = manager . create_guest ( capacity_id , test , create_args ) env . fout ( _build_receipt ( result , test ) )
Allows for creating a virtual guest in a reserved capacity .