示例#1
0
func (command *commandSetMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsSetMetadata)
	containerName := params.containerName

	currentMetadata, err := containers.Get(command.Ctx.ServiceClient, containerName).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	i := 0
	keys := make([]string, len(currentMetadata))
	for k := range currentMetadata {
		keys[i] = k
		i++
	}

	updateOpts := containers.UpdateOpts{
		Metadata:       params.metadata,
		DeleteMetadata: keys,
	}
	updateResponse := containers.Update(command.Ctx.ServiceClient, containerName, updateOpts)
	if updateResponse.Err != nil {
		resource.Err = updateResponse.Err
		return
	}

	metadata, err := containers.Get(command.Ctx.ServiceClient, containerName).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	resource.Result = metadata
}
示例#2
0
func (command *commandUpdateMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsUpdateMetadata)
	containerName := params.containerName

	getResponse := containers.Get(command.Ctx.ServiceClient, containerName)
	if getResponse.Err != nil {
		resource.Err = getResponse.Err
		return
	}

	updateOpts := containers.UpdateOpts{
		Metadata: params.metadata,
	}
	updateResponse := containers.Update(command.Ctx.ServiceClient, containerName, updateOpts)
	if updateResponse.Err != nil {
		resource.Err = updateResponse.Err
		return
	}

	metadata, err := containers.Get(command.Ctx.ServiceClient, containerName).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	updatedMetadata := make(map[string]string, len(params.metadata))
	for k := range params.metadata {
		k = strings.Title(k)
		updatedMetadata[k] = metadata[k]
	}

	resource.Result = updatedMetadata
}
示例#3
0
文件: get.go 项目: hdansou/rack
func (command *commandGet) Execute(resource *handler.Resource) {
	containerName := resource.Params.(*paramsGet).container
	containerInfo, err := containers.Get(command.Ctx.ServiceClient, containerName).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(containerInfo)
	resource.Result.(map[string]interface{})["Name"] = containerName
}
示例#4
0
func (command *commandGetMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsGetMetadata)
	containerName := params.containerName

	metadata, err := containers.Get(command.Ctx.ServiceClient, containerName).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	resource.Result = metadata
}
示例#5
0
func (command *commandUpdate) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsUpdate)
	containerName := params.container

	containerRaw := containers.Get(command.Ctx.ServiceClient, containerName)
	if containerRaw.Err != nil {
		resource.Err = containerRaw.Err
		return
	}

	opts := params.opts
	rawResponse := containers.Update(command.Ctx.ServiceClient, containerName, opts)
	if rawResponse.Err != nil {
		resource.Err = rawResponse.Err
		return
	}
	resource.Result = fmt.Sprintf("Successfully updated container [%s]\n", containerName)
}
示例#6
0
func (command *commandDeleteMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsDeleteMetadata)
	containerName := params.containerName

	getResponse := containers.Get(command.Ctx.ServiceClient, containerName)
	if getResponse.Err != nil {
		resource.Err = getResponse.Err
		return
	}

	updateOpts := containers.UpdateOpts{
		DeleteMetadata: params.metadataKeys,
	}
	updateResponse := containers.Update(command.Ctx.ServiceClient, containerName, updateOpts)
	if updateResponse.Err != nil {
		resource.Err = updateResponse.Err
		return
	}
	resource.Result = fmt.Sprintf("Successfully deleted metadata with keys [%s] from container [%s].\n", strings.Join(params.metadataKeys, ", "), containerName)
}