func storagepoolAgent(c *cli.Context) {
	healthCheckInterval := c.GlobalInt("healthcheck-interval")
	healthCheckBaseDir := c.GlobalString("healthcheck-basedir")
	healthCheckType := c.String("storagepool-healthcheck-type")

	cattleUrl := c.GlobalString("url")
	cattleAccessKey := c.GlobalString("access-key")
	cattleSecretKey := c.GlobalString("secret-key")
	if c.GlobalBool("debug") {
		log.SetLevel(log.DebugLevel)
	}

	storagepoolRootDir := c.GlobalString("storagepool-rootdir")
	driver := c.GlobalString("storagepool-driver")
	if driver == "" {
		log.Fatal("required field storagepool-driver has not been set")
	}

	cattleClient, err := cattle.NewCattleClient(cattleUrl, cattleAccessKey, cattleSecretKey)
	if err != nil {
		log.Fatal(err)
	}

	storagepoolAgent := NewStoragepoolAgent(healthCheckInterval, storagepoolRootDir, driver, healthCheckBaseDir, healthCheckType, cattleClient)

	metadataUrl := c.String("storagepool-metadata-url")

	if err := storagepoolAgent.Run(metadataUrl); err != nil {
		log.Fatal(err)
	}
}
Exemple #2
0
func volumeAgent(c *cli.Context) {
	socket := c.String("socket")
	cattleUrl := c.GlobalString("url")
	cattleAccessKey := c.GlobalString("access-key")
	cattleSecretKey := c.GlobalString("secret-key")
	if c.GlobalBool("debug") {
		logrus.SetLevel(logrus.DebugLevel)
	}

	healthCheckInterval := c.GlobalInt("healthcheck-interval")
	healthCheckBaseDir := c.GlobalString("healthcheck-basedir")

	controlChan := make(chan bool, 1)

	storagepoolDir := c.GlobalString("storagepool-rootdir")

	storagepoolUuid := c.GlobalString("storagepool-uuid")
	var err error
	for {
		if storagepoolUuid != "" {
			break
		}
		spUuid, err := ioutil.ReadFile(filepath.Join(storagepoolDir, rootUuidFileName))
		if err != nil {
			logrus.Errorf("Error reading the storage pool uuid [%v]", err)
		} else {
			storagepoolUuid = string(spUuid)
			break
		}
		time.Sleep(5 * time.Second)
	}

	storagepoolName := c.GlobalString("storagepool-name")
	storagepoolDriver := c.GlobalString("storagepool-driver")
	if storagepoolDriver == "" {
		logrus.Fatal("required field storagepool-driver has not been set")
	}

	hostUuid := c.String("host-uuid")
	if hostUuid == "" {
		logrus.Fatal("required field host-uuid has not been set")
	}

	cattleClient, err := cattle.NewCattleClient(cattleUrl, cattleAccessKey, cattleSecretKey, storagepoolDriver, storagepoolName)
	if err != nil {
		logrus.Fatal(err)
	}

	volAgent := NewVolumeAgent(healthCheckBaseDir, socket, hostUuid, healthCheckInterval, cattleClient, storagepoolUuid)

	if err := volAgent.Run(controlChan); err != nil {
		logrus.Fatal(err)
	}
}
func volumeAgent(c *cli.Context) {
	socket := c.String("socket")
	cattleUrl := c.GlobalString("url")
	cattleAccessKey := c.GlobalString("access-key")
	cattleSecretKey := c.GlobalString("secret-key")
	if c.GlobalBool("debug") {
		logrus.SetLevel(logrus.DebugLevel)
	}

	healthCheckInterval := c.GlobalInt("healthcheck-interval")
	healthCheckBaseDir := c.GlobalString("healthcheck-basedir")

	driver := c.GlobalString("storagepool-driver")
	if driver == "" {
		logrus.Fatal("required field storagepool-driver has not been set")
	}

	hostUuid := c.String("host-uuid")
	if hostUuid == "" {
		logrus.Fatal("required field host-uuid has not been set")
	}

	resultChan := make(chan error)

	go func(rc chan<- error) {
		cmdArgs := buildConvoyCmdArgs(c, socket)
		cmd := exec.Command("convoy", cmdArgs...)
		logrus.Infof("Launching convoy with args: %s", cmdArgs)
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		err := cmd.Run()
		logrus.Infof("convoy exited with error: %v", err)
		rc <- err
	}(resultChan)

	go func(rc chan<- error) {
		controlChan := make(chan bool, 1)
		cattleClient, err := cattle.NewCattleClient(cattleUrl, cattleAccessKey, cattleSecretKey)
		if err != nil {
			rc <- fmt.Errorf("Error getting cattle client: %v", err)
		}
		volAgent := NewVolumeAgent(healthCheckBaseDir, socket, hostUuid, healthCheckInterval, cattleClient, driver)
		err = volAgent.Run(controlChan)
		logrus.Infof("volume-agent exited with error: %v", err)
		rc <- err
	}(resultChan)

	<-resultChan
	logrus.Info("Exiting.")
}
Exemple #4
0
func start(c *cli.Context) {
	healthCheckInterval := c.GlobalInt("healthcheck-interval")

	cattleUrl := c.GlobalString("url")
	cattleAccessKey := c.GlobalString("access-key")
	cattleSecretKey := c.GlobalString("secret-key")
	if c.GlobalBool("debug") {
		log.SetLevel(log.DebugLevel)
	}

	socket := c.GlobalString("socket")

	storagepoolRootDir := c.GlobalString("storagepool-rootdir")
	driver := c.GlobalString("storagepool-driver")
	if driver == "" {
		log.Fatal("required field storagepool-driver has not been set")
	}

	cattleClient, err := cattle.NewCattleClient(cattleUrl, cattleAccessKey, cattleSecretKey)
	if err != nil {
		log.Fatal(err)
	}

	resultChan := make(chan error)

	go func(rc chan error) {
		storagepoolAgent := NewStoragepoolAgent(healthCheckInterval, storagepoolRootDir, driver, cattleClient)
		metadataUrl := c.String("storagepool-metadata-url")
		err := storagepoolAgent.Run(metadataUrl)
		log.Errorf("Error while running storage pool agent [%v]", err)
		rc <- err
	}(resultChan)

	go func(rc chan error) {
		conf := cattleevents.Config{
			CattleURL:       cattleUrl,
			CattleAccessKey: cattleAccessKey,
			CattleSecretKey: cattleSecretKey,
			WorkerCount:     10,
			Socket:          socket,
		}
		err := cattleevents.ConnectToEventStream(conf)
		log.Errorf("Cattle event listener exited with error: %s", err)
		rc <- err
	}(resultChan)

	<-resultChan
	log.Info("Exiting.")
}
Exemple #5
0
func volumeAgent(c *cli.Context) {
	socket := c.GlobalString("socket")
	components := c.String("components")
	cattleUrl := c.GlobalString("url")
	cattleAccessKey := c.GlobalString("access-key")
	cattleSecretKey := c.GlobalString("secret-key")
	if c.GlobalBool("debug") {
		logrus.SetLevel(logrus.DebugLevel)
	}

	driver := c.GlobalString("storagepool-driver")
	if driver == "" {
		logrus.Fatal("required field storagepool-driver has not been set")
	}

	resultChan := make(chan error)

	if strings.Contains(components, "driver") {
		go func(rc chan<- error) {
			cmdArgs := buildConvoyCmdArgs(c, socket)
			cmd := exec.Command("convoy", cmdArgs...)
			logrus.Infof("Launching convoy with args: %s", cmdArgs)
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			err := cmd.Run()
			logrus.Infof("convoy exited with error: %v", err)
			rc <- err
		}(resultChan)
	}

	if strings.Contains(components, "agent") {
		go func(rc chan<- error) {
			controlChan := make(chan bool, 1)
			cattleClient, err := cattle.NewCattleClient(cattleUrl, cattleAccessKey, cattleSecretKey)
			if err != nil {
				rc <- fmt.Errorf("Error getting cattle client: %v", err)
			}
			volAgent := NewVolumeAgent(socket, 1000, cattleClient, driver)
			err = volAgent.Run(controlChan)
			logrus.Infof("volume-agent exited with error: %v", err)
			rc <- err
		}(resultChan)
	}

	<-resultChan
	logrus.Info("Exiting.")
}