Beispiel #1
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
}
Beispiel #2
0
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
}
Beispiel #3
0
func main() {
	flag.Parse()
	capnslog.SetFormatter(capnslog.NewStringFormatter(os.Stderr))
	capnslog.SetGlobalLogLevel(capnslog.INFO)

	var l, n time.Time
	var err error
	if *now != "" {
		n, err = time.Parse(time.UnixDate, *now)
		if err != nil {
			plog.Fatalf("Parsing --now failed: %v", err)
		}
	}
	if *leap != "" {
		l, err = time.Parse(time.UnixDate, *leap)
		if err != nil {
			plog.Fatalf("Parsing --leap failed: %v", err)
		}
		if (l.Truncate(24*time.Hour) != l) || (l.UTC().Day() != 1) {
			plog.Fatalf("Invalid --leap time: %s", l)
		}
	}

	s, err := ntp.NewServer(":123")
	if err != nil {
		plog.Fatalf("Listen failed: %v", err)
	}

	if !n.IsZero() {
		s.SetTime(n)
	}
	if !l.IsZero() {
		s.SetLeapSecond(l, ntp.LEAP_ADD)
	}

	s.Serve()
}