Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmarshal of QueryResultRecordsType for OrgVdcStorageProfileRecord #373

Closed
lelvisl opened this issue May 11, 2021 · 10 comments · Fixed by #499
Closed

Unmarshal of QueryResultRecordsType for OrgVdcStorageProfileRecord #373

lelvisl opened this issue May 11, 2021 · 10 comments · Fixed by #499

Comments

@lelvisl
Copy link
Contributor

lelvisl commented May 11, 2021

Hi!

On struct QueryResultRecordsType you have element OrgVdcStorageProfileRecord with same xml unmarshal tag.
https://github.com/vmware/go-vcloud-director/blob/v2.11.0/types/v56/types.go#L2137

type QueryResultRecordsType struct {
...
	OrgVdcStorageProfileRecord      []*QueryResultOrgVdcStorageProfileRecordType      `xml:"OrgVdcStorageProfileRecord"`      // A record representing storage profiles

But vCloud returns xml element AdminOrgVdcStorageProfileRecord with same content.

In result - i have 1 qty in total with empty OrgVdcStorageProfileRecord

results, err := vCloud.cli[vcloudID].QueryWithNotEncodedParams(nil, map[string]string{
	"type":          "adminOrgVdcStorageProfile",
	"filter":        fmt.Sprintf("id==%s", url.QueryEscape(avdc.AdminVdc.VdcStorageProfiles.VdcStorageProfile[0].ID)),
	"filterEncoded": "true",
})

I want to send PR, but i don't know what you want to do:

  • change unmarshal tag
  • add another Element in struct with name AdminOrgVdcStorageProfileRecord

And i want to add:

  • type for query adminOrgVdcStorageProfile
  • func for querying StorageProfile of ovdc by urn(id)
@lelvisl
Copy link
Contributor Author

lelvisl commented May 11, 2021

@lelvisl
Copy link
Contributor Author

lelvisl commented May 11, 2021

I really hope that we can resolve this issue before 2.12 release.

@lelvisl
Copy link
Contributor Author

lelvisl commented May 11, 2021

With my PR we have working query for adminOrgVdcStorageProfile, but query for orgVdcStorageProfile not working at all on 10.0 and 10.2.2

@Didainius
Copy link
Collaborator

As i understood - it is a different types, which should be implemented both:

Sounds like it - yes. We have a few structures like that. In some cases (when all the fields are the same) we simply link the same struct with multiple tags.
example - https://github.com/vmware/go-vcloud-director/blob/master/types/v56/types.go#L2162-L2163

but query for orgVdcStorageProfile not working at all on 10.0 and 10.2.2

Can you share what error/problem you hit?

@lelvisl
Copy link
Contributor Author

lelvisl commented May 12, 2021

There is no error, just no results - QueryResultRecords with total="0"
I think you can try in your lab this func from PR:

const QtOrgVdcStorageProfile = "orgVdcStorageProfile" // StorageProfile of VDC


func QueryOrgVdcStorageProfileByID(vcdCli *VCDClient, id string) ([]*types.QueryResultOrgVdcStorageProfileRecordType, error) {
 	results, err := vcdCli.QueryWithNotEncodedParams(nil, map[string]string{
 		"type":          types.QtOrgVdcStorageProfile,
 		"filter":        fmt.Sprintf("id==%s", url.QueryEscape(id)),
 		"filterEncoded": "true",
 	})
 	if err != nil {
 		return nil, err
 	}
 	return results.Results.OrgVdcStorageProfileRecord, nil
 }

@lelvisl
Copy link
Contributor Author

lelvisl commented May 12, 2021

@Didainius
Copy link
Collaborator

Are you able to see what query it actually calls inside logs:
You can enable with:

GOVCD_LOG_FILE=go-vcloud-director.log
GOVCD_LOG=true

@lelvisl
Copy link
Contributor Author

lelvisl commented May 12, 2021


2021/05/12 13:08:51 --------------------------------------------------------------------------------
2021/05/12 13:08:51 Request caller: runtime.goexit-->broker.(*VCloud).GetOrgHandler.func1-->govcd.QueryOrgVdcStorageProfileByID-->govcd.(*VCDClient).QueryWithNotEncodedParams-->govcd.(*VCDClient).QueryWithNotEncodedParams-->govcd.(*Client).QueryWithNotEncodedParamsWithApiVersion-->govcd.(*Client).newRequest
2021/05/12 13:08:51 GET https://my-vcd.local.com/api/query?&type=orgVdcStorageProfile&filterEncoded=true&filter=id==urn%3Avcloud%3AvdcstorageProfile%3Afe2109b8-365e-43a1-b685-a1b799d0642f
2021/05/12 13:08:51 --------------------------------------------------------------------------------
2021/05/12 13:08:51 Req header:
2021/05/12 13:08:51 	Accept: [application/*+xml;version=35.0]
2021/05/12 13:08:51 	X-Vmware-Vcloud-Token-Type: [Bearer]
2021/05/12 13:08:51 	Authorization: [********]
2021/05/12 13:08:51 	User-Agent: [my-user-agent]
2021/05/12 13:08:51 	X-Vmware-Vcloud-Access-Token: [********]
2021/05/12 13:08:51 --------------------------------------------------------------------------------
2021/05/12 13:08:51 Request caller: runtime.goexit-->broker.(*VCloud).GetOrgHandler.func1-->govcd.QueryOrgVdcStorageProfileByID-->govcd.(*VCDClient).QueryWithNotEncodedParams-->govcd.(*VCDClient).QueryWithNotEncodedParams-->govcd.(*Client).QueryWithNotEncodedParamsWithApiVersion-->govcd.(*Client).newRequest
2021/05/12 13:08:51 GET https://my-vcd.local.com/api/query?&type=orgVdcStorageProfile&filterEncoded=true&filter=id==urn%3Avcloud%3AvdcstorageProfile%3Abb9aa3e8-1e6d-4e1b-b90c-6bbd8e62ad4b
2021/05/12 13:08:51 --------------------------------------------------------------------------------
2021/05/12 13:08:51 Req header:
2021/05/12 13:08:51 	Accept: [application/*+xml;version=35.0]
2021/05/12 13:08:51 	X-Vmware-Vcloud-Token-Type: [Bearer]
2021/05/12 13:08:51 	Authorization: [********]
2021/05/12 13:08:51 	User-Agent: [my-user-agent]
2021/05/12 13:08:51 	X-Vmware-Vcloud-Access-Token: [********]
2021/05/12 13:08:51 ################################################################################
2021/05/12 13:08:51 Response caller runtime.goexit-->broker.(*VCloud).GetOrgHandler.func1-->govcd.QueryOrgVdcStorageProfileByID-->govcd.(*VCDClient).QueryWithNotEncodedParams-->govcd.(*VCDClient).QueryWithNotEncodedParams-->govcd.(*Client).QueryWithNotEncodedParamsWithApiVersion-->govcd.getResult-->govcd.decodeBody
2021/05/12 13:08:51 Response status 200 OK
2021/05/12 13:08:51 ################################################################################
2021/05/12 13:08:51 Response header:
2021/05/12 13:08:51 	Content-Length: [2140]
2021/05/12 13:08:51 	Date: [Wed, 12 May 2021 10:08:51 GMT]
2021/05/12 13:08:51 	X-Vmware-Vcloud-Request-Id: [ebf95f5f-978f-430a-b282-a426c15b5725]
2021/05/12 13:08:51 	X-Vmware-Vcloud-Ceip-Id: [c10067cb-6b7e-43e2-98f0-021168a2c34e]
2021/05/12 13:08:51 	Content-Type: [application/vnd.vmware.vcloud.query.records+xml;version=35.0]
2021/05/12 13:08:51 	X-Vmware-Vcloud-Request-Execution-Time: [62]
2021/05/12 13:08:51 	Cache-Control: [no-store, must-revalidate]
2021/05/12 13:08:51 	Vary: [Accept-Encoding, User-Agent]
2021/05/12 13:08:51 Response text: [2140]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<QueryResultRecords xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1" xmlns:ns9="http://www.vmware.com/vcloud/versions" name="orgVdcStorageProfile" page="1" pageSize="25" total="0" href="https://my-vcd.local.com/api/query?type=orgVdcStorageProfile&amp;page=1&amp;pageSize=25&amp;format=records&amp;filter=id==urn%3Avcloud%3AvdcstorageProfile%3Abb9aa3e8-1e6d-4e1b-b90c-6bbd8e62ad4b" type="application/vnd.vmware.vcloud.query.records+xml">
    <Link rel="alternate" href="https://my-vcd.local.com/api/query?type=orgVdcStorageProfile&amp;page=1&amp;pageSize=25&amp;format=references&amp;filter=id==urn%3Avcloud%3AvdcstorageProfile%3Abb9aa3e8-1e6d-4e1b-b90c-6bbd8e62ad4b" type="application/vnd.vmware.vcloud.query.references+xml"/>
    <Link rel="alternate" href="https://my-vcd.local.com/api/query?type=orgVdcStorageProfile&amp;page=1&amp;pageSize=25&amp;format=references&amp;filter=id==urn%3Avcloud%3AvdcstorageProfile%3Abb9aa3e8-1e6d-4e1b-b90c-6bbd8e62ad4b" type="application/vnd.vmware.vcloud.query.references+json"/>
    <Link rel="alternate" href="https://my-vcd.local.com/api/query?type=orgVdcStorageProfile&amp;page=1&amp;pageSize=25&amp;format=idrecords&amp;filter=id==urn%3Avcloud%3AvdcstorageProfile%3Abb9aa3e8-1e6d-4e1b-b90c-6bbd8e62ad4b" type="application/vnd.vmware.vcloud.query.idrecords+xml"/>
    <Link rel="alternate" href="https://my-vcd.local.com/api/query?type=orgVdcStorageProfile&amp;page=1&amp;pageSize=25&amp;format=idrecords&amp;filter=id==urn%3Avcloud%3AvdcstorageProfile%3Abb9aa3e8-1e6d-4e1b-b90c-6bbd8e62ad4b" type="application/vnd.vmware.vcloud.query.idrecords+json"/>
</QueryResultRecords>

2021/05/12 13:08:51 ################################################################################
2021/05/12 13:08:51 Response caller runtime.goexit-->broker.(*VCloud).GetOrgHandler.func1-->govcd.QueryOrgVdcStorageProfileByID-->govcd.(*VCDClient).QueryWithNotEncodedParams-->govcd.(*VCDClient).QueryWithNotEncodedParams-->govcd.(*Client).QueryWithNotEncodedParamsWithApiVersion-->govcd.getResult-->govcd.decodeBody
2021/05/12 13:08:51 Response status 200 OK
2021/05/12 13:08:51 ################################################################################
2021/05/12 13:08:51 Response header:
2021/05/12 13:08:51 	X-Vmware-Vcloud-Request-Execution-Time: [68]
2021/05/12 13:08:51 	Cache-Control: [no-store, must-revalidate]
2021/05/12 13:08:51 	Vary: [Accept-Encoding, User-Agent]
2021/05/12 13:08:51 	Content-Length: [2140]
2021/05/12 13:08:51 	Date: [Wed, 12 May 2021 10:08:51 GMT]
2021/05/12 13:08:51 	X-Vmware-Vcloud-Request-Id: [b9720a50-9109-4dfc-9add-5c8c0398b3e4]
2021/05/12 13:08:51 	X-Vmware-Vcloud-Ceip-Id: [c10067cb-6b7e-43e2-98f0-021168a2c34e]
2021/05/12 13:08:51 	Content-Type: [application/vnd.vmware.vcloud.query.records+xml;version=35.0]
2021/05/12 13:08:51 Response text: [2140]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<QueryResultRecords xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1" xmlns:ns9="http://www.vmware.com/vcloud/versions" name="orgVdcStorageProfile" page="1" pageSize="25" total="0" href="https://my-vcd.local.com/api/query?type=orgVdcStorageProfile&amp;page=1&amp;pageSize=25&amp;format=records&amp;filter=id==urn%3Avcloud%3AvdcstorageProfile%3Afe2109b8-365e-43a1-b685-a1b799d0642f" type="application/vnd.vmware.vcloud.query.records+xml">
    <Link rel="alternate" href="https://my-vcd.local.com/api/query?type=orgVdcStorageProfile&amp;page=1&amp;pageSize=25&amp;format=references&amp;filter=id==urn%3Avcloud%3AvdcstorageProfile%3Afe2109b8-365e-43a1-b685-a1b799d0642f" type="application/vnd.vmware.vcloud.query.references+xml"/>
    <Link rel="alternate" href="https://my-vcd.local.com/api/query?type=orgVdcStorageProfile&amp;page=1&amp;pageSize=25&amp;format=references&amp;filter=id==urn%3Avcloud%3AvdcstorageProfile%3Afe2109b8-365e-43a1-b685-a1b799d0642f" type="application/vnd.vmware.vcloud.query.references+json"/>
    <Link rel="alternate" href="https://my-vcd.local.com/api/query?type=orgVdcStorageProfile&amp;page=1&amp;pageSize=25&amp;format=idrecords&amp;filter=id==urn%3Avcloud%3AvdcstorageProfile%3Afe2109b8-365e-43a1-b685-a1b799d0642f" type="application/vnd.vmware.vcloud.query.idrecords+xml"/>
    <Link rel="alternate" href="https://my-vcd.local.com/api/query?type=orgVdcStorageProfile&amp;page=1&amp;pageSize=25&amp;format=idrecords&amp;filter=id==urn%3Avcloud%3AvdcstorageProfile%3Afe2109b8-365e-43a1-b685-a1b799d0642f" type="application/vnd.vmware.vcloud.query.idrecords+json"/>
</QueryResultRecords>

@lelvisl
Copy link
Contributor Author

lelvisl commented May 12, 2021

Querying with same id and type 'adminOrgVdcStorageProfile' working well.

@lelvisl
Copy link
Contributor Author

lelvisl commented May 13, 2021

I understood - as provider admin i cant query non admin objects without X-VMWARE-VCLOUD-TENANT-CONTEXT header and tenant id in value.

And, you already have constant for this header - https://github.com/vmware/go-vcloud-director/blob/v2.11.0/types/v56/constants.go#L350

In result - code in my PR working well, i will open another issue for adding support of X-VMWARE-VCLOUD-TENANT-CONTEXT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants