예제 #1
0
파일: delete.go 프로젝트: hdansou/rack
func (command *commandDelete) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsDelete)
	containerName := params.container
	if command.Ctx.CLIContext.IsSet("purge") {
		allPages, err := objects.List(command.Ctx.ServiceClient, containerName, nil).AllPages()
		if err != nil {
			resource.Err = err
			return
		}
		objectNames, err := objects.ExtractNames(allPages)
		if err != nil {
			resource.Err = err
			return
		}
		wg := &sync.WaitGroup{}
		for _, objectName := range objectNames {
			wg.Add(1)
			go func(objectName string) {
				defer wg.Done()
				rawResponse := objects.Delete(command.Ctx.ServiceClient, containerName, objectName, nil)
				if rawResponse.Err != nil {
					resource.Err = rawResponse.Err
					return
				}
			}(objectName)
		}
		wg.Wait()
		numTimesChecked := 0
		for {
			allPages, err := objects.List(command.Ctx.ServiceClient, containerName, nil).AllPages()
			if err != nil {
				resource.Err = err
				return
			}
			objectNames, err := objects.ExtractNames(allPages)
			if err != nil {
				resource.Err = err
				return
			}
			if len(objectNames) == 0 {
				break
			}
			numTimesChecked++
			if numTimesChecked == 60 {
				resource.Err = fmt.Errorf("Purging objects from container [%s] timed out. There are still %d object left.\n", containerName, len(objectNames))
			}
			time.Sleep(5 * time.Second)
		}
	}
	rawResponse := containers.Delete(command.Ctx.ServiceClient, containerName)
	if rawResponse.Err != nil {
		resource.Err = rawResponse.Err
		return
	}
	resource.Result = fmt.Sprintf("Successfully deleted container [%s]\n", containerName)
}
예제 #2
0
파일: delete.go 프로젝트: harshalhshah/rack
func (command *commandDelete) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsDelete)
	containerName := params.container
	if params.purge {
		emptyParams := &handleEmptyParams{
			container:   containerName,
			quiet:       params.quiet,
			concurrency: params.concurrency,
		}
		handleEmpty(command, resource, emptyParams)
	}

	fmt.Println("Running containers.Delete")
	rawResponse := containers.Delete(command.Ctx.ServiceClient, containerName)
	if rawResponse.Err != nil {
		resource.Err = rawResponse.Err
		return
	}
	resource.Result = fmt.Sprintf("Successfully deleted container [%s]\n", containerName)
}