Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load create snapshot #17

Merged
merged 4 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions ctriface/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ module github.com/ustiugov/fccd-orchestrator/ctriface

go 1.13

replace github.com/firecracker-microvm/firecracker-containerd => github.com/ustiugov/firecracker-containerd v0.0.0-20200617162450-2164fef218a8
replace github.com/firecracker-microvm/firecracker-containerd => github.com/ustiugov/firecracker-containerd v0.0.0-20200710135524-67aece3e7f88

replace github.com/firecracker-microvm/firecracker-go-sdk => github.com/ustiugov/firecracker-go-sdk v0.20.1-0.20200625102438-8edf287b0123

require (
github.com/containerd/containerd v1.3.5-0.20200521195814-e655edce10c9
github.com/davecgh/go-spew v1.1.1
github.com/firecracker-microvm/firecracker-containerd v0.0.0-20200331220105-afedbc74f5ee
github.com/firecracker-microvm/firecracker-containerd v0.0.0-00010101000000-000000000000
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.5.0
github.com/stretchr/testify v1.5.1
github.com/ustiugov/fccd-orchestrator v0.0.0-20200421101715-3d8808b0d980
github.com/ustiugov/fccd-orchestrator/misc v0.0.0-20200608162316-88962af36173
google.golang.org/grpc v1.28.0
github.com/ustiugov/fccd-orchestrator/helloworld v0.0.0-20200710145415-bb09d1a68889
github.com/ustiugov/fccd-orchestrator/misc v0.0.0-20200710145415-bb09d1a68889
google.golang.org/grpc v1.30.0
)

// Workaround for github.com/containerd/containerd issue #3031
Expand Down
62 changes: 62 additions & 0 deletions ctriface/go.sum

Large diffs are not rendered by default.

93 changes: 90 additions & 3 deletions ctriface/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ func (o *Orchestrator) cleanup(ctx context.Context, vm *misc.VM, isVM, isCont, i
}

// StopSingleVM Shuts down a VM
// VM can be starting or deactivating (do nothing), active (shut down)
// Note: VMs are not quisced before being stopped
func (o *Orchestrator) StopSingleVM(ctx context.Context, vmID string) (string, error) {
logger := log.WithFields(log.Fields{"vmID": vmID})
Expand Down Expand Up @@ -439,7 +438,7 @@ func (o *Orchestrator) setupCloseHandler() {
func (o *Orchestrator) PauseVM(ctx context.Context, vmID string) (string, error) {
logger := log.WithFields(log.Fields{"vmID": vmID})
logger.Debug("Orchestrator received PauseVM")

ctx = namespaces.WithNamespace(ctx, namespaceName)

if _, err := o.fcClient.PauseVM(ctx, &proto.PauseVMRequest{VMID: vmID}); err != nil {
Expand All @@ -463,4 +462,92 @@ func (o *Orchestrator) ResumeVM(ctx context.Context, vmID string) (string, error
}

return "VM " + vmID + " resumed successfully", nil
}
}

// CreateSnapshot Creates a snapshot of a VM
func (o *Orchestrator) CreateSnapshot(ctx context.Context, vmID, snapPath, memPath string) (string, error) {
logger := log.WithFields(log.Fields{"vmID": vmID})
logger.Debug("Orchestrator received CreateSnapshot")

ctx = namespaces.WithNamespace(ctx, namespaceName)

req := &proto.CreateSnapshotRequest{VMID: vmID, SnapshotFilePath: snapPath, MemFilePath: memPath}

if _, err := o.fcClient.CreateSnapshot(ctx, req); err != nil {
logger.Warn("failed to create snapshot of the VM: ", err)
return "Creating snapshot of VM " + vmID + " failed", err
}

return "Snapshot of VM " + vmID + " created successfully", nil
}

// LoadSnapshot Loads a snapshot of a VM
func (o *Orchestrator) LoadSnapshot(ctx context.Context, vmID, snapPath, memPath string) (string, error) {
logger := log.WithFields(log.Fields{"vmID": vmID})
logger.Debug("Orchestrator received LoadSnapshot")

ctx = namespaces.WithNamespace(ctx, namespaceName)

req := &proto.LoadSnapshotRequest{VMID: vmID, SnapshotFilePath: snapPath, MemFilePath: memPath}

if _, err := o.fcClient.LoadSnapshot(ctx, req); err != nil {
logger.Warn("failed to load snapshot of the VM: ", err)
return "Loading snapshot of VM " + vmID + " failed", err
}

return "Snapshot of VM " + vmID + " loaded successfully", nil
}

// Offload Shuts down the VM but leaves shim and other resources running.
func (o *Orchestrator) Offload(ctx context.Context, vmID string) (string, error) {
logger := log.WithFields(log.Fields{"vmID": vmID})
logger.Debug("Orchestrator received Offload")

ctx = namespaces.WithNamespace(ctx, namespaceName)

if _, err := o.fcClient.Offload(ctx, &proto.OffloadRequest{VMID: vmID}); err != nil {
logger.Warn("failed to offload the VM: ", err)
return "Offloading VM " + vmID + " failed", err
}

return "VM " + vmID + " offloaded successfully", nil
}

// StopSingleVMOnly Shuts down a VM, but does not delete the task or container
// Note: VMs are not quisced before being stopped
// Broken as of now
func (o *Orchestrator) StopSingleVMOnly(ctx context.Context, vmID string) (string, error) {
logger := log.WithFields(log.Fields{"vmID": vmID})
logger.Debug("Orchestrator received StopVMOnly")

ctx = namespaces.WithNamespace(ctx, namespaceName)
vm, err := o.vmPool.GetVM(vmID)
if err != nil {
if _, ok := err.(*misc.NonExistErr); ok {
logger.Panic("StopVMOnly: VM does not exist")
return "VM does not exist", nil
}
logger.Panic("StopVMOnly: GetVM() failed for an unknown reason")

}

logger = log.WithFields(log.Fields{"vmID": vmID})

if err := vm.Conn.Close(); err != nil {
logger.Warn("Failed to close the connection to function: ", err)
return "Closing connection to function in VM " + vmID + " failed", err
}

if _, err := o.fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: vmID}); err != nil {
logger.Warn("failed to stop the VM: ", err)
return "Stopping VM " + vmID + " failed", err
plamenmpetrov marked this conversation as resolved.
Show resolved Hide resolved
}

if err := o.vmPool.Free(vmID); err != nil {
return "Free", err
}

logger.Debug("Stopped VM successfully")

return "VM " + vmID + " stopped successfully", nil
}
Loading