#NEWLINE# def _StartInstance( self , instance_name , role ) : #NEWLINE# #INDENT# 'Starts single Compute Engine instance.\n\n    Args:\n      instance_name: Name of the instance.\n      role: Instance role name.  Must be one of the keys of INSTANCE_ROLES.\n    Raises:\n      ClusterSetUpError: Role name was invalid.\n    ' #NEWLINE# logging . info ( 'Starting instance: %s' , instance_name ) #NEWLINE# boot_disk_name = instance_name #NEWLINE# data_disk_name = ( instance_name + self . DATA_DISK_APPENDIX ) #NEWLINE# if ( not self . _GetApi ( ) . GetDisk ( boot_disk_name ) ) : #NEWLINE# #INDENT# image = ( self . flags . image or self . DEFAULT_IMAGE ) #NEWLINE# if ( not self . _GetApi ( ) . CreateDisk ( boot_disk_name , image = image ) ) : #NEWLINE# #INDENT# raise ClusterSetUpError ( ( 'Failed to create boot disk: %s' % boot_disk_name ) ) #NEWLINE# #UNINDENT# self . _WaitForDiskReady ( boot_disk_name ) #NEWLINE# #UNINDENT# if ( not self . _GetApi ( ) . GetDisk ( data_disk_name ) ) : #NEWLINE# #INDENT# if ( not self . _GetApi ( ) . CreateDisk ( data_disk_name , size_gb = self . data_disk_size_gb ) ) : #NEWLINE# #INDENT# raise ClusterSetUpError ( ( 'Failed to create data disk: %s' % data_disk_name ) ) #NEWLINE# #UNINDENT# self . _WaitForDiskReady ( data_disk_name ) #NEWLINE# #UNINDENT# if ( not self . startup_script ) : #NEWLINE# #INDENT# self . startup_script = open ( MakeScriptRelativePath ( self . COMPUTE_STARTUP_SCRIPT ) ) . read ( ) #NEWLINE# #UNINDENT# if ( not self . private_key ) : #NEWLINE# #INDENT# self . private_key = open ( self . PRIVATE_KEY_FILE ) . read ( ) #NEWLINE# #UNINDENT# if ( not self . public_key ) : #NEWLINE# #INDENT# self . public_key = open ( self . PUBLIC_KEY_FILE ) . read ( ) #NEWLINE# #UNINDENT# metadata = { #NEWLINE# #INDENT# 'num-workers' : self . flags . num_workers , #NEWLINE# 'hadoop-master' : self . master_name , #NEWLINE# 'hadoop-worker-template' : self . worker_name_template , #NEWLINE# 'tmp-cloud-storage' : self . tmp_storage , #NEWLINE# 'custom-command' : self . flags . command , #NEWLINE# 'hadoop-private-key' : self . private_key , #NEWLINE# 'hadoop-public-key' : self . public_key , #NEWLINE# 'worker-external-ip' : int ( ( self . flags . external_ip == 'all' ) ) , #NEWLINE# 'data-disk-id' : data_disk_name , #NEWLINE# #UNINDENT# } #NEWLINE# if ( role not in self . INSTANCE_ROLES ) : #NEWLINE# #INDENT# raise ClusterSetUpError ( ( 'Invalid instance role name: %s' % role ) ) #NEWLINE# #UNINDENT# for command in self . INSTANCE_ROLES [ role ] : #NEWLINE# #INDENT# metadata [ command ] = 1 #NEWLINE# #UNINDENT# external_ip = False #NEWLINE# if ( ( role == 'master' ) or ( self . flags . external_ip == 'all' ) ) : #NEWLINE# #INDENT# external_ip = True #NEWLINE# #UNINDENT# can_ip_forward = False #NEWLINE# if ( ( role == 'master' ) and ( self . flags . external_ip == 'master' ) ) : #NEWLINE# #INDENT# can_ip_forward = True #NEWLINE# #UNINDENT# tags = None #NEWLINE# if ( role == 'worker' ) : #NEWLINE# #INDENT# tags = [ self . worker_tag ] #NEWLINE# #UNINDENT# self . _GetApi ( ) . CreateInstance ( instance_name , ( self . flags . machinetype or self . DEFAULT_MACHINE_TYPE ) , boot_disk = boot_disk_name , disks = [ data_disk_name ] , startup_script = self . startup_script , service_accounts = [ 'https://www.googleapis.com/auth/devstorage.full_control' ] , external_ip = external_ip , metadata = metadata , tags = tags , can_ip_forward = can_ip_forward )