Пример #1
0
func checkOpPerms(op string) error {
	if os.Geteuid() != 0 {
		return goof.Newf("REX-Ray can only be %s by root", op)
	}

	return nil
}
Пример #2
0
func (d *driver) waitJob(instanceID string) (*govmax.GetJobStatusResp, error) {

	timeout := make(chan bool, 1)
	go func() {
		time.Sleep(jobTimeout * time.Second)
		timeout <- true
	}()

	successCh := make(chan *govmax.GetJobStatusResp, 1)
	errorCh := make(chan struct {
		err           error
		jobStatusResp *govmax.GetJobStatusResp
	}, 1)
	go func(instanceID string) {
		log.Println("waiting for job to complete")
		for {
			jobStatusResp, jobStatus, err := d.client.GetJobStatus(instanceID)
			if err != nil {
				errorCh <- struct {
					err           error
					jobStatusResp *govmax.GetJobStatusResp
				}{
					goof.WithError(
						"error getting job status", err),
					nil,
				}
			}

			switch {
			case jobStatus == "TERMINATED" || jobStatus == "KILLED" ||
				jobStatus == "EXCEPTION":
				errorCh <- struct {
					err           error
					jobStatusResp *govmax.GetJobStatusResp
				}{
					goof.Newf(
						"problem with job: %s", jobStatus),
					jobStatusResp,
				}
				return
			case jobStatus == "COMPLETED":
				successCh <- jobStatusResp
				return
			}

			time.Sleep(100 * time.Millisecond)
		}
	}(instanceID)

	select {
	case jobStatusResp := <-successCh:
		return jobStatusResp, nil
	case jobStatusRespErr := <-errorCh:
		return jobStatusRespErr.jobStatusResp, jobStatusRespErr.err
	case <-timeout:
		return nil, goof.New("timed out waiting for job")
	}

}
Пример #3
0
func (d *driver) waitAttach(volumeID string) (*core.BlockDevice, error) {

	volumes, err := d.GetVolume(volumeID, "")
	if err != nil {
		return nil, err
	}

	if len(volumes) == 0 {
		return nil, goof.New("no volumes returned")
	}

	timeout := make(chan bool, 1)
	go func() {
		time.Sleep(10 * time.Second)
		timeout <- true
	}()

	successCh := make(chan *core.BlockDevice, 1)
	errorCh := make(chan error, 1)
	go func(volumeID string) {
		log.Println("XtremIO: waiting for volume attach")
		for {
			if d.multipath() {
				_, _ = exec.Command("/sbin/multipath", "-f",
					fmt.Sprintf("3%s", volumes[0].NetworkName)).Output()
				_, _ = exec.Command("/sbin/multipath").Output()
			}

			blockDevices, err := d.GetVolumeMapping()
			if err != nil {
				errorCh <- goof.Newf(
					"problem getting local block devices: %s", err)
				return
			}

			for _, blockDevice := range blockDevices {
				if blockDevice.VolumeID == volumeID {
					successCh <- blockDevice
					return
				}
			}
			time.Sleep(100 * time.Millisecond)
		}
	}(volumeID)

	select {
	case blockDevice := <-successCh:
		log.Println(fmt.Sprintf("XtremIO: got attachedVolume %s at %s",
			blockDevice.VolumeID, blockDevice.DeviceName))
		return blockDevice, nil
	case err := <-errorCh:
		return nil, err
	case <-timeout:
		return nil, goof.New("timed out waiting for mount")
	}

}
Пример #4
0
func getClient(clientID C.h) (types.Client, error) {
	clientsRWL.RLock()
	defer clientsRWL.RUnlock()
	c, ok := clients[clientID]
	if !ok {
		return nil, goof.Newf("invalid client ID %d", int64(clientID))
	}
	return c, nil
}