Esempio n. 1
0
func runConfig(config *cloudinit.CloudConfig) error {
	f, err := ioutil.TempFile("", "rackspace-cloudinit-")
	if err != nil {
		return err
	}
	log.Println("writing to:", f.Name())
	_, err = f.WriteString(config.String())
	if err != nil {
		return err
	}
	// systemd-run coreos-cloudinit --file f.Name()
	props := []dbus.Property{
		dbus.PropDescription("Unit generated and executed by coreos-cloudinit on behalf of user"),
		dbus.PropExecStart([]string{"/usr/bin/coreos-cloudinit", "--from-file", f.Name()}, false),
	}

	tmp_file := filepath.Base(f.Name())
	name := fmt.Sprintf("%s.service", tmp_file)
	log.Printf("Creating transient systemd unit '%s'", name)

	conn, err := dbus.New()
	if err != nil {
		return err
	}
	_, err = conn.StartTransientUnit(name, "replace", props...)
	return err
}
Esempio n. 2
0
func handleHostname(contents string, scripts_dir string) (*cloudinit.CloudConfig, error) {
	config := cloudinit.CloudConfig{}
	hostname := contents
	// HOSTNAME="polvi-test"
	re := regexp.MustCompile("HOSTNAME=\"(.+)\"")
	keys := re.FindStringSubmatch(hostname)
	if len(keys) == 2 {
		hostname := keys[1]

		config.Hostname = hostname
	}

	return &config, nil
}
Esempio n. 3
0
// config.SSHAuthorizedKeys sets the "core" user, the other sets the root
func setKey(config *cloudinit.CloudConfig, key string) *cloudinit.CloudConfig {
	config.SSHAuthorizedKeys = append(config.SSHAuthorizedKeys, key)
	// set the password for both users
	if len(config.Users) == 0 {
		root := cloudinit.User{
			Name: "root",
		}
		root.SSHAuthorizedKeys = append(root.SSHAuthorizedKeys, key)
		config.Users = append(config.Users, root)
	} else {
		config.Users[0].SSHAuthorizedKeys = append(config.Users[0].SSHAuthorizedKeys, key)
	}
	return config
}
Esempio n. 4
0
func handleShadow(contents string, scripts_dir string) (*cloudinit.CloudConfig, error) {
	config := cloudinit.CloudConfig{}
	passwd := contents

	// root:$1$NyBnu0Gl$GBoj9u6lx3R8nyqHuxPwz/:15839:0:::::
	re := regexp.MustCompile("root:([^:]+):.+\n")
	keys := re.FindStringSubmatch(passwd)
	if len(keys) == 2 {
		passwd_hash := keys[1]

		// set the password for both users
		root := cloudinit.User{
			Name:         "root",
			PasswordHash: passwd_hash,
		}
		config.Users = append(config.Users, root)
		core := cloudinit.User{
			Name:         "core",
			PasswordHash: passwd_hash,
		}
		config.Users = append(config.Users, core)
	}
	return &config, nil
}