This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out the ignite container command into a separate ignite-spawn …
…binary
- Loading branch information
Showing
16 changed files
with
303 additions
and
289 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,67 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/weaveworks/ignite/pkg/container" | ||
"github.com/weaveworks/ignite/pkg/metadata/loader" | ||
"github.com/weaveworks/ignite/pkg/metadata/vmmd" | ||
) | ||
|
||
func main() { | ||
if err := Run(); err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// Run runs the main cobra command of this application | ||
func Run() error { | ||
if len(os.Args) != 1 { | ||
fmt.Printf("Usage: ignite-spawn [VM ID]") | ||
os.Exit(0) | ||
} | ||
|
||
vmID := os.Args[0] | ||
opts, err := NewOptions(loader.NewResLoader(), vmID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return StartVM(opts) | ||
} | ||
|
||
func StartVM(co *options) error { | ||
// Setup networking inside of the container, return the available interfaces | ||
dhcpIfaces, err := container.SetupContainerNetworking() | ||
if err != nil { | ||
return fmt.Errorf("network setup failed: %v", err) | ||
} | ||
// Serve DHCP requests for those interfaces | ||
if err := container.StartDHCPServers(co.vm, dhcpIfaces); err != nil { | ||
return err | ||
} | ||
|
||
// VM state handling | ||
if err := co.vm.SetState(vmmd.Running); err != nil { | ||
return fmt.Errorf("failed to update VM state: %v", err) | ||
} | ||
defer co.vm.SetState(vmmd.Stopped) // Performs a save, all other metadata-modifying defers need to be after this | ||
|
||
// Remove the snapshot overlay post-run, which also removes the detached backing loop devices | ||
defer co.vm.RemoveSnapshot() | ||
|
||
// Remove the IP addresses post-run | ||
defer co.vm.ClearIPAddresses() | ||
|
||
// Remove the port mappings post-run | ||
defer co.vm.ClearPortMappings() | ||
|
||
// Execute Firecracker | ||
if err := container.ExecuteFirecracker(co.vm, dhcpIfaces); err != nil { | ||
return fmt.Errorf("runtime error for VM %q: %v", co.vm.ID, err) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/weaveworks/ignite/pkg/metadata/loader" | ||
"github.com/weaveworks/ignite/pkg/metadata/vmmd" | ||
) | ||
|
||
type options struct { | ||
vm *vmmd.VMMetadata | ||
} | ||
|
||
func NewOptions(l *loader.ResLoader, vmMatch string) (*options, error) { | ||
co := &options{} | ||
|
||
if allVMS, err := l.VMs(); err == nil { | ||
if co.vm, err = allVMS.MatchSingle(vmMatch); err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
return nil, err | ||
} | ||
|
||
return co, nil | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.