Commit 8636db4c authored by Finn's avatar Finn

Add explicit cloud-init support to the metadata server

parent 1467866a
Pipeline #3419 passed with stage
in 1 minute and 33 seconds
......@@ -23,6 +23,8 @@ type Config struct {
ImageHost string // ImageHost is the base URL for the disk image server
ImageOwner string // ImageOwner is the UID that should own volume images
MetadataBind string // MetadataBind is the port (and optionally IP) to bind the metadata server to
CloudInitSeed string // CloudInitSeed is the seed to pass to cloud-init
CloudName string // CloudName is the cloud provider name to tell cloud-init
Vault VaultConfig
}
......@@ -55,6 +57,8 @@ var (
ImageHost: "http://image-host.fruit-0.entanglement.garden",
ImageOwner: "64055",
MetadataBind: "127.0.0.1:8081",
CloudInitSeed: "http://127.0.0.1:8081/cloud-init/",
CloudName: "rhyzome",
Vault: VaultConfig{
TLSConfig: api.TLSConfig{},
InjectionCommand: "/opt/entanglement/vault-inject.sh",
......
......@@ -198,6 +198,12 @@ func (i *Instance) CreateAsJob(j *jobs.Job) error {
Graphics: []libvirtxml.DomainGraphic{libvirtxml.DomainGraphic{VNC: &libvirtxml.DomainGraphicVNC{}}},
Videos: []libvirtxml.DomainVideo{libvirtxml.DomainVideo{Model: libvirtxml.DomainVideoModel{Type: "virtio"}}},
},
QEMUCommandline: &libvirtxml.DomainQEMUCommandline{
Args: []libvirtxml.DomainQEMUCommandlineArg{
libvirtxml.DomainQEMUCommandlineArg{Value: "-smbios"},
libvirtxml.DomainQEMUCommandlineArg{Value: "type=1,serial=ds=nocloud-net;s=" + config.C.CloudInitSeed},
},
},
}
domainXMLString, err := domainXML.Marshal()
......
package metadata
import (
"log"
"net/http"
libvirtxml "github.com/libvirt/libvirt-go-xml"
"gopkg.in/yaml.v2"
"git.callpipe.com/entanglement.garden/rhyzome/config"
"git.callpipe.com/entanglement.garden/rhyzome/utils"
)
type CloudInitMetadata struct {
LocalHostname string `yaml:"local-hostname,omitempty"`
InstanceID string `yaml:"instance-id,omitempty"`
CloudName string `yaml:"cloud-name,omitempty"`
}
func cloudInitUserData(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
domain := ctx.Value(utils.InstanceDomainXMLContextKey).(libvirtxml.Domain)
w.Write([]byte(domain.Description))
}
func cloudInitMetaData(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/yaml")
type cloudInitMetaDataResponse struct {
}
ctx := r.Context()
domain := ctx.Value(utils.InstanceDomainXMLContextKey).(libvirtxml.Domain)
err := yaml.NewEncoder(w).Encode(CloudInitMetadata{
LocalHostname: domain.Name,
InstanceID: domain.UUID,
CloudName: config.C.CloudName,
})
if err != nil {
log.Println("Error encoding response", err)
http.Error(w, err.Error(), 500)
}
}
......@@ -27,6 +27,8 @@ func ListenAndServe() {
r.Use(utils.LoggingMiddleware)
r.Use(lookupRequester)
r.HandleFunc("/", index)
r.HandleFunc("/cloud-init/user-data", cloudInitUserData)
r.HandleFunc("/cloud-init/meta-data", cloudInitMetaData)
r.HandleFunc("/guest-info", guestInfo)
r.HandleFunc("/guest-get-osinfo", guestGetOSInfo)
r.HandleFunc("/vault/inject-app-role", vault.InjectAppRole)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment