예제 #1
0
파일: get.go 프로젝트: nelsnelson/rack
func (command *commandGet) Execute(resource *handler.Resource) {
	volumeID := resource.Params.(*paramsGet).volumeID
	volume, err := osVolumes.Get(command.Ctx.ServiceClient, volumeID).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = volumeSingle(volume)
}
예제 #2
0
func (command *commandDelete) Execute(resource *handler.Resource) {
	volumeID := resource.Params.(*paramsDelete).volumeID
	err := osVolumes.Delete(command.Ctx.ServiceClient, volumeID).ExtractErr()
	if err != nil {
		resource.Err = err
		return
	}

	if resource.Params.(*paramsDelete).wait {
		i := 0
		for i < 120 {
			_, err := osVolumes.Get(command.Ctx.ServiceClient, volumeID).Extract()
			if err != nil {
				break
			}
			time.Sleep(5 * time.Second)
			i++
		}
		resource.Result = fmt.Sprintf("Deleted volume [%s]\n", volumeID)
	} else {
		resource.Result = fmt.Sprintf("Deleting volume [%s]\n", volumeID)
	}
}
예제 #3
0
func (command *commandCreate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsCreate).opts
	volume, err := osVolumes.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}

	if resource.Params.(*paramsCreate).wait {
		err = osVolumes.WaitForStatus(command.Ctx.ServiceClient, volume.ID, "available", 600)
		if err != nil {
			resource.Err = err
			return
		}

		volume, err = osVolumes.Get(command.Ctx.ServiceClient, volume.ID).Extract()
		if err != nil {
			resource.Err = err
			return
		}
	}

	resource.Result = volumeSingle(volume)
}