Use PreCreateCheck to check the project/credentials

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot 2015-10-28 10:52:16 +01:00
parent 8e7a85b8b9
commit b213da0961
1 changed files with 24 additions and 10 deletions

View File

@ -156,34 +156,48 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
return nil return nil
} }
func (d *Driver) initApis() (*ComputeUtil, error) { // PreCreateCheck is called to enforce pre-creation steps
return newComputeUtil(d) func (d *Driver) PreCreateCheck() error {
}
// Create creates a GCE VM instance acting as a docker host.
func (d *Driver) Create() error {
c, err := newComputeUtil(d) c, err := newComputeUtil(d)
if err != nil { if err != nil {
return err return err
} }
log.Infof("Creating host...")
// Check that the project exists. It will also check that credentials
// at the same time.
log.Infof("Check that the project exists")
if _, err = c.service.Projects.Get(d.Project).Do(); err != nil {
return fmt.Errorf("Project with ID %q not found. %v", d.Project, err)
}
// Check if the instance already exists. There will be an error if the instance // Check if the instance already exists. There will be an error if the instance
// doesn't exist, so just check instance for nil. // doesn't exist, so just check instance for nil.
log.Infof("Check if the instance already exists")
if instance, _ := c.instance(); instance != nil { if instance, _ := c.instance(); instance != nil {
return fmt.Errorf("Instance %v already exists.", d.MachineName) return fmt.Errorf("Instance %v already exists.", d.MachineName)
} }
return nil
}
// Create creates a GCE VM instance acting as a docker host.
func (d *Driver) Create() error {
log.Infof("Generating SSH Key") log.Infof("Generating SSH Key")
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return err return err
} }
err = c.createInstance(d) log.Infof("Creating host...")
c, err := newComputeUtil(d)
if err != nil { if err != nil {
return fmt.Errorf("You might have to run `gcloud auth login` to get the authorization credentials: %s", err) return err
} }
return err return c.createInstance(d)
} }
// GetURL returns the URL of the remote docker daemon. // GetURL returns the URL of the remote docker daemon.