idx
int64 0
63k
| question
stringlengths 61
4.03k
| target
stringlengths 6
1.23k
|
|---|---|---|
8,800
|
def get_upload_path ( instance , filename ) : if not instance . name : instance . name = filename date = timezone . now ( ) . date ( ) filename = '{name}.{ext}' . format ( name = uuid4 ( ) . hex , ext = filename . split ( '.' ) [ - 1 ] ) return os . path . join ( 'post_office_attachments' , str ( date . year ) , str ( date . month ) , str ( date . day ) , filename )
|
Overriding to store the original filename
|
8,801
|
def create ( sender , recipients = None , cc = None , bcc = None , subject = '' , message = '' , html_message = '' , context = None , scheduled_time = None , headers = None , template = None , priority = None , render_on_delivery = False , commit = True , backend = '' ) : priority = parse_priority ( priority ) status = None if priority == PRIORITY . now else STATUS . queued if recipients is None : recipients = [ ] if cc is None : cc = [ ] if bcc is None : bcc = [ ] if context is None : context = '' if render_on_delivery : email = Email ( from_email = sender , to = recipients , cc = cc , bcc = bcc , scheduled_time = scheduled_time , headers = headers , priority = priority , status = status , context = context , template = template , backend_alias = backend ) else : if template : subject = template . subject message = template . content html_message = template . html_content _context = Context ( context or { } ) subject = Template ( subject ) . render ( _context ) message = Template ( message ) . render ( _context ) html_message = Template ( html_message ) . render ( _context ) email = Email ( from_email = sender , to = recipients , cc = cc , bcc = bcc , subject = subject , message = message , html_message = html_message , scheduled_time = scheduled_time , headers = headers , priority = priority , status = status , backend_alias = backend ) if commit : email . save ( ) return email
|
Creates an email from supplied keyword arguments . If template is specified email subject and content will be rendered during delivery .
|
8,802
|
def send_queued ( processes = 1 , log_level = None ) : queued_emails = get_queued ( ) total_sent , total_failed = 0 , 0 total_email = len ( queued_emails ) logger . info ( 'Started sending %s emails with %s processes.' % ( total_email , processes ) ) if log_level is None : log_level = get_log_level ( ) if queued_emails : if total_email < processes : processes = total_email if processes == 1 : total_sent , total_failed = _send_bulk ( queued_emails , uses_multiprocessing = False , log_level = log_level ) else : email_lists = split_emails ( queued_emails , processes ) pool = Pool ( processes ) results = pool . map ( _send_bulk , email_lists ) pool . terminate ( ) total_sent = sum ( [ result [ 0 ] for result in results ] ) total_failed = sum ( [ result [ 1 ] for result in results ] ) message = '%s emails attempted, %s sent, %s failed' % ( total_email , total_sent , total_failed ) logger . info ( message ) return ( total_sent , total_failed )
|
Sends out all queued mails that has scheduled_time less than now or None
|
8,803
|
def send_messages ( self , email_messages ) : from . mail import create from . utils import create_attachments if not email_messages : return for email_message in email_messages : subject = email_message . subject from_email = email_message . from_email message = email_message . body headers = email_message . extra_headers alternatives = getattr ( email_message , 'alternatives' , ( ) ) for alternative in alternatives : if alternative [ 1 ] . startswith ( 'text/html' ) : html_message = alternative [ 0 ] break else : html_message = '' attachment_files = { } for attachment in email_message . attachments : if isinstance ( attachment , MIMEBase ) : attachment_files [ attachment . get_filename ( ) ] = { 'file' : ContentFile ( attachment . get_payload ( ) ) , 'mimetype' : attachment . get_content_type ( ) , 'headers' : OrderedDict ( attachment . items ( ) ) , } else : attachment_files [ attachment [ 0 ] ] = ContentFile ( attachment [ 1 ] ) email = create ( sender = from_email , recipients = email_message . to , cc = email_message . cc , bcc = email_message . bcc , subject = subject , message = message , html_message = html_message , headers = headers ) if attachment_files : attachments = create_attachments ( attachment_files ) email . attachments . add ( * attachments ) if get_default_priority ( ) == 'now' : email . dispatch ( )
|
Queue one or more EmailMessage objects and returns the number of email messages sent .
|
8,804
|
def valid_lock ( self ) : lock_pid = self . get_lock_pid ( ) if lock_pid is None : return False if self . _pid == lock_pid : return True try : os . kill ( lock_pid , 0 ) except OSError : self . release ( ) return False return True
|
See if the lock exists and is left over from an old process .
|
8,805
|
def release ( self ) : if self . lock_filename != self . pid_filename : try : os . unlink ( self . lock_filename ) except OSError : pass try : os . remove ( self . pid_filename ) except OSError : pass
|
Try to delete the lock files . Doesn t matter if we fail
|
8,806
|
def validate_email_with_name ( value ) : value = force_text ( value ) recipient = value if '<' and '>' in value : start = value . find ( '<' ) + 1 end = value . find ( '>' ) if start < end : recipient = value [ start : end ] validate_email ( recipient )
|
Validate email address .
|
8,807
|
def validate_comma_separated_emails ( value ) : if not isinstance ( value , ( tuple , list ) ) : raise ValidationError ( 'Email list must be a list/tuple.' ) for email in value : try : validate_email_with_name ( email ) except ValidationError : raise ValidationError ( 'Invalid email: %s' % email , code = 'invalid' )
|
Validate every email address in a comma separated list of emails .
|
8,808
|
def validate_template_syntax ( source ) : try : Template ( source ) except ( TemplateSyntaxError , TemplateDoesNotExist ) as err : raise ValidationError ( text_type ( err ) )
|
Basic Django Template syntax validation . This allows for robuster template authoring .
|
8,809
|
def send_mail ( subject , message , from_email , recipient_list , html_message = '' , scheduled_time = None , headers = None , priority = PRIORITY . medium ) : subject = force_text ( subject ) status = None if priority == PRIORITY . now else STATUS . queued emails = [ ] for address in recipient_list : emails . append ( Email . objects . create ( from_email = from_email , to = address , subject = subject , message = message , html_message = html_message , status = status , headers = headers , priority = priority , scheduled_time = scheduled_time ) ) if priority == PRIORITY . now : for email in emails : email . dispatch ( ) return emails
|
Add a new message to the mail queue . This is a replacement for Django s send_mail core email method .
|
8,810
|
def get_email_template ( name , language = '' ) : use_cache = getattr ( settings , 'POST_OFFICE_CACHE' , True ) if use_cache : use_cache = getattr ( settings , 'POST_OFFICE_TEMPLATE_CACHE' , True ) if not use_cache : return EmailTemplate . objects . get ( name = name , language = language ) else : composite_name = '%s:%s' % ( name , language ) email_template = cache . get ( composite_name ) if email_template is not None : return email_template else : email_template = EmailTemplate . objects . get ( name = name , language = language ) cache . set ( composite_name , email_template ) return email_template
|
Function that returns an email template instance from cache or DB .
|
8,811
|
def create_attachments ( attachment_files ) : attachments = [ ] for filename , filedata in attachment_files . items ( ) : if isinstance ( filedata , dict ) : content = filedata . get ( 'file' , None ) mimetype = filedata . get ( 'mimetype' , None ) headers = filedata . get ( 'headers' , None ) else : content = filedata mimetype = None headers = None opened_file = None if isinstance ( content , string_types ) : opened_file = open ( content , 'rb' ) content = File ( opened_file ) attachment = Attachment ( ) if mimetype : attachment . mimetype = mimetype attachment . headers = headers attachment . file . save ( filename , content = content , save = True ) attachments . append ( attachment ) if opened_file is not None : opened_file . close ( ) return attachments
|
Create Attachment instances from files
|
8,812
|
def parse_emails ( emails ) : if isinstance ( emails , string_types ) : emails = [ emails ] elif emails is None : emails = [ ] for email in emails : try : validate_email_with_name ( email ) except ValidationError : raise ValidationError ( '%s is not a valid email address' % email ) return emails
|
A function that returns a list of valid email addresses . This function will also convert a single email address into a list of email addresses . None value is also converted into an empty list .
|
8,813
|
def VERSION ( self ) : return int ( re . match ( r'^(\D+)(\d+)$' , self . __class__ . __name__ ) . group ( 2 ) )
|
TAN mechanism version
|
8,814
|
def parse_message ( self , data : bytes ) -> SegmentSequence : if isinstance ( data , bytes ) : data = self . explode_segments ( data ) message = SegmentSequence ( ) for segment in data : seg = self . parse_segment ( segment ) message . segments . append ( seg ) return message
|
Takes a FinTS 3 . 0 message as byte array and returns a parsed segment sequence
|
8,815
|
def terminal_flicker_unix ( code , field_width = 3 , space_width = 3 , height = 1 , clear = False , wait = 0.05 ) : code = parse ( code ) . render ( ) data = swap_bytes ( code ) high = '\033[48;05;15m' low = '\033[48;05;0m' std = '\033[0m' stream = [ '10000' , '00000' , '11111' , '01111' , '11111' , '01111' , '11111' ] for c in data : v = int ( c , 16 ) stream . append ( '1' + str ( v & 1 ) + str ( ( v & 2 ) >> 1 ) + str ( ( v & 4 ) >> 2 ) + str ( ( v & 8 ) >> 3 ) ) stream . append ( '0' + str ( v & 1 ) + str ( ( v & 2 ) >> 1 ) + str ( ( v & 4 ) >> 2 ) + str ( ( v & 8 ) >> 3 ) ) while True : for frame in stream : if clear : print ( '\033c' , end = '' ) for i in range ( height ) : for c in frame : print ( low + ' ' * space_width , end = '' ) if c == '1' : print ( high + ' ' * field_width , end = '' ) else : print ( low + ' ' * field_width , end = '' ) print ( low + ' ' * space_width + std ) time . sleep ( wait )
|
Re - encodes a flicker code and prints it on a unix terminal .
|
8,816
|
def find_segments ( self , query = None , version = None , callback = None , recurse = True , throw = False ) : found_something = False if query is None : query = [ ] elif isinstance ( query , str ) or not isinstance ( query , ( list , tuple , Iterable ) ) : query = [ query ] if version is None : version = [ ] elif not isinstance ( version , ( list , tuple , Iterable ) ) : version = [ version ] if callback is None : callback = lambda s : True for s in self . segments : if ( ( not query ) or any ( ( isinstance ( s , t ) if isinstance ( t , type ) else s . header . type == t ) for t in query ) ) and ( ( not version ) or any ( s . header . version == v for v in version ) ) and callback ( s ) : yield s found_something = True if recurse : for name , field in s . _fields . items ( ) : val = getattr ( s , name ) if val and hasattr ( val , 'find_segments' ) : for v in val . find_segments ( query = query , version = version , callback = callback , recurse = recurse ) : yield v found_something = True if throw and not found_something : raise FinTSNoResponseError ( 'The bank\'s response did not contain a response to your request, please inspect debug log.' )
|
Yields an iterable of all matching segments .
|
8,817
|
def find_segment_first ( self , * args , ** kwargs ) : for m in self . find_segments ( * args , ** kwargs ) : return m return None
|
Finds the first matching segment .
|
8,818
|
def find_segment_highest_version ( self , query = None , version = None , callback = None , recurse = True , default = None ) : retval = None for s in self . find_segments ( query = query , version = version , callback = callback , recurse = recurse ) : if not retval or s . header . version > retval . header . version : retval = s if retval is None : return default return retval
|
Finds the highest matching segment .
|
8,819
|
def print_nested ( self , stream = None , level = 0 , indent = " " , prefix = "" , first_level_indent = True , trailer = "" , print_doc = True , first_line_suffix = "" ) : import sys stream = stream or sys . stdout stream . write ( ( ( prefix + level * indent ) if first_level_indent else "" ) + "{}.{}(" . format ( self . __class__ . __module__ , self . __class__ . __name__ ) + first_line_suffix + "\n" ) for name , value in self . _repr_items : val = getattr ( self , name ) if print_doc and not name . startswith ( "_" ) : docstring = self . _fields [ name ] . _inline_doc_comment ( val ) else : docstring = "" if not hasattr ( getattr ( val , 'print_nested' , None ) , '__call__' ) : stream . write ( ( prefix + ( level + 1 ) * indent ) + "{} = {!r},{}\n" . format ( name , val , docstring ) ) else : stream . write ( ( prefix + ( level + 1 ) * indent ) + "{} = " . format ( name ) ) val . print_nested ( stream = stream , level = level + 2 , indent = indent , prefix = prefix , first_level_indent = False , trailer = "," , print_doc = print_doc , first_line_suffix = docstring ) stream . write ( ( prefix + level * indent ) + "){}\n" . format ( trailer ) )
|
Structured nested print of the object to the given stream .
|
8,820
|
def from_data ( cls , blob ) : version , data = decompress_datablob ( DATA_BLOB_MAGIC_RETRY , blob ) if version == 1 : for clazz in cls . _all_subclasses ( ) : if clazz . __name__ == data [ "_class_name" ] : return clazz . _from_data_v1 ( data ) raise Exception ( "Invalid data blob data or version" )
|
Restore an object instance from a compressed datablob .
|
8,821
|
def deconstruct ( self , including_private : bool = False ) -> bytes : data = self . _deconstruct_v1 ( including_private = including_private ) return compress_datablob ( DATA_BLOB_MAGIC , 1 , data )
|
Return state of this FinTSClient instance as an opaque datablob . You should not use this object after calling this method .
|
8,822
|
def get_information ( self ) : retval = { 'bank' : { } , 'accounts' : [ ] , 'auth' : { } , } if self . bpa : retval [ 'bank' ] [ 'name' ] = self . bpa . bank_name if self . bpd . segments : retval [ 'bank' ] [ 'supported_operations' ] = { op : any ( self . bpd . find_segment_first ( cmd [ 0 ] + 'I' + cmd [ 2 : ] + 'S' ) for cmd in op . value ) for op in FinTSOperations } hispas = self . bpd . find_segment_first ( 'HISPAS' ) if hispas : retval [ 'bank' ] [ 'supported_sepa_formats' ] = list ( hispas . parameter . supported_sepa_formats ) else : retval [ 'bank' ] [ 'supported_sepa_formats' ] = [ ] if self . upd . segments : for upd in self . upd . find_segments ( 'HIUPD' ) : acc = { } acc [ 'iban' ] = upd . iban acc [ 'account_number' ] = upd . account_information . account_number acc [ 'subaccount_number' ] = upd . account_information . subaccount_number acc [ 'bank_identifier' ] = upd . account_information . bank_identifier acc [ 'customer_id' ] = upd . customer_id acc [ 'type' ] = upd . account_type acc [ 'currency' ] = upd . account_currency acc [ 'owner_name' ] = [ ] if upd . name_account_owner_1 : acc [ 'owner_name' ] . append ( upd . name_account_owner_1 ) if upd . name_account_owner_2 : acc [ 'owner_name' ] . append ( upd . name_account_owner_2 ) acc [ 'product_name' ] = upd . account_product_name acc [ 'supported_operations' ] = { op : any ( allowed_transaction . transaction in op . value for allowed_transaction in upd . allowed_transactions ) for op in FinTSOperations } retval [ 'accounts' ] . append ( acc ) return retval
|
Return information about the connected bank .
|
8,823
|
def get_sepa_accounts ( self ) : with self . _get_dialog ( ) as dialog : response = dialog . send ( HKSPA1 ( ) ) self . accounts = [ ] for seg in response . find_segments ( HISPA1 , throw = True ) : self . accounts . extend ( seg . accounts ) return [ a for a in [ acc . as_sepa_account ( ) for acc in self . accounts ] if a ]
|
Returns a list of SEPA accounts
|
8,824
|
def _find_highest_supported_command ( self , * segment_classes , ** kwargs ) : return_parameter_segment = kwargs . get ( "return_parameter_segment" , False ) parameter_segment_name = "{}I{}S" . format ( segment_classes [ 0 ] . TYPE [ 0 ] , segment_classes [ 0 ] . TYPE [ 2 : ] ) version_map = dict ( ( clazz . VERSION , clazz ) for clazz in segment_classes ) max_version = self . bpd . find_segment_highest_version ( parameter_segment_name , version_map . keys ( ) ) if not max_version : raise FinTSUnsupportedOperation ( 'No supported {} version found. I support {}, bank supports {}.' . format ( parameter_segment_name , tuple ( version_map . keys ( ) ) , tuple ( v . header . version for v in self . bpd . find_segments ( parameter_segment_name ) ) ) ) if return_parameter_segment : return max_version , version_map . get ( max_version . header . version ) else : return version_map . get ( max_version . header . version )
|
Search the BPD for the highest supported version of a segment .
|
8,825
|
def get_transactions ( self , account : SEPAAccount , start_date : datetime . date = None , end_date : datetime . date = None ) : with self . _get_dialog ( ) as dialog : hkkaz = self . _find_highest_supported_command ( HKKAZ5 , HKKAZ6 , HKKAZ7 ) logger . info ( 'Start fetching from {} to {}' . format ( start_date , end_date ) ) responses = self . _fetch_with_touchdowns ( dialog , lambda touchdown : hkkaz ( account = hkkaz . _fields [ 'account' ] . type . from_sepa_account ( account ) , all_accounts = False , date_start = start_date , date_end = end_date , touchdown_point = touchdown , ) , 'HIKAZ' ) logger . info ( 'Fetching done.' ) statement = [ ] for seg in responses : statement += mt940_to_array ( seg . statement_booked . decode ( 'iso-8859-1' ) ) logger . debug ( 'Statement: {}' . format ( statement ) ) return statement
|
Fetches the list of transactions of a bank account in a certain timeframe .
|
8,826
|
def get_transactions_xml ( self , account : SEPAAccount , start_date : datetime . date = None , end_date : datetime . date = None ) -> list : with self . _get_dialog ( ) as dialog : hkcaz = self . _find_highest_supported_command ( HKCAZ1 ) logger . info ( 'Start fetching from {} to {}' . format ( start_date , end_date ) ) responses = self . _fetch_with_touchdowns ( dialog , lambda touchdown : hkcaz ( account = hkcaz . _fields [ 'account' ] . type . from_sepa_account ( account ) , all_accounts = False , date_start = start_date , date_end = end_date , touchdown_point = touchdown , supported_camt_messages = SupportedMessageTypes ( 'urn:iso:std:iso:20022:tech:xsd:camt.052.001.02' ) , ) , 'HICAZ' ) logger . info ( 'Fetching done.' ) xml_streams = [ ] for seg in responses : xml_streams . append ( seg . statement_booked ) return xml_streams
|
Fetches the list of transactions of a bank account in a certain timeframe as camt . 052 . 001 . 02 XML files .
|
8,827
|
def get_balance ( self , account : SEPAAccount ) : with self . _get_dialog ( ) as dialog : hksal = self . _find_highest_supported_command ( HKSAL5 , HKSAL6 , HKSAL7 ) seg = hksal ( account = hksal . _fields [ 'account' ] . type . from_sepa_account ( account ) , all_accounts = False , ) response = dialog . send ( seg ) for resp in response . response_segments ( seg , 'HISAL' ) : return resp . balance_booked . as_mt940_Balance ( )
|
Fetches an accounts current balance .
|
8,828
|
def get_holdings ( self , account : SEPAAccount ) : with self . _get_dialog ( ) as dialog : hkwpd = self . _find_highest_supported_command ( HKWPD5 , HKWPD6 ) responses = self . _fetch_with_touchdowns ( dialog , lambda touchdown : hkwpd ( account = hkwpd . _fields [ 'account' ] . type . from_sepa_account ( account ) , touchdown_point = touchdown , ) , 'HIWPD' ) holdings = [ ] for resp in responses : if type ( resp . holdings ) == bytes : holding_str = resp . holdings . decode ( ) else : holding_str = resp . holdings mt535_lines = str . splitlines ( holding_str ) del mt535_lines [ 0 ] mt535 = MT535_Miniparser ( ) holdings . extend ( mt535 . parse ( mt535_lines ) ) if not holdings : logger . debug ( 'No HIWPD response segment found - maybe account has no holdings?' ) return holdings
|
Retrieve holdings of an account .
|
8,829
|
def simple_sepa_transfer ( self , account : SEPAAccount , iban : str , bic : str , recipient_name : str , amount : Decimal , account_name : str , reason : str , endtoend_id = 'NOTPROVIDED' ) : config = { "name" : account_name , "IBAN" : account . iban , "BIC" : account . bic , "batch" : False , "currency" : "EUR" , } sepa = SepaTransfer ( config , 'pain.001.001.03' ) payment = { "name" : recipient_name , "IBAN" : iban , "BIC" : bic , "amount" : round ( Decimal ( amount ) * 100 ) , "execution_date" : datetime . date ( 1999 , 1 , 1 ) , "description" : reason , "endtoend_id" : endtoend_id , } sepa . add_payment ( payment ) xml = sepa . export ( ) . decode ( ) return self . sepa_transfer ( account , xml )
|
Simple SEPA transfer .
|
8,830
|
def sepa_transfer ( self , account : SEPAAccount , pain_message : str , multiple = False , control_sum = None , currency = 'EUR' , book_as_single = False , pain_descriptor = 'urn:iso:std:iso:20022:tech:xsd:pain.001.001.03' ) : with self . _get_dialog ( ) as dialog : if multiple : command_class = HKCCM1 else : command_class = HKCCS1 hiccxs , hkccx = self . _find_highest_supported_command ( command_class , return_parameter_segment = True ) seg = hkccx ( account = hkccx . _fields [ 'account' ] . type . from_sepa_account ( account ) , sepa_descriptor = pain_descriptor , sepa_pain_message = pain_message . encode ( ) , ) if multiple : if hiccxs . parameter . sum_amount_required and control_sum is None : raise ValueError ( "Control sum required." ) if book_as_single and not hiccxs . parameter . single_booking_allowed : raise FinTSUnsupportedOperation ( "Single booking not allowed by bank." ) if control_sum : seg . sum_amount . amount = control_sum seg . sum_amount . currency = currency if book_as_single : seg . request_single_booking = True return self . _send_with_possible_retry ( dialog , seg , self . _continue_sepa_transfer )
|
Custom SEPA transfer .
|
8,831
|
def sepa_debit ( self , account : SEPAAccount , pain_message : str , multiple = False , cor1 = False , control_sum = None , currency = 'EUR' , book_as_single = False , pain_descriptor = 'urn:iso:std:iso:20022:tech:xsd:pain.008.003.01' ) : with self . _get_dialog ( ) as dialog : if multiple : if cor1 : command_candidates = ( HKDMC1 , ) else : command_candidates = ( HKDME1 , HKDME2 ) else : if cor1 : command_candidates = ( HKDSC1 , ) else : command_candidates = ( HKDSE1 , HKDSE2 ) hidxxs , hkdxx = self . _find_highest_supported_command ( * command_candidates , return_parameter_segment = True ) seg = hkdxx ( account = hkdxx . _fields [ 'account' ] . type . from_sepa_account ( account ) , sepa_descriptor = pain_descriptor , sepa_pain_message = pain_message . encode ( ) , ) if multiple : if hidxxs . parameter . sum_amount_required and control_sum is None : raise ValueError ( "Control sum required." ) if book_as_single and not hidxxs . parameter . single_booking_allowed : raise FinTSUnsupportedOperation ( "Single booking not allowed by bank." ) if control_sum : seg . sum_amount . amount = control_sum seg . sum_amount . currency = currency if book_as_single : seg . request_single_booking = True return self . _send_with_possible_retry ( dialog , seg , self . _continue_sepa_debit )
|
Custom SEPA debit .
|
8,832
|
def send_tan ( self , challenge : NeedTANResponse , tan : str ) : with self . _get_dialog ( ) as dialog : tan_seg = self . _get_tan_segment ( challenge . command_seg , '2' , challenge . tan_request ) self . _pending_tan = tan response = dialog . send ( tan_seg ) resume_func = getattr ( self , challenge . resume_method ) return resume_func ( challenge . command_seg , response )
|
Sends a TAN to confirm a pending operation .
|
8,833
|
def get_tan_mechanisms ( self ) : retval = OrderedDict ( ) for version in sorted ( IMPLEMENTED_HKTAN_VERSIONS . keys ( ) ) : for seg in self . bpd . find_segments ( 'HITANS' , version ) : for parameter in seg . parameter . twostep_parameters : if parameter . security_function in self . allowed_security_functions : retval [ parameter . security_function ] = parameter return retval
|
Get the available TAN mechanisms .
|
8,834
|
def _generate_MAC ( segments = 6 , segment_length = 2 , delimiter = ":" , charset = "0123456789abcdef" ) : addr = [ ] for _ in range ( segments ) : sub = '' . join ( random . choice ( charset ) for _ in range ( segment_length ) ) addr . append ( sub ) return delimiter . join ( addr )
|
generate a non - guaranteed - unique mac address
|
8,835
|
def recv ( self , packet , interface ) : for f in self . filters : if not packet : break packet = f . tr ( packet , interface ) if packet : self . inq [ interface ] . put ( packet )
|
run incoming packet through the filters then place it in its inq
|
8,836
|
def send ( self , packet , interfaces = None ) : interfaces = interfaces or self . interfaces interfaces = interfaces if hasattr ( interfaces , '__iter__' ) else [ interfaces ] for interface in interfaces : for f in self . filters : packet = f . tx ( packet , interface ) if packet : interface . send ( packet )
|
write packet to given interfaces default is broadcast to all interfaces
|
8,837
|
def match ( cls , pattern , inverse = False ) : string_pattern = pattern invert_search = inverse class DefinedStringFilter ( cls ) : pattern = string_pattern inverse = invert_search return DefinedStringFilter
|
Factory method to create a StringFilter which filters with the given pattern .
|
8,838
|
def run_cmd ( command , verbose = True , shell = '/bin/bash' ) : process = Popen ( command , shell = True , stdout = PIPE , stderr = STDOUT , executable = shell ) output = process . stdout . read ( ) . decode ( ) . strip ( ) . split ( '\n' ) if verbose : return output return [ line for line in output if line . strip ( ) ]
|
internal helper function to run shell commands and get output
|
8,839
|
def run_python ( cmd , timeout = 60 ) : try : try : buffer = StringIO ( ) sys . stdout = buffer exec ( cmd ) sys . stdout = sys . __stdout__ out = buffer . getvalue ( ) except Exception as error : out = error out = str ( out ) . strip ( ) if len ( out ) < 1 : try : out = "[eval]: " + str ( eval ( cmd ) ) except Exception as error : out = "[eval]: " + str ( error ) else : out = "[exec]: " + out except Exception as python_exception : out = "[X]: %s" % python_exception return out . strip ( )
|
interactively interpret recieved python code
|
8,840
|
def run_shell ( cmd , timeout = 60 , verbose = False ) : retcode = None try : p = Popen ( cmd , shell = True , stdout = PIPE , stderr = STDOUT , executable = '/bin/bash' ) continue_running = True except Exception as e : yield ( "Failed: %s" % e ) continue_running = False while continue_running : try : line = p . stdout . readline ( ) if verbose and line : yield ( line ) elif line . strip ( ) : yield ( line . strip ( ) ) except Exception : pass try : data = irc . recv ( 4096 ) except Exception as e : data = "" retcode = p . poll ( ) if '!cancel' in data : retcode = "Cancelled live output reading. You have to kill the process manually." yield "[X]: %s" % retcode break elif retcode is not None : try : line = p . stdout . read ( ) except : retcode = "Too much output, read timed out. Process is still running in background." if verbose and line : yield line if retcode != 0 : yield "[X]: %s" % retcode elif retcode == 0 and verbose : yield "[√]" break
|
run a shell command and return the output verbose enables live command output via yield
|
8,841
|
def get_platform ( ) : mac_version = str ( platform . mac_ver ( ) [ 0 ] ) . strip ( ) if mac_version : return 'OS X %s' % mac_version return platform . platform ( ) . strip ( )
|
get Mac OS X version or kernel version if mac version is not found
|
8,842
|
def email ( to = 'medusa@sweeting.me' , _from = default_from , subject = 'BOT MSG' , message = "Info email" , attachments = None ) : for attachment in attachments or [ ] : filename = attachment . strip ( ) try : result = run_cmd ( 'uuencode %s %s | mailx -s "%s" %s' % ( filename , filename , subject , to ) ) [ 0 ] return "Sending email From: %s; To: %s; Subject: %s; Attachment: %s (%s)" % ( _from , to , subject , filename , result or 'Succeded' ) except Exception as error : return str ( error ) if not attachments : p = os . popen ( "/usr/sbin/sendmail -t" , "w" ) p . write ( "From: %s\n" % _from ) p . write ( "To: %s\n" % to ) p . write ( "Subject: %s\n" % subject ) p . write ( "\n" ) p . write ( '%s\n' % message ) result = p . close ( ) if not result : return "Sent email From: %s; To: %s; Subject: %s; Attachments: %s)" % ( _from , to , subject , ',' . join ( attachments or [ ] ) ) else : return "Error: %s. Please fix Postfix:\n %s" % ( result , help_str )
|
function to send mail to a specified address with the given attachments
|
8,843
|
def log ( self , * args ) : print ( "%s %s" % ( str ( self ) . ljust ( 8 ) , " " . join ( [ str ( x ) for x in args ] ) ) )
|
stdout and stderr for the link
|
8,844
|
def recv ( self , mac_addr = broadcast_addr , timeout = 0 ) : if self . keep_listening : try : return self . inq [ str ( mac_addr ) ] . get ( timeout = timeout ) except Empty : return "" else : self . log ( "is down." )
|
read packet off the recv queue for a given address optional timeout to block and wait for packet
|
8,845
|
def register_on_network_adapter_changed ( self , callback ) : event_type = library . VBoxEventType . on_network_adapter_changed return self . event_source . register_callback ( callback , event_type )
|
Set the callback function to consume on network adapter changed events .
|
8,846
|
def register_on_medium_changed ( self , callback ) : event_type = library . VBoxEventType . on_medium_changed return self . event_source . register_callback ( callback , event_type )
|
Set the callback function to consume on medium changed events .
|
8,847
|
def register_on_clipboard_mode_changed ( self , callback ) : event_type = library . VBoxEventType . on_clipboard_mode_changed return self . event_source . register_callback ( callback , event_type )
|
Set the callback function to consume on clipboard mode changed events .
|
8,848
|
def register_on_drag_and_drop_mode_changed ( self , callback ) : event_type = library . VBoxEventType . on_drag_and_drop_mode_changed return self . event_source . register_callback ( callback , event_type )
|
Set the callback function to consume on drag and drop mode changed events .
|
8,849
|
def register_on_shared_folder_changed ( self , callback ) : event_type = library . VBoxEventType . on_shared_folder_changed return self . event_source . register_callback ( callback , event_type )
|
Set the callback function to consume on shared folder changed events .
|
8,850
|
def register_on_additions_state_changed ( self , callback ) : event_type = library . VBoxEventType . on_additions_state_change return self . event_source . register_callback ( callback , event_type )
|
Set the callback function to consume on additions state changed events .
|
8,851
|
def register_on_state_changed ( self , callback ) : event_type = library . VBoxEventType . on_state_changed return self . event_source . register_callback ( callback , event_type )
|
Set the callback function to consume on state changed events which are generated when the state of the machine changes .
|
8,852
|
def register_on_event_source_changed ( self , callback ) : event_type = library . VBoxEventType . on_event_source_changed return self . event_source . register_callback ( callback , event_type )
|
Set the callback function to consume on event source changed events . This occurs when a listener is added or removed .
|
8,853
|
def register_on_can_show_window ( self , callback ) : event_type = library . VBoxEventType . on_can_show_window return self . event_source . register_callback ( callback , event_type )
|
Set the callback function to consume on can show window events . This occurs when the console window is to be activated and brought to the foreground of the desktop of the host PC . If this behaviour is not desired a call to event . add_veto will stop this from happening .
|
8,854
|
def register_on_show_window ( self , callback ) : event_type = library . VBoxEventType . on_show_window return self . event_source . register_callback ( callback , event_type )
|
Set the callback function to consume on show window events . This occurs when the console window is to be activated and brought to the foreground of the desktop of the host PC .
|
8,855
|
def manager ( self , value ) : "Set the manager object in the global _managers dict." pid = current_process ( ) . ident if _managers is None : raise RuntimeError ( "Can not set the manager following a system exit." ) if pid not in _managers : _managers [ pid ] = value else : raise Exception ( "Manager already set for pid %s" % pid )
|
Set the manager object in the global _managers dict .
|
8,856
|
def get_session ( self ) : if hasattr ( self . manager , 'mgr' ) : manager = getattr ( self . manager , 'mgr' ) else : manager = self . manager return Session ( interface = manager . getSessionObject ( None ) )
|
Return a Session interface
|
8,857
|
def cast_object ( self , interface_object , interface_class ) : name = interface_class . __name__ i = self . manager . queryInterface ( interface_object . _i , name ) return interface_class ( interface = i )
|
Cast the obj to the interface class
|
8,858
|
def _lock ( self , timeout_ms = - 1 ) : vbox = VirtualBox ( ) machine = vbox . find_machine ( self . machine_name ) wait_time = 0 while True : session = Session ( ) try : machine . lock_machine ( session , LockType . write ) except Exception as exc : if timeout_ms != - 1 and wait_time > timeout_ms : raise ValueError ( "Failed to acquire lock - %s" % exc ) time . sleep ( 1 ) wait_time += 1000 else : try : yield session finally : session . unlock_machine ( ) break
|
Exclusive lock over root machine
|
8,859
|
def _clones ( self ) : vbox = VirtualBox ( ) machines = [ ] for machine in vbox . machines : if machine . name == self . machine_name : continue if machine . name . startswith ( self . machine_name ) : machines . append ( machine ) return machines
|
Yield all machines under this pool
|
8,860
|
def acquire ( self , username , password , frontend = 'headless' ) : with self . _lock ( ) as root_session : for clone in self . _clones : session = Session ( ) try : clone . lock_machine ( session , LockType . write ) except Exception : continue else : try : p = session . machine . restore_snapshot ( ) p . wait_for_completion ( 60 * 1000 ) except Exception : pass session . unlock_machine ( ) break else : machine = root_session . machine clone = machine . clone ( name = "%s Pool" % self . machine_name ) p = clone . launch_vm_process ( type_p = frontend ) p . wait_for_completion ( 60 * 1000 ) session = clone . create_session ( ) console = session . console guest = console . guest try : guest_session = guest . create_session ( username , password , timeout_ms = 300 * 1000 ) idle_count = 0 timeout = 60 while idle_count < 5 and timeout > 0 : act = console . get_device_activity ( [ DeviceType . hard_disk ] ) if act [ 0 ] == DeviceActivity . idle : idle_count += 1 time . sleep ( 0.5 ) timeout -= 0.5 guest_session . close ( ) console . pause ( ) p , id_p = console . machine . take_snapshot ( 'initialised' , 'machine pool' , True ) p . wait_for_completion ( 60 * 1000 ) self . _power_down ( session ) finally : if session . state == SessionState . locked : session . unlock_machine ( ) p = clone . launch_vm_process ( type_p = frontend ) p . wait_for_completion ( 60 * 1000 ) session = clone . create_session ( ) return session
|
Acquire a Machine resource .
|
8,861
|
def release ( self , session ) : if session . state != SessionState . locked : return with self . _lock ( ) : return self . _power_down ( session )
|
Release a machine session resource .
|
8,862
|
def add_port_forward_rule ( self , is_ipv6 , rule_name , proto , host_ip , host_port , guest_ip , guest_port ) : if not isinstance ( is_ipv6 , bool ) : raise TypeError ( "is_ipv6 can only be an instance of type bool" ) if not isinstance ( rule_name , basestring ) : raise TypeError ( "rule_name can only be an instance of type basestring" ) if not isinstance ( proto , NATProtocol ) : raise TypeError ( "proto can only be an instance of type NATProtocol" ) if not isinstance ( host_ip , basestring ) : raise TypeError ( "host_ip can only be an instance of type basestring" ) if not isinstance ( host_port , baseinteger ) : raise TypeError ( "host_port can only be an instance of type baseinteger" ) if not isinstance ( guest_ip , basestring ) : raise TypeError ( "guest_ip can only be an instance of type basestring" ) if not isinstance ( guest_port , baseinteger ) : raise TypeError ( "guest_port can only be an instance of type baseinteger" ) self . _call ( "addPortForwardRule" , in_p = [ is_ipv6 , rule_name , proto , host_ip , host_port , guest_ip , guest_port ] )
|
Protocol handled with the rule .
|
8,863
|
def start ( self , trunk_type ) : if not isinstance ( trunk_type , basestring ) : raise TypeError ( "trunk_type can only be an instance of type basestring" ) self . _call ( "start" , in_p = [ trunk_type ] )
|
Type of internal network trunk .
|
8,864
|
def remove_vm_slot_options ( self , vmname , slot ) : if not isinstance ( vmname , basestring ) : raise TypeError ( "vmname can only be an instance of type basestring" ) if not isinstance ( slot , baseinteger ) : raise TypeError ( "slot can only be an instance of type baseinteger" ) self . _call ( "removeVmSlotOptions" , in_p = [ vmname , slot ] )
|
removes all option for the specified adapter
|
8,865
|
def set_configuration ( self , ip_address , network_mask , from_ip_address , to_ip_address ) : if not isinstance ( ip_address , basestring ) : raise TypeError ( "ip_address can only be an instance of type basestring" ) if not isinstance ( network_mask , basestring ) : raise TypeError ( "network_mask can only be an instance of type basestring" ) if not isinstance ( from_ip_address , basestring ) : raise TypeError ( "from_ip_address can only be an instance of type basestring" ) if not isinstance ( to_ip_address , basestring ) : raise TypeError ( "to_ip_address can only be an instance of type basestring" ) self . _call ( "setConfiguration" , in_p = [ ip_address , network_mask , from_ip_address , to_ip_address ] )
|
configures the server
|
8,866
|
def start ( self , network_name , trunk_name , trunk_type ) : if not isinstance ( network_name , basestring ) : raise TypeError ( "network_name can only be an instance of type basestring" ) if not isinstance ( trunk_name , basestring ) : raise TypeError ( "trunk_name can only be an instance of type basestring" ) if not isinstance ( trunk_type , basestring ) : raise TypeError ( "trunk_type can only be an instance of type basestring" ) self . _call ( "start" , in_p = [ network_name , trunk_name , trunk_type ] )
|
Starts DHCP server process .
|
8,867
|
def find_machine ( self , name_or_id ) : if not isinstance ( name_or_id , basestring ) : raise TypeError ( "name_or_id can only be an instance of type basestring" ) machine = self . _call ( "findMachine" , in_p = [ name_or_id ] ) machine = IMachine ( machine ) return machine
|
Attempts to find a virtual machine given its name or UUID . Inaccessible machines cannot be found by name only by UUID because their name cannot safely be determined .
|
8,868
|
def get_machines_by_groups ( self , groups ) : if not isinstance ( groups , list ) : raise TypeError ( "groups can only be an instance of type list" ) for a in groups [ : 10 ] : if not isinstance ( a , basestring ) : raise TypeError ( "array can only contain objects of type basestring" ) machines = self . _call ( "getMachinesByGroups" , in_p = [ groups ] ) machines = [ IMachine ( a ) for a in machines ] return machines
|
Gets all machine references which are in one of the specified groups .
|
8,869
|
def get_machine_states ( self , machines ) : if not isinstance ( machines , list ) : raise TypeError ( "machines can only be an instance of type list" ) for a in machines [ : 10 ] : if not isinstance ( a , IMachine ) : raise TypeError ( "array can only contain objects of type IMachine" ) states = self . _call ( "getMachineStates" , in_p = [ machines ] ) states = [ MachineState ( a ) for a in states ] return states
|
Gets the state of several machines in a single operation .
|
8,870
|
def set_settings_secret ( self , password ) : if not isinstance ( password , basestring ) : raise TypeError ( "password can only be an instance of type basestring" ) self . _call ( "setSettingsSecret" , in_p = [ password ] )
|
Unlocks the secret data by passing the unlock password to the server . The server will cache the password for that machine .
|
8,871
|
def create_dhcp_server ( self , name ) : if not isinstance ( name , basestring ) : raise TypeError ( "name can only be an instance of type basestring" ) server = self . _call ( "createDHCPServer" , in_p = [ name ] ) server = IDHCPServer ( server ) return server
|
Creates a DHCP server settings to be used for the given internal network name
|
8,872
|
def remove_dhcp_server ( self , server ) : if not isinstance ( server , IDHCPServer ) : raise TypeError ( "server can only be an instance of type IDHCPServer" ) self . _call ( "removeDHCPServer" , in_p = [ server ] )
|
Removes the DHCP server settings
|
8,873
|
def check_firmware_present ( self , firmware_type , version ) : if not isinstance ( firmware_type , FirmwareType ) : raise TypeError ( "firmware_type can only be an instance of type FirmwareType" ) if not isinstance ( version , basestring ) : raise TypeError ( "version can only be an instance of type basestring" ) ( result , url , file_p ) = self . _call ( "checkFirmwarePresent" , in_p = [ firmware_type , version ] ) return ( result , url , file_p )
|
Check if this VirtualBox installation has a firmware of the given type available either system - wide or per - user . Optionally this may return a hint where this firmware can be downloaded from .
|
8,874
|
def cd ( self , dir_p ) : if not isinstance ( dir_p , basestring ) : raise TypeError ( "dir_p can only be an instance of type basestring" ) progress = self . _call ( "cd" , in_p = [ dir_p ] ) progress = IProgress ( progress ) return progress
|
Change the current directory level .
|
8,875
|
def exists ( self , names ) : if not isinstance ( names , list ) : raise TypeError ( "names can only be an instance of type list" ) for a in names [ : 10 ] : if not isinstance ( a , basestring ) : raise TypeError ( "array can only contain objects of type basestring" ) exists = self . _call ( "exists" , in_p = [ names ] ) return exists
|
Checks if the given file list exists in the current directory level .
|
8,876
|
def remove ( self , names ) : if not isinstance ( names , list ) : raise TypeError ( "names can only be an instance of type list" ) for a in names [ : 10 ] : if not isinstance ( a , basestring ) : raise TypeError ( "array can only contain objects of type basestring" ) progress = self . _call ( "remove" , in_p = [ names ] ) progress = IProgress ( progress ) return progress
|
Deletes the given files in the current directory level .
|
8,877
|
def query_info ( self , what ) : if not isinstance ( what , baseinteger ) : raise TypeError ( "what can only be an instance of type baseinteger" ) result = self . _call ( "queryInfo" , in_p = [ what ] ) return result
|
Way to extend the interface .
|
8,878
|
def get_medium_ids_for_password_id ( self , password_id ) : if not isinstance ( password_id , basestring ) : raise TypeError ( "password_id can only be an instance of type basestring" ) identifiers = self . _call ( "getMediumIdsForPasswordId" , in_p = [ password_id ] ) return identifiers
|
Returns a list of medium identifiers which use the given password identifier .
|
8,879
|
def add_passwords ( self , identifiers , passwords ) : if not isinstance ( identifiers , list ) : raise TypeError ( "identifiers can only be an instance of type list" ) for a in identifiers [ : 10 ] : if not isinstance ( a , basestring ) : raise TypeError ( "array can only contain objects of type basestring" ) if not isinstance ( passwords , list ) : raise TypeError ( "passwords can only be an instance of type list" ) for a in passwords [ : 10 ] : if not isinstance ( a , basestring ) : raise TypeError ( "array can only contain objects of type basestring" ) self . _call ( "addPasswords" , in_p = [ identifiers , passwords ] )
|
Adds a list of passwords required to import or export encrypted virtual machines .
|
8,880
|
def remove_description_by_type ( self , type_p ) : if not isinstance ( type_p , VirtualSystemDescriptionType ) : raise TypeError ( "type_p can only be an instance of type VirtualSystemDescriptionType" ) self . _call ( "removeDescriptionByType" , in_p = [ type_p ] )
|
Delete all records which are equal to the passed type from the list
|
8,881
|
def update_state ( self , state ) : if not isinstance ( state , MachineState ) : raise TypeError ( "state can only be an instance of type MachineState" ) self . _call ( "updateState" , in_p = [ state ] )
|
Updates the VM state . This operation will also update the settings file with the correct information about the saved state file and delete this file from disk when appropriate .
|
8,882
|
def on_session_end ( self , session ) : if not isinstance ( session , ISession ) : raise TypeError ( "session can only be an instance of type ISession" ) progress = self . _call ( "onSessionEnd" , in_p = [ session ] ) progress = IProgress ( progress ) return progress
|
Triggered by the given session object when the session is about to close normally .
|
8,883
|
def pull_guest_properties ( self ) : ( names , values , timestamps , flags ) = self . _call ( "pullGuestProperties" ) return ( names , values , timestamps , flags )
|
Get the list of the guest properties matching a set of patterns along with their values timestamps and flags and give responsibility for managing properties to the console .
|
8,884
|
def push_guest_property ( self , name , value , timestamp , flags ) : if not isinstance ( name , basestring ) : raise TypeError ( "name can only be an instance of type basestring" ) if not isinstance ( value , basestring ) : raise TypeError ( "value can only be an instance of type basestring" ) if not isinstance ( timestamp , baseinteger ) : raise TypeError ( "timestamp can only be an instance of type baseinteger" ) if not isinstance ( flags , basestring ) : raise TypeError ( "flags can only be an instance of type basestring" ) self . _call ( "pushGuestProperty" , in_p = [ name , value , timestamp , flags ] )
|
Update a single guest property in IMachine .
|
8,885
|
def eject_medium ( self , attachment ) : if not isinstance ( attachment , IMediumAttachment ) : raise TypeError ( "attachment can only be an instance of type IMediumAttachment" ) new_attachment = self . _call ( "ejectMedium" , in_p = [ attachment ] ) new_attachment = IMediumAttachment ( new_attachment ) return new_attachment
|
Tells VBoxSVC that the guest has ejected the medium associated with the medium attachment .
|
8,886
|
def authenticate_external ( self , auth_params ) : if not isinstance ( auth_params , list ) : raise TypeError ( "auth_params can only be an instance of type list" ) for a in auth_params [ : 10 ] : if not isinstance ( a , basestring ) : raise TypeError ( "array can only contain objects of type basestring" ) result = self . _call ( "authenticateExternal" , in_p = [ auth_params ] ) return result
|
Verify credentials using the external auth library .
|
8,887
|
def is_feature_enabled ( self , feature ) : if not isinstance ( feature , RecordingFeature ) : raise TypeError ( "feature can only be an instance of type RecordingFeature" ) enabled = self . _call ( "isFeatureEnabled" , in_p = [ feature ] ) return enabled
|
Returns whether a particular recording feature is enabled for this screen or not .
|
8,888
|
def get_screen_settings ( self , screen_id ) : if not isinstance ( screen_id , baseinteger ) : raise TypeError ( "screen_id can only be an instance of type baseinteger" ) record_screen_settings = self . _call ( "getScreenSettings" , in_p = [ screen_id ] ) record_screen_settings = IRecordingScreenSettings ( record_screen_settings ) return record_screen_settings
|
Returns the recording settings for a particular screen .
|
8,889
|
def from_long ( self , number ) : if not isinstance ( number , baseinteger ) : raise TypeError ( "number can only be an instance of type baseinteger" ) self . _call ( "fromLong" , in_p = [ number ] )
|
Make PCI address from long .
|
8,890
|
def get_medium_attachments_of_controller ( self , name ) : if not isinstance ( name , basestring ) : raise TypeError ( "name can only be an instance of type basestring" ) medium_attachments = self . _call ( "getMediumAttachmentsOfController" , in_p = [ name ] ) medium_attachments = [ IMediumAttachment ( a ) for a in medium_attachments ] return medium_attachments
|
Returns an array of medium attachments which are attached to the the controller with the given name .
|
8,891
|
def get_medium_attachment ( self , name , controller_port , device ) : if not isinstance ( name , basestring ) : raise TypeError ( "name can only be an instance of type basestring" ) if not isinstance ( controller_port , baseinteger ) : raise TypeError ( "controller_port can only be an instance of type baseinteger" ) if not isinstance ( device , baseinteger ) : raise TypeError ( "device can only be an instance of type baseinteger" ) attachment = self . _call ( "getMediumAttachment" , in_p = [ name , controller_port , device ] ) attachment = IMediumAttachment ( attachment ) return attachment
|
Returns a medium attachment which corresponds to the controller with the given name on the given port and device slot .
|
8,892
|
def get_storage_controller_by_name ( self , name ) : if not isinstance ( name , basestring ) : raise TypeError ( "name can only be an instance of type basestring" ) storage_controller = self . _call ( "getStorageControllerByName" , in_p = [ name ] ) storage_controller = IStorageController ( storage_controller ) return storage_controller
|
Returns a storage controller with the given name .
|
8,893
|
def get_storage_controller_by_instance ( self , connection_type , instance ) : if not isinstance ( connection_type , StorageBus ) : raise TypeError ( "connection_type can only be an instance of type StorageBus" ) if not isinstance ( instance , baseinteger ) : raise TypeError ( "instance can only be an instance of type baseinteger" ) storage_controller = self . _call ( "getStorageControllerByInstance" , in_p = [ connection_type , instance ] ) storage_controller = IStorageController ( storage_controller ) return storage_controller
|
Returns a storage controller of a specific storage bus with the given instance number .
|
8,894
|
def remove_storage_controller ( self , name ) : if not isinstance ( name , basestring ) : raise TypeError ( "name can only be an instance of type basestring" ) self . _call ( "removeStorageController" , in_p = [ name ] )
|
Removes a storage controller from the machine with all devices attached to it .
|
8,895
|
def set_storage_controller_bootable ( self , name , bootable ) : if not isinstance ( name , basestring ) : raise TypeError ( "name can only be an instance of type basestring" ) if not isinstance ( bootable , bool ) : raise TypeError ( "bootable can only be an instance of type bool" ) self . _call ( "setStorageControllerBootable" , in_p = [ name , bootable ] )
|
Sets the bootable flag of the storage controller with the given name .
|
8,896
|
def remove_usb_controller ( self , name ) : if not isinstance ( name , basestring ) : raise TypeError ( "name can only be an instance of type basestring" ) self . _call ( "removeUSBController" , in_p = [ name ] )
|
Removes a USB controller from the machine .
|
8,897
|
def get_usb_controller_by_name ( self , name ) : if not isinstance ( name , basestring ) : raise TypeError ( "name can only be an instance of type basestring" ) controller = self . _call ( "getUSBControllerByName" , in_p = [ name ] ) controller = IUSBController ( controller ) return controller
|
Returns a USB controller with the given type .
|
8,898
|
def get_usb_controller_count_by_type ( self , type_p ) : if not isinstance ( type_p , USBControllerType ) : raise TypeError ( "type_p can only be an instance of type USBControllerType" ) controllers = self . _call ( "getUSBControllerCountByType" , in_p = [ type_p ] ) return controllers
|
Returns the number of USB controllers of the given type attached to the VM .
|
8,899
|
def get_cpu_property ( self , property_p ) : if not isinstance ( property_p , CPUPropertyType ) : raise TypeError ( "property_p can only be an instance of type CPUPropertyType" ) value = self . _call ( "getCPUProperty" , in_p = [ property_p ] ) return value
|
Returns the virtual CPU boolean value of the specified property .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.