<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import sys <EOL> import time <EOL> from oauth2client . client import GoogleCredentials <EOL> from googleapiclient . discovery import build <EOL> from six . moves import input <EOL> def list_instances ( compute , project , zone ) : <EOL> result = compute . instances ( ) . list ( project = project , zone = zone ) . execute ( ) <EOL> return result [ '<STR_LIT>' ] <EOL> def create_instance ( compute , project , zone , name ) : <EOL> source_disk_image = "<STR_LIT>" <EOL> machine_type = "<STR_LIT>" % zone <EOL> startup_script = open ( '<STR_LIT>' , '<STR_LIT:r>' ) . read ( ) <EOL> image_url = "<STR_LIT>" <EOL> image_caption = "<STR_LIT>" <EOL> config = { <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : machine_type , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : source_disk_image , <EOL> } <EOL> } <EOL> ] , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' } <EOL> ] <EOL> } ] , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT:email>' : '<STR_LIT:default>' , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : startup_script <EOL> } , { <EOL> '<STR_LIT:key>' : '<STR_LIT:url>' , <EOL> '<STR_LIT:value>' : image_url <EOL> } , { <EOL> '<STR_LIT:key>' : '<STR_LIT:text>' , <EOL> '<STR_LIT:value>' : image_caption <EOL> } , { <EOL> '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : project <EOL> } ] <EOL> } <EOL> } <EOL> return compute . instances ( ) . insert ( <EOL> project = project , <EOL> zone = zone , <EOL> body = config ) . execute ( ) <EOL> def delete_instance ( compute , project , zone , name ) : <EOL> return compute . instances ( ) . delete ( <EOL> project = project , <EOL> zone = zone , <EOL> instance = name ) . execute ( ) <EOL> def wait_for_operation ( compute , project , zone , operation ) : <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> while True : <EOL> result = compute . zoneOperations ( ) . get ( <EOL> project = project , <EOL> zone = zone , <EOL> operation = operation ) . execute ( ) <EOL> if result [ '<STR_LIT:status>' ] == '<STR_LIT>' : <EOL> print ( "<STR_LIT>" ) <EOL> if '<STR_LIT:error>' in result : <EOL> raise Exception ( result [ '<STR_LIT:error>' ] ) <EOL> return result <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT:.>' ) <EOL> sys . stdout . flush ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> def run ( project , zone , instance_name ) : <EOL> credentials = GoogleCredentials . get_application_default ( ) <EOL> compute = build ( '<STR_LIT>' , '<STR_LIT>' , credentials = credentials ) <EOL> print ( '<STR_LIT>' ) <EOL> operation = create_instance ( compute , project , zone , instance_name ) <EOL> wait_for_operation ( compute , project , zone , operation [ '<STR_LIT:name>' ] ) <EOL> instances = list_instances ( compute , project , zone ) <EOL> print ( '<STR_LIT>' % ( project , zone ) ) <EOL> for instance in instances : <EOL> print ( '<STR_LIT>' + instance [ '<STR_LIT:name>' ] ) <EOL> print ( """<STR_LIT>""" % project ) <EOL> input ( ) <EOL> print ( '<STR_LIT>' ) <EOL> operation = delete_instance ( compute , project , zone , instance_name ) <EOL> wait_for_operation ( compute , project , zone , operation [ '<STR_LIT:name>' ] ) <EOL> def main ( ) : <EOL> project = input ( '<STR_LIT>' ) <EOL> zone = input ( <EOL> '<STR_LIT>' ) or '<STR_LIT>' <EOL> instance_name = '<STR_LIT>' <EOL> run ( project , zone , instance_name ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
