Exemple #1
0
func NewServer(confPath string, setup PipelineSetupFunc) (*OsInstallServer, error) {
	conf, err := jsonconf.New(confPath).Load()
	if err != nil {
		return nil, err
	}
	log := logger.NewLogrusLogger(conf)
	repo, err := mysqlrepo.NewRepo(conf, log)
	if err != nil {
		return nil, err
	}

	api := rest.NewAPI()

	api.Use(setup(conf, log, repo)...)

	// routes a global
	router, err := rest.MakeRouter(routes...)

	api.SetApp(router)

	server := &OsInstallServer{
		conf:    conf,
		log:     log,
		repo:    repo,
		handler: api.MakeHandler(),
	}

	return server, nil
}
Exemple #2
0
func New() (*OSInstallAgent, error) {
	// get config
	var conf, err = iniconf.NewContent([]byte(confContent)).Load()
	if err != nil {
		return nil, err
	}
	var log = logger.NewLogrusLogger(conf)
	var agent = &OSInstallAgent{
		Config: conf,
		Logger: log,
	}

	var data []byte
	// get sn
	if data, err = execScript(GetSNScript); err != nil {
		log.Error(err)
		return nil, err
	}
	agent.Sn = string(data)
	agent.Sn = strings.Trim(agent.Sn, "\n")

	// get mac addr
	if data, err = execScript(GetMacScript); err != nil {
		log.Error(err)
		return nil, err
	}
	agent.MacAddr = string(data)
	agent.MacAddr = strings.Trim(agent.MacAddr, "\n")

	var serverAddr = ""
	// get server addr
	if serverAddr, err = getCmdlineArgs(RegexpServerAddr); err != nil {
		log.Error(err)
		return nil, err
	}
	agent.ServerAddr = serverAddr
	// agent.ServerAddr = "http://10.0.0.135:8083"
	agent.ServerAddr = strings.Trim(agent.ServerAddr, "\n")

	// loop interval
	var interval string
	if interval, err = getCmdlineArgs(RegexpLoopInterval); err != nil {
		log.Error(err)
		agent.LoopInterval = defaultLoopInterval
	} else {
		agent.LoopInterval = parseInterval(interval)
	}

	// get Vendor
	if data, err = execScript(GetVendorScript); err != nil {
		log.Error(err)
		return nil, err
	}
	agent.Vendor = string(data)
	agent.Vendor = strings.Trim(agent.Vendor, "\n")

	// get Model number
	if data, err = execScript(GetModelNumScript); err != nil {
		log.Error(err)
		return nil, err
	}
	var productModel = strings.SplitN(string(data), " ", 2)
	agent.Product = productModel[0]
	if len(productModel) > 1 {
		agent.ModelName = productModel[1]
	} else {
		agent.ModelName = ""
	}
	agent.Product = strings.Trim(agent.Product, "\n")
	agent.ModelName = strings.Trim(agent.ModelName, "\n")

	return agent, nil
}