Skip to content

Compute V2: Image reference is hidden Server JSON serialization #1618

Description

@artpej

The Image reference is hidden for the Server JSON serialization:

Image map[string]interface{} `json:"-"`

it could be usefull according I didn't found another way to get the image reference of a running server.

Activity

  1. jtopjian commented on Jun 11, 2019

    @jtopjian
    Contributor

    The image reference is built here:

    switch t := s.Image.(type) {
    case map[string]interface{}:
    r.Image = t
    case string:
    switch t {
    case "":
    r.Image = nil
    }
    }

    I think in newer microversions, the image structure has changed. Try to make sure you are using API version 2.1 without a microversion and see if that helps. If it does, we'll have to look into amending the server result for a newer image format.

  2. artpej commented on Jun 11, 2019

    @artpej
    Author

    Unmarshalling works fine for me, my use case is to serve directly the results through a webservice by re-serialize them in JSON but the custom Mashaller is not present.

  3. jtopjian commented on Jun 11, 2019

    @jtopjian
    Contributor

    You should be able to do something like:

    type MyImage struct {
      Image map[string]interface{} `json:"image"`
    }
    
    var onlyImage MyImage
    
    res := servers.Get(client, "id")
    err := res.ExtractInto(&onlyImage)
  4. artpej commented on Jun 11, 2019

    @artpej
    Author

    Yes, ExtractInto and ̀ExtractServersInto saved me today 😉.

    Is there any plan to also provide Marshaling of result resources?

    Whatever, many thanks @jtopjian for your help.

  5. jtopjian commented on Jun 11, 2019

    @jtopjian
    Contributor

    Not at this time. If you could explain a detailed use-case of why it would be useful, we can leave it here as a feature request.

  6. apuzyrevsky commented on May 21, 2020

    @apuzyrevsky

    Hi @jtopjian ! I've encountered on the same issue as well and I am wondering why did you set an image map to "-" instruct, cause when I changed it to the "image", it works fine. And is there an option to serve service results through the Allpages method with image info as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions