#NEWLINE# def create_disk( kwargs = None , call = None ) : #NEWLINE# #INDENT# '\n    Create a new persistent disk. Must specify `disk_name` and `location`.\n    Can also specify an `image` or `snapshot` but if neither of those are\n    specified, a `size` (in GB) is required.\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt-cloud -f create_disk gce disk_name=pd size=300 location=us-central1-b\n    ' #NEWLINE# if ( call != 'function' ) : #NEWLINE# #INDENT# raise SaltCloudSystemExit ( 'The create_disk function must be called with -f or --function.' ) #NEWLINE# #UNINDENT# if ( kwargs is None ) : #NEWLINE# #INDENT# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# name = kwargs . get ( 'disk_name' , None ) #NEWLINE# image = kwargs . get ( 'image' , None ) #NEWLINE# location = kwargs . get ( 'location' , None ) #NEWLINE# size = kwargs . get ( 'size' , None ) #NEWLINE# snapshot = kwargs . get ( 'snapshot' , None ) #NEWLINE# if ( location is None ) : #NEWLINE# #INDENT# log . error ( 'A location (zone) must be specified when creating a disk.' ) #NEWLINE# return False #NEWLINE# #UNINDENT# if ( location is None ) : #NEWLINE# #INDENT# log . error ( 'A disk_name must be specified when creating a disk.' ) #NEWLINE# return False #NEWLINE# #UNINDENT# if ( ( 'size' is None ) and ( 'image' is None ) and ( 'snapshot' is None ) ) : #NEWLINE# #INDENT# log . error ( 'Must specify image, snapshot, or size.' ) #NEWLINE# return False #NEWLINE# #UNINDENT# conn = get_conn ( ) #NEWLINE# location = conn . ex_get_zone ( kwargs [ 'location' ] ) #NEWLINE# use_existing = True #NEWLINE# salt . utils . cloud . fire_event ( 'event' , 'create disk' , 'salt/cloud/disk/creating' , { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'location' : location . name , #NEWLINE# 'image' : image , #NEWLINE# 'snapshot' : snapshot , #NEWLINE# #UNINDENT# } , transport = __opts__ [ 'transport' ] ) #NEWLINE# disk = conn . create_volume ( size , name , location , snapshot , image , use_existing ) #NEWLINE# salt . utils . cloud . fire_event ( 'event' , 'created disk' , 'salt/cloud/disk/created' , { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'location' : location . name , #NEWLINE# 'image' : image , #NEWLINE# 'snapshot' : snapshot , #NEWLINE# #UNINDENT# } , transport = __opts__ [ 'transport' ] ) #NEWLINE# return _expand_disk ( disk )