Skip to content

Commit 18dd2ba

Browse files
committed
Add support for NUMA topologies
1 parent 5c93e22 commit 18dd2ba

8 files changed

+222
-267
lines changed

README.md

+17-78
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ Libvirt.
1313
- Supports [vhost-user network interfaces](https://libvirt.org/formatdomain.html#elementVhostuser), to allow a VM to connect e.g. with a DPDK-based vswitch
1414

1515
Provisioning options:
16-
- cloud image used for provisioning (currently tested with Ubuntu 16.04)
16+
- cloud image used for provisioning (currently tested with Ubuntu 16.04 & 18.04)
1717
- user credentials
1818
- custom provisioning script to be used during VM creation
1919
- custom init.d script to be installed permanently
2020

2121
VM configuration options:
22-
- number of vCPUs
22+
- number and topology of vCPUs
2323
- guest memory
2424
- hugepage backing options
2525
- network interfaces: support for `bridge`-type and `vhostuser`-type interfaces
@@ -42,88 +42,27 @@ virgo makes use of the following utilities:
4242

4343
## Usage
4444

45-
Provision a new VM called "foo":
46-
```console
47-
$ sudo virgo provision foo --config guest_config.json --provision-script provision.sh --initd-script initd.sh
45+
```console
46+
$ virgo init
4847
```
49-
"foo" will shutdown after provisioning.
5048

51-
Edit `guest_config.json` to change VM's parameters (e.g. #vCPUs), and launch "foo":
52-
```console
53-
$ sudo virgo launch foo --config guest_config.json
54-
```
49+
Edit the created `virgo.json` according to your needs.
5550

56-
Usage:
57-
```console
58-
$ virgo --help
59-
60-
virgo enables easy provisioning, configuration and management of Libvirt guests.
61-
62-
For provisioning a new VM image, you should specify a JSON config file with provisioning
63-
options, along with a provisioning script to be executed on image's first boot.
64-
65-
For launching a new VM instance from an already-provisioned image, you should specify a
66-
JSON config file with launch options.
67-
68-
The example below shows all available provisioning and launch options, all in a single
69-
JSON file (ignore the '#' lines which serve as comments).
70-
71-
{
72-
# PROVISIONING OPTIONS
73-
"cloud_img_url": "https://cloud-images.ubuntu.com/releases/16.04/release/",
74-
"cloud_img_name": "ubuntu-16.04-server-cloudimg-amd64-disk1.img",
75-
"user": "nfvsap",
76-
"passwd": "nfvsap",
77-
"root_img_gb": 10,
78-
79-
# LAUNCH OPTIONS
80-
"guest_memory_mb": 4096,
81-
"guest_num_vcpus": 8,
82-
"guest_hugepage_support": true,
83-
"guest_hugepage_size": 2,
84-
"guest_hugepage_size_unit": "M",
85-
"guest_hugepage_node_set": "0",
86-
"guest_net_ifs": [
87-
{"type": "bridge", "bridge": "virbr0"},
88-
{"type": "bridge", "bridge": "virbr0"},
89-
{
90-
"type": "vhostuser",
91-
"mac_addr": "de:ad:be:ef:01:23",
92-
"unix_socket_path": "/usr/local/var/run/openvswitch/dpdkvhostuser1",
93-
"queues": 2
94-
},
95-
{
96-
"type": "vhostuser",
97-
"mac_addr": "de:ad:be:ef:45:67",
98-
"unix_socket_path": "/usr/local/var/run/openvswitch/dpdkvhostuser2",
99-
"queues": 2
100-
}]
101-
}
102-
103-
The provisioning script can be any valid bash script, and it's executed as the
104-
last step of cloud-init provisioning.
105-
106-
PREREQUISITES
107-
The following Linux utilities are required by virgo:
108-
- wget
109-
- genisoimage
51+
Optionally, create additional `provision.sh` and `initd.sh` files to be used as provisioning
52+
and initd scripts, respectively.
11053

111-
Usage:
112-
virgo [command]
54+
Provision a new VM called "foo":
11355

114-
Available Commands:
115-
help Help about any command
116-
launch Define and start a new VM instance
117-
provision Provision a new VM image
118-
purge Fully destroy a VM by undefining it and removing its image
119-
start Create a new VM instance from an already existing specification
120-
stop Shut down a running VM instance
121-
undefine Undefine a VM by removing its specification
56+
```console
57+
$ sudo virgo provision foo --config virgo.json [--provision-script provision.sh] [--initd-script initd.sh]
58+
```
12259

123-
Flags:
124-
-h, --help help for virgo
60+
"foo" will shutdown after provisioning.
12561

126-
Use "virgo [command] --help" for more information about a command.
127-
```
62+
Edit `virgo.json` to change VM's parameters (e.g. #vCPUs), and launch "foo":
12863

64+
```console
65+
$ sudo virgo launch foo --config virgo.json
66+
```
12967

68+
To find out more, run `virgo -h`.

cmd/init.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
// initCmd represents the init command
12+
var initCmd = &cobra.Command{
13+
Use: "init",
14+
Short: "Create sample configuration files and scripts",
15+
Long: `Create sample configuration files and scripts.`,
16+
RunE: func(cmd *cobra.Command, args []string) error {
17+
configFile := "virgo.json"
18+
19+
if _, err := os.Stat(configFile); err == nil {
20+
return fmt.Errorf("file %s already exists", configFile)
21+
}
22+
23+
err := ioutil.WriteFile(configFile, []byte(sampleConfig), 0644)
24+
if err != nil {
25+
return fmt.Errorf("failed to create %s: %v", configFile, err)
26+
}
27+
28+
return nil
29+
},
30+
}
31+
32+
func init() {
33+
rootCmd.AddCommand(initCmd)
34+
}

cmd/provision.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/anastop/virgo/pkg/virgo"
76
"io/ioutil"
87
"log"
98

9+
"github.com/anastop/virgo/pkg/virgo"
10+
1011
"github.com/spf13/cobra"
1112
)
1213

@@ -54,12 +55,13 @@ The bash script can be any valid bash script and is executed with root permissio
5455
}
5556
gc.Name = guest
5657

57-
data, err = ioutil.ReadFile(provisionScript)
58-
if err != nil {
59-
return fmt.Errorf("failed to read provision script %s: %v", provisionScript, err)
58+
if provisionScript != "" {
59+
data, err = ioutil.ReadFile(provisionScript)
60+
if err != nil {
61+
return fmt.Errorf("failed to read provision script %s: %v", provisionScript, err)
62+
}
63+
pc.Provision = string(data)
6064
}
61-
pc.Provision = string(data)
62-
6365

6466
if initdScript != "" {
6567
data, err = ioutil.ReadFile(initdScript)

cmd/root.go

+34-24
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,23 @@ import (
77
"github.com/spf13/cobra"
88
)
99

10-
// rootCmd represents the base command when called without any subcommands
11-
var rootCmd = &cobra.Command{
12-
Use: "virgo",
13-
Short: "virgo enables easy provisioning, configuration and management of Libvirt guests",
14-
Long: `virgo enables easy provisioning, configuration and management of Libvirt guests.
15-
16-
All virgo commands accept a single argument, the name of the VM they act upon. Every command
17-
has its own flags.
18-
19-
For provisioning a new VM image, you should specify a JSON config file with provisioning
20-
options, along with a provisioning script to be executed on image's first boot.
21-
22-
For launching a new VM instance from an already-provisioned image, you should specify a
23-
JSON config file with launch options.
24-
25-
The example below shows all available provisioning and launch options, all in a single
26-
JSON file (ignore the '#' lines which serve as comments).
27-
10+
var sampleConfig = `
2811
{
29-
# PROVISIONING OPTIONS
30-
"cloud_img_url": "https://cloud-images.ubuntu.com/releases/16.04/release/",
31-
"cloud_img_name": "ubuntu-16.04-server-cloudimg-amd64-disk1.img",
32-
"user": "nfvsap",
33-
"passwd": "nfvsap",
12+
"cloud_img_url": "https://cloud-images.ubuntu.com/releases/18.04/release/",
13+
"cloud_img_name": "ubuntu-18.04-server-cloudimg-amd64.img",
14+
"user": "guest",
15+
"passwd": "guest",
3416
"root_img_gb": 10,
3517
36-
# LAUNCH OPTIONS
3718
"guest_memory_mb": 4096,
3819
"guest_num_vcpus": 8,
20+
"guest_num_sockets": 2,
21+
"guest_num_cores_per_socket": 2,
22+
"guest_num_threads_per_core": 2,
23+
"guest_numa_nodes": [
24+
{"id": 0, "cpus": "0-3", "memory_mb": 2048 },
25+
{"id": 1, "cpus": "4-7", "memory_mb": 2048 }
26+
],
3927
"guest_hugepage_support": true,
4028
"guest_hugepage_size": 2,
4129
"guest_hugepage_size_unit": "M",
@@ -56,6 +44,28 @@ JSON file (ignore the '#' lines which serve as comments).
5644
"queues": 2
5745
}]
5846
}
47+
`
48+
49+
// rootCmd represents the base command when called without any subcommands
50+
var rootCmd = &cobra.Command{
51+
Use: "virgo",
52+
Short: "virgo enables easy provisioning, configuration and management of Libvirt guests",
53+
Long: `virgo enables easy provisioning, configuration and management of Libvirt guests.
54+
55+
Most virgo commands accept a single argument, the name of the VM they act upon. Every command
56+
has its own flags.
57+
58+
For provisioning a new VM image, you should specify a JSON config file with provisioning
59+
options. Additionally, you may specify a provisioning script to be executed on image's first boot,
60+
and/or an initd script with commands to be executed on every boot.
61+
62+
For launching a new VM instance from an already-provisioned image, you should specify a
63+
JSON config file with launch options.
64+
65+
The example below shows all available provisioning and launch options, all in a single JSON file
66+
(these groups of options are separated by an empty line).
67+
68+
` + sampleConfig + `
5969
6070
The provisioning script can be any valid bash script, and it's executed as the
6171
last step of cloud-init provisioning.

example_config.json

-29
This file was deleted.

example_script.sh

-23
This file was deleted.

0 commit comments

Comments
 (0)