Compare commits

..

7 Commits

Author SHA1 Message Date
Brian Waldon
d823f99f7d chore(release): Bump version to v0.1.1 2014-03-05 14:52:51 -08:00
Brian Waldon
282e4637cd Merge pull request #1 from bcwaldon/bump-go-systemd
bump github.com/coreos/go-systemd/dbus
2014-03-05 14:51:24 -08:00
Brian Waldon
840b1dfb6e Merge pull request #2 from bcwaldon/custom-ssh-identity
feat(ssh): Set custom name for ssh identity
2014-03-05 14:50:51 -08:00
Brian Waldon
7474a85fec refactor(config): s/ResolveCloudConfig/ApplyCloudConfig/ 2014-03-05 14:50:20 -08:00
Brian Waldon
95a00070c3 feat(ssh): Set custom name for ssh identity 2014-03-05 14:38:40 -08:00
Brian Waldon
8b5049cf40 bump(github.com/coreos/go-systemd/dbus): 57eb061b918b793c3ec3939c69a632fc4dfac8c9 2014-03-05 10:54:51 -08:00
Brian Waldon
743b2dd939 chore(release): Bump version back to v0.1.0+git 2014-03-04 21:08:15 -08:00
7 changed files with 78 additions and 10 deletions

View File

@@ -15,6 +15,9 @@ Only a subset of [cloud-config functionality][cloud-config] is implemented. A se
Provided public SSH keys will be authorized for the `core` user.
The keys will be named "coreos-cloudinit" by default.
Override this with the `--ssh-key-name` flag when calling `coreos-cloudinit`.
### Custom cloud-config Parameters
#### coreos.etcd.discovery_url

View File

@@ -6,6 +6,8 @@ import (
"launchpad.net/goyaml"
)
const DefaultSSHKeyName = "coreos-cloudinit"
type CloudConfig struct {
SSH_Authorized_Keys []string
Coreos struct{Etcd struct{ Discovery_URL string }; Fleet struct{ Autostart bool } }
@@ -26,9 +28,9 @@ func (cc CloudConfig) String() string {
}
}
func ResolveCloudConfig(cfg CloudConfig) error {
func ApplyCloudConfig(cfg CloudConfig, sshKeyName string) error {
if len(cfg.SSH_Authorized_Keys) > 0 {
err := AuthorizeSSHKeys(cfg.SSH_Authorized_Keys)
err := AuthorizeSSHKeys(sshKeyName, cfg.SSH_Authorized_Keys)
if err == nil {
log.Printf("Authorized SSH keys for core user")
} else {

View File

@@ -10,7 +10,7 @@ import (
// Add the provide SSH public key to the core user's list of
// authorized keys
func AuthorizeSSHKeys(keys []string) error {
func AuthorizeSSHKeys(name string, keys []string) error {
for i, key := range keys {
keys[i] = strings.TrimSpace(key)
}
@@ -19,7 +19,7 @@ func AuthorizeSSHKeys(keys []string) error {
// also ends with a newline
joined := fmt.Sprintf("%s\n", strings.Join(keys, "\n"))
cmd := exec.Command("update-ssh-keys", "-u", "core", "-a", "coreos-cloudinit")
cmd := exec.Command("update-ssh-keys", "-u", "core", "-a", name)
stdin, err := cmd.StdinPipe()
if err != nil {
return err

View File

@@ -10,7 +10,7 @@ import (
"github.com/coreos/coreos-cloudinit/cloudinit"
)
const version = "0.1.0"
const version = "0.1.1"
func main() {
var userdata []byte
@@ -28,6 +28,9 @@ func main() {
var workspace string
flag.StringVar(&workspace, "workspace", "/var/lib/coreos-cloudinit", "Base directory coreos-cloudinit should use to store data")
var sshKeyName string
flag.StringVar(&sshKeyName, "ssh-key-name", cloudinit.DefaultSSHKeyName, "Add SSH keys to the system with the given name")
flag.Parse()
if printVersion == true {
@@ -70,7 +73,7 @@ func main() {
switch t := parsed.(type) {
case cloudinit.CloudConfig:
err = cloudinit.ResolveCloudConfig(t)
err = cloudinit.ApplyCloudConfig(t, sshKeyName)
case cloudinit.Script:
var path string
path, err = cloudinit.PersistScriptInWorkspace(t, workspace)

View File

@@ -128,10 +128,7 @@ func (c *Conn) ReloadOrTryRestartUnit(name string, mode string) (string, error)
// unique. mode is the same as in StartUnit(), properties contains properties
// of the unit.
func (c *Conn) StartTransientUnit(name string, mode string, properties ...Property) (string, error) {
// the dbus interface for this method does not use the last argument and
// should simply be given an empty list. We use a concrete type here
// (instead of the more appropriate interface{}) to satisfy the dbus library.
return c.runJob("org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, make([]string, 0))
return c.runJob("org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, make([]PropertyCollection, 0))
}
// KillUnit takes the unit name and a UNIX signal number to send. All of the unit's

View File

@@ -17,6 +17,8 @@ limitations under the License.
package dbus
import (
"fmt"
"math/rand"
"os"
"path/filepath"
"testing"
@@ -153,3 +155,59 @@ func TestGetUnitPropertiesRejectsInvalidName(t *testing.T) {
t.Fatal("Expected an error, got nil")
}
}
// Ensure that basic transient unit starting and stopping works.
func TestStartStopTransientUnit(t *testing.T) {
conn := setupConn(t)
props := []Property{
PropExecStart([]string{"/bin/sleep", "400"}, false),
}
target := fmt.Sprintf("testing-transient-%d.service", rand.Int())
// Start the unit
job, err := conn.StartTransientUnit(target, "replace", props...)
if err != nil {
t.Fatal(err)
}
if job != "done" {
t.Fatal("Job is not done, %v", job)
}
units, err := conn.ListUnits()
var unit *UnitStatus
for _, u := range units {
if u.Name == target {
unit = &u
}
}
if unit == nil {
t.Fatalf("Test unit not found in list")
}
if unit.ActiveState != "active" {
t.Fatalf("Test unit not active")
}
// 3. Stop the unit
job, err = conn.StopUnit(target, "replace")
if err != nil {
t.Fatal(err)
}
units, err = conn.ListUnits()
unit = nil
for _, u := range units {
if u.Name == target {
unit = &u
}
}
if unit != nil {
t.Fatalf("Test unit found in list, should be stopped")
}
}

View File

@@ -41,6 +41,11 @@ type Property struct {
Value dbus.Variant
}
type PropertyCollection struct {
Name string
Properties []Property
}
type execStart struct {
Path string // the binary path to execute
Args []string // an array with all arguments to pass to the executed command, starting with argument 0