mirror of
				https://github.com/linuxkit/linuxkit.git
				synced 2025-11-04 11:03:44 +00:00 
			
		
		
		
	Merge pull request #3503 from deitch/metadata-cdrom-cloudinit
read cdrom userdata from spec location
This commit is contained in:
		@@ -13,7 +13,7 @@ onboot:
 | 
			
		||||
    image: linuxkit/dhcpcd:2f8a9b670aa6e96a09db56ec45c9f07ef2a811ee
 | 
			
		||||
    command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
 | 
			
		||||
  - name: metadata
 | 
			
		||||
    image: linuxkit/metadata:12794dd50fd1563dee6c960710fd8b923dba6231
 | 
			
		||||
    image: linuxkit/metadata:04ce7519c2ea2eaf99bbdc76bb01fc036eed7ab0
 | 
			
		||||
services:
 | 
			
		||||
  - name: rngd
 | 
			
		||||
    image: linuxkit/rngd:7fab61cca793113280397dcee8159f35dc37adcb
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ init:
 | 
			
		||||
onboot:
 | 
			
		||||
  # support metadata for optional config in /run/config
 | 
			
		||||
  - name: metadata
 | 
			
		||||
    image: linuxkit/metadata:12794dd50fd1563dee6c960710fd8b923dba6231
 | 
			
		||||
    image: linuxkit/metadata:04ce7519c2ea2eaf99bbdc76bb01fc036eed7ab0
 | 
			
		||||
  - name: sysctl
 | 
			
		||||
    image: linuxkit/sysctl:541f60fe3676611328e89e8bac251fc636b1a6aa
 | 
			
		||||
  - name: sysfs
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ onboot:
 | 
			
		||||
    image: linuxkit/dhcpcd:2f8a9b670aa6e96a09db56ec45c9f07ef2a811ee
 | 
			
		||||
    command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
 | 
			
		||||
  - name: metadata
 | 
			
		||||
    image: linuxkit/metadata:12794dd50fd1563dee6c960710fd8b923dba6231
 | 
			
		||||
    image: linuxkit/metadata:04ce7519c2ea2eaf99bbdc76bb01fc036eed7ab0
 | 
			
		||||
services:
 | 
			
		||||
  - name: getty
 | 
			
		||||
    image: linuxkit/getty:48f66df198981e692084bf70ab72b9fe2be0f880
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ onboot:
 | 
			
		||||
    image: linuxkit/dhcpcd:2f8a9b670aa6e96a09db56ec45c9f07ef2a811ee
 | 
			
		||||
    command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
 | 
			
		||||
  - name: metadata
 | 
			
		||||
    image: linuxkit/metadata:12794dd50fd1563dee6c960710fd8b923dba6231
 | 
			
		||||
    image: linuxkit/metadata:04ce7519c2ea2eaf99bbdc76bb01fc036eed7ab0
 | 
			
		||||
    command: ["/usr/bin/metadata", "hetzner"]
 | 
			
		||||
services:
 | 
			
		||||
  - name: rngd
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ onboot:
 | 
			
		||||
    image: linuxkit/dhcpcd:2f8a9b670aa6e96a09db56ec45c9f07ef2a811ee
 | 
			
		||||
    command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
 | 
			
		||||
  - name: metadata
 | 
			
		||||
    image: linuxkit/metadata:12794dd50fd1563dee6c960710fd8b923dba6231
 | 
			
		||||
    image: linuxkit/metadata:04ce7519c2ea2eaf99bbdc76bb01fc036eed7ab0
 | 
			
		||||
    command: ["/usr/bin/metadata", "openstack"]
 | 
			
		||||
services:
 | 
			
		||||
  - name: rngd
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ onboot:
 | 
			
		||||
    image: linuxkit/dhcpcd:2f8a9b670aa6e96a09db56ec45c9f07ef2a811ee
 | 
			
		||||
    command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
 | 
			
		||||
  - name: metadata
 | 
			
		||||
    image: linuxkit/metadata:12794dd50fd1563dee6c960710fd8b923dba6231
 | 
			
		||||
    image: linuxkit/metadata:04ce7519c2ea2eaf99bbdc76bb01fc036eed7ab0
 | 
			
		||||
    command: ["/usr/bin/metadata", "packet"]
 | 
			
		||||
services:
 | 
			
		||||
  - name: rngd
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@ onboot:
 | 
			
		||||
    image: linuxkit/dhcpcd:2f8a9b670aa6e96a09db56ec45c9f07ef2a811ee
 | 
			
		||||
    command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
 | 
			
		||||
  - name: metadata
 | 
			
		||||
    image: linuxkit/metadata:12794dd50fd1563dee6c960710fd8b923dba6231
 | 
			
		||||
    image: linuxkit/metadata:04ce7519c2ea2eaf99bbdc76bb01fc036eed7ab0
 | 
			
		||||
services:
 | 
			
		||||
  - name: getty
 | 
			
		||||
    image: linuxkit/getty:48f66df198981e692084bf70ab72b9fe2be0f880
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ onboot:
 | 
			
		||||
    image: linuxkit/dhcpcd:2f8a9b670aa6e96a09db56ec45c9f07ef2a811ee
 | 
			
		||||
    command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
 | 
			
		||||
  - name: metadata
 | 
			
		||||
    image: linuxkit/metadata:12794dd50fd1563dee6c960710fd8b923dba6231
 | 
			
		||||
    image: linuxkit/metadata:04ce7519c2ea2eaf99bbdc76bb01fc036eed7ab0
 | 
			
		||||
    command: ["/usr/bin/metadata", "vultr"]
 | 
			
		||||
services:
 | 
			
		||||
  - name: getty
 | 
			
		||||
 
 | 
			
		||||
@@ -9,17 +9,23 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	configFile = "config"
 | 
			
		||||
	metadataFile     = "meta-data"
 | 
			
		||||
	userdataFile     = "user-data"
 | 
			
		||||
	userdataFallback = "config"
 | 
			
		||||
	cdromDevs        = "/dev/sr[0-9]*"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	userdataFiles = []string{userdataFile, userdataFallback}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// ProviderCDROM is the type implementing the Provider interface for CDROMs
 | 
			
		||||
// It looks for a file called 'configFile' in the root
 | 
			
		||||
// It looks for file called 'meta-data', 'user-data' or 'config' in the root
 | 
			
		||||
type ProviderCDROM struct {
 | 
			
		||||
	device             string
 | 
			
		||||
	mountPoint         string
 | 
			
		||||
	err                error
 | 
			
		||||
	data       []byte
 | 
			
		||||
	userdata, metadata []byte
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ListCDROMs lists all the cdroms in the system
 | 
			
		||||
@@ -39,10 +45,28 @@ func ListCDROMs() []Provider {
 | 
			
		||||
// NewCDROM returns a new ProviderCDROM
 | 
			
		||||
func NewCDROM(device string) *ProviderCDROM {
 | 
			
		||||
	mountPoint, err := ioutil.TempDir("", "cd")
 | 
			
		||||
	p := ProviderCDROM{device, mountPoint, err, []byte{}}
 | 
			
		||||
	p := ProviderCDROM{device, mountPoint, err, []byte{}, []byte{}}
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		if p.err = p.mount(); p.err == nil {
 | 
			
		||||
			p.data, p.err = ioutil.ReadFile(path.Join(p.mountPoint, configFile))
 | 
			
		||||
			// read the userdata - we read the spec file and the fallback, but eventually
 | 
			
		||||
			// will remove the fallback
 | 
			
		||||
			for _, f := range userdataFiles {
 | 
			
		||||
				userdata, err := ioutil.ReadFile(path.Join(p.mountPoint, f))
 | 
			
		||||
				// did we find a file?
 | 
			
		||||
				if err == nil && userdata != nil {
 | 
			
		||||
					p.userdata = userdata
 | 
			
		||||
					break
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			if p.userdata == nil {
 | 
			
		||||
				p.err = fmt.Errorf("no userdata file found at any of %v", userdataFiles)
 | 
			
		||||
			}
 | 
			
		||||
			// read the metadata
 | 
			
		||||
			metadata, err := ioutil.ReadFile(path.Join(p.mountPoint, metadataFile))
 | 
			
		||||
			// did we find a file?
 | 
			
		||||
			if err == nil && metadata != nil {
 | 
			
		||||
				p.metadata = metadata
 | 
			
		||||
			}
 | 
			
		||||
			p.unmount()
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -55,12 +79,12 @@ func (p *ProviderCDROM) String() string {
 | 
			
		||||
 | 
			
		||||
// Probe checks if the CD has the right file
 | 
			
		||||
func (p *ProviderCDROM) Probe() bool {
 | 
			
		||||
	return len(p.data) != 0
 | 
			
		||||
	return len(p.userdata) != 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Extract gets both the CDROM specific and generic userdata
 | 
			
		||||
func (p *ProviderCDROM) Extract() ([]byte, error) {
 | 
			
		||||
	return p.data, p.err
 | 
			
		||||
	return p.userdata, p.err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// mount mounts a CDROM/DVD device under mountPoint
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user