3737    CFRChecksumError ,
3838    CFRUserError ,
3939)
40- from  cf_remote .spawn  import  VM , VMRequest , Providers , AWSCredentials , GCPCredentials 
40+ from  cf_remote .spawn  import  (
41+     VM ,
42+     VMRequest ,
43+     Providers ,
44+     AWSCredentials ,
45+     GCPCredentials ,
46+     VagrantVM ,
47+ )
4148from  cf_remote .spawn  import  spawn_vms , destroy_vms , dump_vms_info , get_cloud_driver 
4249from  cf_remote  import  log 
4350from  cf_remote  import  cloud_data 
@@ -393,6 +400,9 @@ def spawn(
393400    network = None ,
394401    public_ip = True ,
395402    extend_group = False ,
403+     vagrant_cpus = None ,
404+     vagrant_sync = None ,
405+     vagrant_provision = None ,
396406):
397407    creds_data  =  None 
398408    if  os .path .exists (CLOUD_CONFIG_FPATH ):
@@ -469,13 +479,20 @@ def spawn(
469479            network = network ,
470480            role = role ,
471481            spawned_cb = print_progress_dot ,
482+             vagrant_cpus = vagrant_cpus ,
483+             vagrant_sync = vagrant_sync ,
484+             vagrant_provision = vagrant_provision ,
472485        )
473486    except  ValueError  as  e :
474487        print ("\n Error: Failed to spawn VMs - "  +  str (e ))
475488        return  1 
476489    print ("DONE" )
477490
478-     if  public_ip  and  (not  all (vm .public_ips  for  vm  in  vms )):
491+     if  (
492+         provider  !=  Providers .VAGRANT 
493+         and  public_ip 
494+         and  (not  all (vm .public_ips  for  vm  in  vms ))
495+     ):
479496        print ("Waiting for VMs to get IP addresses..." , end = "" )
480497        sys .stdout .flush ()  # STDOUT is line-buffered 
481498        while  not  all (vm .public_ips  for  vm  in  vms ):
@@ -565,35 +582,47 @@ def destroy(group_name=None):
565582
566583        region  =  vms_info [group_name ]["meta" ]["region" ]
567584        provider  =  vms_info [group_name ]["meta" ]["provider" ]
568-         if  provider  not  in "aws" , "gcp" ]:
585+         if  provider  not  in "aws" , "gcp" ,  "vagrant" ]:
569586            raise  CFRUserError (
570-                 "Unsupported provider '{}' encountered in '{}', only aws /  gcp is  supported" .format (
587+                 "Unsupported provider '{}' encountered in '{}', only aws,  gcp or vagrant are  supported" .format (
571588                    provider , CLOUD_STATE_FPATH 
572589                )
573590            )
574591
575592        driver  =  None 
576-         if  provider  ==  "aws" :
577-             if  aws_creds  is  None :
578-                 raise  CFRExitError ("Missing/incomplete AWS credentials" )
579-             driver  =  get_cloud_driver (Providers .AWS , aws_creds , region )
580-         if  provider  ==  "gcp" :
581-             if  gcp_creds  is  None :
582-                 raise  CFRExitError ("Missing/incomplete GCP credentials" )
583-             driver  =  get_cloud_driver (Providers .GCP , gcp_creds , region )
584-         assert  driver  is  not None 
585- 
586-         nodes  =  driver .list_nodes ()
587-         for  name , vm_info  in  vms_info [group_name ].items ():
588-             if  name  ==  "meta" :
589-                 continue 
590-             vm_uuid  =  vm_info ["uuid" ]
591-             vm  =  VM .get_by_uuid (vm_uuid , nodes = nodes )
592-             if  vm  is  not None :
593-                 to_destroy .append (vm )
594-             else :
595-                 print ("VM '%s' not found in the clouds"  %  vm_uuid )
596-         del  vms_info [group_name ]
593+         if  not  provider  ==  "vagrant" :
594+             if  provider  ==  "aws" :
595+                 if  aws_creds  is  None :
596+                     raise  CFRExitError ("Missing/incomplete AWS credentials" )
597+                 driver  =  get_cloud_driver (Providers .AWS , aws_creds , region )
598+             if  provider  ==  "gcp" :
599+                 if  gcp_creds  is  None :
600+                     raise  CFRExitError ("Missing/incomplete GCP credentials" )
601+                 driver  =  get_cloud_driver (Providers .GCP , gcp_creds , region )
602+ 
603+             assert  driver  is  not None 
604+ 
605+             nodes  =  driver .list_nodes ()
606+             for  name , vm_info  in  vms_info [group_name ].items ():
607+                 if  name  ==  "meta" :
608+                     continue 
609+                 vm_uuid  =  vm_info ["uuid" ]
610+                 vm  =  VM .get_by_uuid (vm_uuid , nodes = nodes )
611+                 if  vm  is  not None :
612+                     to_destroy .append (vm )
613+                 else :
614+                     print ("VM '%s' not found in the clouds"  %  vm_uuid )
615+             del  vms_info [group_name ]
616+         else :
617+             for  name , vm_info  in  vms_info [group_name ].items ():
618+                 if  name  ==  "meta" :
619+                     continue 
620+                 vm  =  VagrantVM .get_by_info (name , vm_info )
621+                 if  vm  is  not None :
622+                     to_destroy .append (vm )
623+                 else :
624+                     print ("VM '%s' not found in the clouds"  %  name )
625+             del  vms_info [group_name ]
597626    else :
598627        print ("Destroying all hosts" )
599628        for  group_name  in  [key  for  key  in  vms_info .keys () if  key .startswith ("@" )]:
@@ -603,7 +632,7 @@ def destroy(group_name=None):
603632
604633            region  =  vms_info [group_name ]["meta" ]["region" ]
605634            provider  =  vms_info [group_name ]["meta" ]["provider" ]
606-             if  provider  not  in "aws" , "gcp" ]:
635+             if  provider  not  in "aws" , "gcp" ,  "vagrant" ]:
607636                raise  CFRUserError (
608637                    "Unsupported provider '{}' encountered in '{}', only aws / gcp is supported" .format (
609638                        provider , CLOUD_STATE_FPATH 
@@ -655,6 +684,10 @@ def list_platforms():
655684    return  0 
656685
657686
687+ def  list_boxes ():
688+     return  0 
689+ 
690+ 
658691def  init_cloud_config ():
659692    if  os .path .exists (CLOUD_CONFIG_FPATH ):
660693        print ("File %s already exists"  %  CLOUD_CONFIG_FPATH )
0 commit comments