-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #544 from rgooch/master
Add optional destroy protection for running VMs.
- Loading branch information
Showing
8 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
|
||
"github.com/Symantec/Dominator/lib/errors" | ||
"github.com/Symantec/Dominator/lib/log" | ||
proto "github.com/Symantec/Dominator/proto/hypervisor" | ||
) | ||
|
||
func changeVmDestroyProtectionSubcommand(args []string, | ||
logger log.DebugLogger) { | ||
if err := changeVmDestroyProtection(args[0], logger); err != nil { | ||
fmt.Fprintf(os.Stderr, "Error changing VM destroy protection: %s\n", | ||
err) | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
} | ||
|
||
func changeVmDestroyProtection(vmHostname string, | ||
logger log.DebugLogger) error { | ||
if vmIP, hypervisor, err := lookupVmAndHypervisor(vmHostname); err != nil { | ||
return err | ||
} else { | ||
return changeVmDestroyProtectionOnHypervisor(hypervisor, vmIP, logger) | ||
} | ||
} | ||
|
||
func changeVmDestroyProtectionOnHypervisor(hypervisor string, ipAddr net.IP, | ||
logger log.DebugLogger) error { | ||
request := proto.ChangeVmDestroyProtectionRequest{ | ||
DestroyProtection: *destroyProtection, | ||
IpAddress: ipAddr, | ||
} | ||
client, err := dialHypervisor(hypervisor) | ||
if err != nil { | ||
return err | ||
} | ||
defer client.Close() | ||
var reply proto.ChangeVmOwnerUsersResponse | ||
err = client.RequestReply("Hypervisor.ChangeVmDestroyProtection", | ||
request, &reply) | ||
if err != nil { | ||
return err | ||
} | ||
return errors.New(reply.Error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package rpcd | ||
|
||
import ( | ||
"github.com/Symantec/Dominator/lib/errors" | ||
"github.com/Symantec/Dominator/lib/srpc" | ||
"github.com/Symantec/Dominator/proto/hypervisor" | ||
) | ||
|
||
func (t *srpcType) ChangeVmDestroyProtection(conn *srpc.Conn, | ||
request hypervisor.ChangeVmDestroyProtectionRequest, | ||
reply *hypervisor.ChangeVmDestroyProtectionResponse) error { | ||
*reply = hypervisor.ChangeVmDestroyProtectionResponse{ | ||
errors.ErrorToString( | ||
t.manager.ChangeVmDestroyProtection(request.IpAddress, | ||
conn.GetAuthInformation(), | ||
request.DestroyProtection))} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters