Skip to content

Commit

Permalink
fix: conditional lifecycle, as in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-miemiec committed Sep 30, 2020
1 parent 8faf72b commit bb7ae44
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ func (driver *Driver) PreCreateCheck() error {
driver.ConfigVariables["dm_ssh_public_key_file"] = driver.SSHKeyPath + ".pub"
driver.ConfigVariables["dm_ssh_user"] = driver.SSHUser
driver.ConfigVariables["dm_ssh_port"] = driver.SSHPort
driver.ConfigVariables["dm_lifecycle"] = "running"

if driver.LifecycleOn {
driver.ConfigVariables["dm_lifecycle"] = "running"
}

err = driver.readAdditionalVariables()
if err != nil {
Expand Down Expand Up @@ -296,7 +299,9 @@ func (driver *Driver) GetURL() (string, error) {

// Remove deletes the target machine.
func (driver *Driver) Remove() error {
driver.ConfigVariables["dm_lifecycle"] = "stopped"
if driver.LifecycleOn {
driver.ConfigVariables["dm_lifecycle"] = "stopped"
}
err := driver.writeVariables()
if err != nil {
return err
Expand Down Expand Up @@ -327,9 +332,13 @@ func (driver *Driver) Start() error {

// Stop the target machine (gracefully).
func (driver *Driver) Stop() error {
driver.ConfigVariables["dm_lifecycle"] = "stopped"
_, err := driver.Apply()
return err
if driver.LifecycleOn {
driver.ConfigVariables["dm_lifecycle"] = "stopped"
_, err := driver.Apply()
return err
} else{
return driver.Remove()
}
}

// Restart the target machine.
Expand Down

0 comments on commit bb7ae44

Please sign in to comment.