예제 #1
0
파일: gce.go 프로젝트: pwaller/mantle
func NewGCECluster(conf GCEOptions) (Cluster, error) {
	var client *http.Client
	var err error
	if conf.ServiceAuth {
		client = auth.GoogleServiceClient()
	} else {
		client, err = auth.GoogleClient()
	}
	if err != nil {
		return nil, err
	}

	api, err := compute.New(client)
	if err != nil {
		return nil, err
	}

	gc := &gceCluster{
		api:      api,
		conf:     &conf,
		machines: make(map[string]*gceMachine),
	}

	gc.sshAgent, err = network.NewSSHAgent(&net.Dialer{})
	if err != nil {
		return nil, err
	}

	return gc, nil
}
예제 #2
0
func NewLocalCluster() (*LocalCluster, error) {
	lc := &LocalCluster{}

	var err error
	lc.nshandle, err = NsCreate()
	if err != nil {
		return nil, err
	}
	lc.AddCloser(&lc.nshandle)

	dialer := NewNsDialer(lc.nshandle)
	lc.SSHAgent, err = network.NewSSHAgent(dialer)
	if err != nil {
		lc.Destroy()
		return nil, err
	}
	lc.AddCloser(lc.SSHAgent)

	// dnsmasq and etcd much be launched in the new namespace
	nsExit, err := NsEnter(lc.nshandle)
	if err != nil {
		return nil, err
	}
	defer nsExit()

	lc.Dnsmasq, err = NewDnsmasq()
	if err != nil {
		lc.Destroy()
		return nil, err
	}
	lc.AddDestructor(lc.Dnsmasq)

	lc.SimpleEtcd, err = NewSimpleEtcd()
	if err != nil {
		lc.Destroy()
		return nil, err
	}
	lc.AddDestructor(lc.SimpleEtcd)

	lc.NTPServer, err = ntp.NewServer(":123")
	if err != nil {
		lc.Destroy()
		return nil, err
	}
	lc.AddCloser(lc.NTPServer)
	go lc.NTPServer.Serve()

	lc.OmahaServer, err = omaha.NewServer(":34567", &omaha.UpdaterStub{})
	if err != nil {
		lc.Destroy()
		return nil, err
	}
	lc.AddDestructor(lc.OmahaServer)
	go lc.OmahaServer.Serve()

	return lc, nil
}
예제 #3
0
파일: cluster.go 프로젝트: hanscj1/mantle
func NewLocalCluster() (*LocalCluster, error) {
	lc := &LocalCluster{}

	var err error
	lc.nshandle, err = NsCreate()
	if err != nil {
		return nil, err
	}

	dialer := NewNsDialer(lc.nshandle)
	lc.SSHAgent, err = network.NewSSHAgent(dialer)
	if err != nil {
		lc.nshandle.Close()
		return nil, err
	}

	// dnsmasq and etcd much be lunched in the new namespace
	nsExit, err := NsEnter(lc.nshandle)
	if err != nil {
		return nil, err
	}
	defer nsExit()

	lc.Dnsmasq, err = NewDnsmasq()
	if err != nil {
		lc.nshandle.Close()
		return nil, err
	}

	lc.SimpleEtcd, err = NewSimpleEtcd()
	if err != nil {
		lc.Dnsmasq.Destroy()
		lc.nshandle.Close()
		return nil, err
	}

	lc.NTPServer, err = ntp.NewServer(":123")
	if err != nil {
		lc.Dnsmasq.Destroy()
		lc.SimpleEtcd.Destroy()
		lc.nshandle.Close()
		return nil, err
	}
	go lc.NTPServer.Serve()

	return lc, nil
}
예제 #4
0
파일: aws.go 프로젝트: chancez/mantle
func NewAWSCluster(conf AWSOptions) (Cluster, error) {
	api := ec2.New(aws.NewConfig().WithCredentials(credentials.NewEnvCredentials()))

	agent, err := network.NewSSHAgent(&net.Dialer{})
	if err != nil {
		return nil, err
	}

	ac := &awsCluster{
		api:   api,
		conf:  conf,
		agent: agent,
		machs: make(map[string]*awsMachine),
	}

	return ac, nil
}
예제 #5
0
파일: base.go 프로젝트: carriercomm/mantle
func newBaseCluster() (*baseCluster, error) {
	// set reasonable timeout and keepalive interval
	dialer := &net.Dialer{
		Timeout:   30 * time.Second,
		KeepAlive: 30 * time.Second,
	}

	agent, err := network.NewSSHAgent(dialer)
	if err != nil {
		return nil, err
	}

	bc := &baseCluster{
		agent:   agent,
		machmap: make(map[string]Machine),
	}

	return bc, nil
}
예제 #6
0
파일: conf_test.go 프로젝트: pwaller/mantle
func TestConfCopyKey(t *testing.T) {
	agent, err := network.NewSSHAgent(&net.Dialer{})
	if err != nil {
		t.Fatalf("NewSSHAgent failed: %v", err)
	}

	keys, err := agent.List()
	if err != nil {
		t.Fatalf("agent.List failed: %v", err)
	}

	tests := []struct {
		conf string
	}{
		{""},
		{`{ "ignitionVersion": 1 }`},
		{"#cloud-config"},
	}

	for i, tt := range tests {
		conf, err := NewConf(tt.conf)
		if err != nil {
			t.Errorf("failed to parse config %i: %v", i, err)
			continue
		}

		conf.CopyKeys(keys)

		str := conf.String()

		if !strings.Contains(str, "ssh-rsa ") || !strings.Contains(str, " core@default") {
			t.Errorf("ssh public key not found in config %i: ", i)
			continue
		}
	}
}