37
37
CFRChecksumError ,
38
38
CFRUserError ,
39
39
)
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
+ )
41
48
from cf_remote .spawn import spawn_vms , destroy_vms , dump_vms_info , get_cloud_driver
42
49
from cf_remote import log
43
50
from cf_remote import cloud_data
@@ -393,6 +400,9 @@ def spawn(
393
400
network = None ,
394
401
public_ip = True ,
395
402
extend_group = False ,
403
+ vagrant_cpus = None ,
404
+ vagrant_sync = None ,
405
+ vagrant_provision = None ,
396
406
):
397
407
creds_data = None
398
408
if os .path .exists (CLOUD_CONFIG_FPATH ):
@@ -469,13 +479,20 @@ def spawn(
469
479
network = network ,
470
480
role = role ,
471
481
spawned_cb = print_progress_dot ,
482
+ vagrant_cpus = vagrant_cpus ,
483
+ vagrant_sync = vagrant_sync ,
484
+ vagrant_provision = vagrant_provision ,
472
485
)
473
486
except ValueError as e :
474
487
print ("\n Error: Failed to spawn VMs - " + str (e ))
475
488
return 1
476
489
print ("DONE" )
477
490
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
+ ):
479
496
print ("Waiting for VMs to get IP addresses..." , end = "" )
480
497
sys .stdout .flush () # STDOUT is line-buffered
481
498
while not all (vm .public_ips for vm in vms ):
@@ -565,35 +582,47 @@ def destroy(group_name=None):
565
582
566
583
region = vms_info [group_name ]["meta" ]["region" ]
567
584
provider = vms_info [group_name ]["meta" ]["provider" ]
568
- if provider not in ["aws" , "gcp" ]:
585
+ if provider not in ["aws" , "gcp" , "vagrant" ]:
569
586
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 (
571
588
provider , CLOUD_STATE_FPATH
572
589
)
573
590
)
574
591
575
592
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 ]
597
626
else :
598
627
print ("Destroying all hosts" )
599
628
for group_name in [key for key in vms_info .keys () if key .startswith ("@" )]:
@@ -603,7 +632,7 @@ def destroy(group_name=None):
603
632
604
633
region = vms_info [group_name ]["meta" ]["region" ]
605
634
provider = vms_info [group_name ]["meta" ]["provider" ]
606
- if provider not in ["aws" , "gcp" ]:
635
+ if provider not in ["aws" , "gcp" , "vagrant" ]:
607
636
raise CFRUserError (
608
637
"Unsupported provider '{}' encountered in '{}', only aws / gcp is supported" .format (
609
638
provider , CLOUD_STATE_FPATH
@@ -655,6 +684,10 @@ def list_platforms():
655
684
return 0
656
685
657
686
687
+ def list_boxes ():
688
+ return 0
689
+
690
+
658
691
def init_cloud_config ():
659
692
if os .path .exists (CLOUD_CONFIG_FPATH ):
660
693
print ("File %s already exists" % CLOUD_CONFIG_FPATH )
0 commit comments