#NEWLINE# def CreateInstance( self , instance_name , machine_type , boot_disk , disks = None , startup_script = '' , service_accounts = None , external_ip = True , metadata = None , tags = None , can_ip_forward = False ) : #NEWLINE# #INDENT# "Creates Google Compute Engine instance.\n\n    Args:\n      instance_name: Name of the new instance.\n      machine_type: Machine type.  e.g. 'n1-standard-2'\n      boot_disk: Name of the persistent disk to be used as a boot disk.\n          The disk must preexist in the same zone as the instance.\n      disks: List of the names of the extra persistent disks attached to\n          the instance in addition to the boot disk.\n      startup_script: Content of start up script to run on the new instance.\n      service_accounts: List of scope URLs to give to the instance with\n          the service account.\n      external_ip: Boolean value to indicate whether the new instance has\n          an external IP address.\n      metadata: Additional key-value pairs in dictionary to add as\n          instance metadata.\n      tags: String list of tags to attach to the new instance.\n      can_ip_forward: Boolean to indicate if the new instance can forward IP\n          packets.\n    Returns:\n      Boolean to indicate whether the instance creation was successful.\n    " #NEWLINE# params = { #NEWLINE# #INDENT# 'kind' : 'compute#instance' , #NEWLINE# 'name' : instance_name , #NEWLINE# 'zone' : self . _ResourceUrl ( 'zones' , self . _zone , zoning = ResourceZoning . NONE ) , #NEWLINE# 'machineType' : self . _ResourceUrl ( 'machineTypes' , machine_type ) , #NEWLINE# 'disks' : [ { #NEWLINE# #INDENT# 'kind' : 'compute#attachedDisk' , #NEWLINE# 'boot' : True , #NEWLINE# 'source' : self . _ResourceUrl ( 'disks' , boot_disk ) , #NEWLINE# 'mode' : 'READ_WRITE' , #NEWLINE# 'type' : 'PERSISTENT' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'metadata' : { #NEWLINE# #INDENT# 'kind' : 'compute#metadata' , #NEWLINE# 'items' : [ { #NEWLINE# #INDENT# 'key' : 'startup-script' , #NEWLINE# 'value' : external_ip , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } , #NEWLINE# 'canIpForward' : can_ip_forward , #NEWLINE# 'networkInterfaces' : [ { #NEWLINE# #INDENT# 'kind' : 'compute#instanceNetworkInterface' , #NEWLINE# 'accessConfigs' : [ ] , #NEWLINE# 'network' : self . _ResourceUrl ( 'networks' , 'default' , zoning = ResourceZoning . GLOBAL ) , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'serviceAccounts' : [ { #NEWLINE# #INDENT# 'kind' : 'compute#serviceAccount' , #NEWLINE# 'email' : 'default' , #NEWLINE# 'scopes' : ( service_accounts or [ ] ) , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# if disks : #NEWLINE# #INDENT# for disk in disks : #NEWLINE# #INDENT# params [ 'disks' ] . append ( { #NEWLINE# #INDENT# 'kind' : 'compute#attachedDisk' , #NEWLINE# 'boot' : False , #NEWLINE# 'source' : self . _ResourceUrl ( 'disks' , disk ) , #NEWLINE# 'deviceName' : disk , #NEWLINE# 'mode' : 'READ_WRITE' , #NEWLINE# 'type' : 'PERSISTENT' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# if external_ip : #NEWLINE# #INDENT# params [ 'networkInterfaces' ] [ 0 ] [ 'accessConfigs' ] . append ( { #NEWLINE# #INDENT# 'kind' : 'compute#accessConfig' , #NEWLINE# 'type' : 'ONE_TO_ONE_NAT' , #NEWLINE# 'name' : 'External NAT' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if metadata : #NEWLINE# #INDENT# for ( key , value ) in metadata . items ( ) : #NEWLINE# #INDENT# params [ 'metadata' ] [ 'items' ] . append ( { #NEWLINE# #INDENT# 'key' : key , #NEWLINE# 'value' : value , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# if tags : #NEWLINE# #INDENT# params [ 'tags' ] = { #NEWLINE# #INDENT# 'items' : tags , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# operation = self . GetApi ( ) . instances ( ) . insert ( project = self . _project , zone = self . _zone , body = params ) . execute ( ) #NEWLINE# return self . _ParseOperation ( operation , ( 'Instance creation: %s' % instance_name ) )