Beispiel #1
0
func (mgr *pxeManagerT) startIPXEserver() error {
	mgr.router = mux.NewRouter()

	// first stage ipxe boot script
	mgr.router.Methods("GET").PathPrefix("/ipxebootscript").HandlerFunc(ipxeBootScript)
	mgr.router.Methods("GET").PathPrefix("/first-stage-script/{serial}").HandlerFunc(mgr.firstStageScriptGenerator)

	// used by the first-stage-script:
	mgr.router.Methods("GET").PathPrefix("/hostinfo-helper").HandlerFunc(mgr.infoPusher)
	mgr.router.Methods("POST").PathPrefix("/final-cloud-config.yaml").HandlerFunc(mgr.cloudConfigGenerator)

	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/boot_complete").HandlerFunc(withSerialParam(mgr.bootComplete))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_installed").HandlerFunc(withSerialParam(mgr.setInstalled))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_metadata").HandlerFunc(withSerialParam(mgr.setMetadata))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/mark_fresh").HandlerFunc(withSerialParam(mgr.markFresh))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_provider_id").HandlerFunc(withSerialParam(mgr.setProviderId))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_ipmi_addr").HandlerFunc(withSerialParam(mgr.setIPMIAddr))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_cabinet").HandlerFunc(withSerialParam(mgr.setCabinet))

	// boring stuff
	mgr.router.Methods("GET").PathPrefix("/admin/hosts").HandlerFunc(mgr.hostsList)
	mgr.router.Methods("GET").PathPrefix("/images").HandlerFunc(imagesHandler)

	// add welcome handler for debugging
	mgr.router.Path("/").HandlerFunc(mgr.welcomeHandler)

	// serve static files like yochu, fleet, etc.
	mgr.router.PathPrefix("/").Handler(http.FileServer(http.Dir(conf.StaticHTMLPath)))

	glogWrapper := logging.NewGlogWrapper(8)
	loggedRouter := handlers.LoggingHandler(glogWrapper, mgr.router)

	glog.V(8).Infoln(fmt.Sprintf("starting iPXE server at %s:%d", conf.HTTPBindAddr, conf.HTTPPort))

	if conf.NoSecure {
		err := http.ListenAndServe(fmt.Sprintf("%s:%d", conf.HTTPBindAddr, conf.HTTPPort), loggedRouter)
		if err != nil {
			return err
		}
	} else {
		err := http.ListenAndServeTLS(fmt.Sprintf("%s:%d", conf.HTTPBindAddr, conf.HTTPPort), conf.HTTPSCertFile, conf.HTTPSKeyFile, loggedRouter)
		if err != nil {
			return err
		}
	}

	return nil
}
Beispiel #2
0
func (mgr *pxeManagerT) startIPXEserver() error {
	mgr.router = mux.NewRouter()

	// first stage ipxe boot script
	mgr.router.Methods("GET").PathPrefix("/ipxebootscript").HandlerFunc(mgr.ipxeBootScript)
	mgr.router.Methods("GET").PathPrefix("/first-stage-script/{serial}").HandlerFunc(mgr.firstStageScriptGenerator)

	// used by the first-stage-script:
	mgr.router.Methods("GET").PathPrefix("/hostinfo-helper").HandlerFunc(mgr.infoPusher)

	if mgr.useIgnition {
		mgr.router.Methods("POST").PathPrefix("/final-ignition-config.json").HandlerFunc(mgr.configGenerator)
	} else {
		mgr.router.Methods("POST").PathPrefix("/final-cloud-config.yaml").HandlerFunc(mgr.configGenerator)
	}

	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/boot_complete").HandlerFunc(withSerialParam(mgr.bootComplete))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_installed").HandlerFunc(withSerialParam(mgr.setInstalled))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_metadata").HandlerFunc(withSerialParam(mgr.setMetadata))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/mark_fresh").HandlerFunc(withSerialParam(mgr.markFresh))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_provider_id").HandlerFunc(withSerialParam(mgr.setProviderId))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_ipmi_addr").HandlerFunc(withSerialParam(mgr.setIPMIAddr))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_cabinet").HandlerFunc(withSerialParam(mgr.setCabinet))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_state").HandlerFunc(withSerialParam(mgr.setState))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/set_etcd_cluster_token").HandlerFunc(withSerialParam(mgr.setEtcdClusterToken))
	mgr.router.Methods("PUT").PathPrefix("/admin/host/{serial}/override").HandlerFunc(withSerialParam(mgr.override))

	// etcd discovery
	if mgr.useInternalEtcdDiscovery {
		etcdRouter := mgr.router.PathPrefix("/etcd").Subrouter()
		mgr.defineEtcdDiscoveryRoutes(etcdRouter)
	}

	// boring stuff
	mgr.router.Methods("GET").PathPrefix("/admin/hosts").HandlerFunc(mgr.hostsList)
	mgr.router.Methods("GET").PathPrefix("/images/{serial}").HandlerFunc(mgr.imagesHandler)

	// serve assets for yochu like etcd, fleet, docker, kubectl and rkt
	mgr.router.PathPrefix("/yochu").Handler(http.StripPrefix("/yochu", http.FileServer(http.Dir(mgr.yochuPath))))

	// add welcome handler for debugging
	mgr.router.Path("/").HandlerFunc(mgr.welcomeHandler)

	// serve static files like infopusher and mayuctl etc.
	mgr.router.PathPrefix("/").Handler(http.FileServer(http.Dir(mgr.staticHTMLPath)))

	glogWrapper := logging.NewGlogWrapper(8)
	loggedRouter := handlers.LoggingHandler(glogWrapper, mgr.router)

	glog.V(8).Infoln(fmt.Sprintf("starting iPXE server at %s:%d", mgr.httpBindAddress, mgr.httpPort))

	if mgr.noTLS {
		err := http.ListenAndServe(fmt.Sprintf("%s:%d", mgr.httpBindAddress, mgr.httpPort), loggedRouter)
		if err != nil {
			return err
		}
	} else {
		err := http.ListenAndServeTLS(fmt.Sprintf("%s:%d", mgr.httpBindAddress, mgr.httpPort), mgr.tlsCertFile, mgr.tlsKeyFile, loggedRouter)
		if err != nil {
			return err
		}
	}

	return nil
}