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 }
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 }
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 }
func (command *commandGet) Execute(resource *handler.Resource) { containerName := resource.Params.(*paramsGet).container containerRaw := containers.Get(command.Ctx.ServiceClient, containerName) containerInfo, err := containerRaw.Extract() if err != nil { resource.Err = err return } containerMetadata, err := containerRaw.ExtractMetadata() if err != nil { resource.Err = err return } resource.Result = structs.Map(containerInfo) resource.Result.(map[string]interface{})["Name"] = containerName resource.Result.(map[string]interface{})["Metadata"] = containerMetadata }
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) }
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) }
func CheckContainerExists(sc *gophercloud.ServiceClient, containerName string) error { containerRaw := containers.Get(sc, containerName) return containerRaw.Err }