Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 09ae23d

Browse files
Ian CampbellDavid Chung
authored andcommitted
Add basic libvirt instance plugin (#477)
Signed-off-by: Ian Campbell <[email protected]>
1 parent a8d3837 commit 09ae23d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+17974
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ endif
127127
$(call build_binary,infrakit-flavor-swarm,github.com/docker/infrakit/examples/flavor/swarm)
128128
$(call build_binary,infrakit-flavor-vanilla,github.com/docker/infrakit/examples/flavor/vanilla)
129129
$(call build_binary,infrakit-flavor-zookeeper,github.com/docker/infrakit/examples/flavor/zookeeper)
130+
$(call build_binary,infrakit-instance-libvirt,github.com/docker/infrakit/cmd/instance/libvirt)
130131
$(call build_binary,infrakit-instance-file,github.com/docker/infrakit/examples/instance/file)
131132
$(call build_binary,infrakit-instance-terraform,github.com/docker/infrakit/examples/instance/terraform)
132133
$(call build_binary,infrakit-instance-vagrant,github.com/docker/infrakit/examples/instance/vagrant)

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies:
3737

3838
# Install dependencies
3939
- cd $WORKDIR && go get github.com/golang/lint/golint github.com/wfarner/blockcheck
40+
- sudo apt-get update && sudo apt-get install -y libvirt-dev
4041

4142
test:
4243
override:

cmd/instance/libvirt/libvirt.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"ID": "cattle",
3+
"Properties": {
4+
"Allocation": {
5+
"Size": 1
6+
},
7+
"Instance": {
8+
"Plugin": "instance-libvirt",
9+
"Properties": {
10+
"Kernel": "../bzImage",
11+
"Ramdisk": "../initrd.img",
12+
"CmdlineFile": "../cmdline",
13+
"Disk" : 512,
14+
"CPUs" : 2,
15+
"Memory" : 1024
16+
}
17+
},
18+
"Flavor": {
19+
"Plugin": "flavor-vanilla",
20+
"Properties": {
21+
"Init": [
22+
"test1",
23+
"test2"
24+
],
25+
"Tags": {
26+
"tier": "sample",
27+
"project": "infrakit"
28+
}
29+
}
30+
}
31+
}
32+
}

cmd/instance/libvirt/main.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
"os/user"
8+
9+
log "github.com/Sirupsen/logrus"
10+
"github.com/spf13/cobra"
11+
12+
"github.com/docker/infrakit/pkg/cli"
13+
instance "github.com/docker/infrakit/pkg/plugin/instance/libvirt"
14+
"github.com/docker/infrakit/pkg/plugin/metadata"
15+
instance_plugin "github.com/docker/infrakit/pkg/rpc/instance"
16+
metadata_plugin "github.com/docker/infrakit/pkg/rpc/metadata"
17+
instance_spi "github.com/docker/infrakit/pkg/spi/instance"
18+
)
19+
20+
func main() {
21+
22+
cmd := &cobra.Command{
23+
Use: os.Args[0],
24+
Short: "Libvirt instance plugin",
25+
}
26+
27+
name := cmd.Flags().String("name", "instance-libvirt", "Plugin name to advertise for discovery")
28+
logLevel := cmd.Flags().Int("log", cli.DefaultLogLevel, "Logging level. 0 is least verbose. Max is 5")
29+
30+
uri := cmd.Flags().String("uri", "qemu:///session", "libvirt URI to connect to")
31+
32+
cmd.RunE = func(c *cobra.Command, args []string) error {
33+
cli.SetLogLevel(*logLevel)
34+
cli.RunPlugin(*name,
35+
instance_plugin.PluginServer(instance.NewLibvirtPlugin(*uri)),
36+
metadata_plugin.PluginServer(metadata.NewPluginFromData(
37+
map[string]interface{}{
38+
"version": cli.Version,
39+
"revision": cli.Revision,
40+
"implements": instance_spi.InterfaceSpec,
41+
},
42+
)),
43+
)
44+
return nil
45+
}
46+
47+
cmd.AddCommand(&cobra.Command{
48+
Use: "version",
49+
Short: "print build version information",
50+
RunE: func(cmd *cobra.Command, args []string) error {
51+
buff, err := json.MarshalIndent(map[string]interface{}{
52+
"version": cli.Version,
53+
"revision": cli.Revision,
54+
}, " ", " ")
55+
if err != nil {
56+
return err
57+
}
58+
fmt.Println(string(buff))
59+
return nil
60+
},
61+
})
62+
63+
if err := cmd.Execute(); err != nil {
64+
log.Error(err)
65+
os.Exit(1)
66+
}
67+
}
68+
69+
func getHome() string {
70+
if usr, err := user.Current(); err == nil {
71+
return usr.HomeDir
72+
}
73+
return os.Getenv("HOME")
74+
}

dockerfiles/Dockerfile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM golang:1.8-alpine
22

3-
RUN apk add --update git make gcc musl-dev wget ca-certificates openssl
3+
RUN apk add --update git make gcc musl-dev wget ca-certificates openssl libvirt-dev
44
RUN go get github.com/rancher/trash
55

66
WORKDIR /go/src/github.com/docker/infrakit

0 commit comments

Comments
 (0)