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

Support for JSON #3007

Merged
merged 7 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/govmomi-go-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
boilerplate-check check \
--boilerplate ./hack/boilerplate/boilerplate.${{ matrix.extension }}.txt \
--file-extension ${{ matrix.extension }} \
--exclude "(vendor|third_party|dist)/" |
--exclude "((vim25/json)|vendor|third_party|dist)/" |
reviewdog -efm="%A%f:%l: %m" \
-efm="%C%.%#" \
-name="${{ matrix.language }} headers" \
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ linters-settings:
run:
timeout: 6m
skip-dirs:
- vim25/json
- vim25/xml
- cns/types
356 changes: 178 additions & 178 deletions eam/types/types.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions gen/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sdk/
rbvmomi/
51 changes: 41 additions & 10 deletions gen/vim_wsdl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,25 +232,29 @@ def var_type
if pointer_type?
prefix += "*"
self.need_omitempty = false
self.json_omitempty = true
end
t = "int32"
when "boolean"
t = "bool"
if !slice? && optional?
prefix += "*"
self.need_omitempty = false
self.json_omitempty = true
end
when "long"
if pointer_type?
prefix += "*"
self.need_omitempty = false
self.json_omitempty = true
end
t = "int64"
when "dateTime"
t = "time.Time"
if !slice? && optional?
prefix += "*"
self.need_omitempty = false
self.json_omitempty = true
end
when "anyType"
pkg = ""
Expand Down Expand Up @@ -306,6 +310,10 @@ def need_omitempty=(v)
@need_omitempty = v
end

def json_omitempty=(v)
@json_omitempty = v
end

def need_omitempty?
var_type # HACK: trigger setting need_omitempty if necessary
if @need_omitempty.nil?
Expand All @@ -315,6 +323,15 @@ def need_omitempty?
end
end

def json_omitempty?
var_type # HACK: trigger setting json_omitempty if necessary
if @json_omitempty.nil?
@json_omitempty = need_omitempty?
else
@json_omitempty
end
end

def need_typeattr?
base_type? || any_type?
end
Expand Down Expand Up @@ -370,10 +387,16 @@ def dump_init(io)
end

def dump_field(io)
tag = name
tag += ",omitempty" if need_omitempty?
tag += ",typeattr" if need_typeattr?
io.print "%s %s `xml:\"%s\"`\n" % [var_name, var_type, tag]
xmlTag = name
xmlTag += ",omitempty" if need_omitempty?
xmlTag += ",typeattr" if need_typeattr?
tag = "%s %s `xml:\"%s\"" % [var_name, var_type, xmlTag]

jsonTag = name
jsonTag += ",omitempty" if json_omitempty?
tag += " json:\"%s\"" % [jsonTag]

io.print "%s`\n" % [tag]
end

def peek(type=nil)
Expand All @@ -389,10 +412,17 @@ def peek(type=nil)

class Attribute < Simple
def dump_field(io)
tag = name
tag += ",omitempty" if need_omitempty?
tag += ",attr"
io.print "%s %s `xml:\"%s\"`\n" % [var_name, var_type, tag]
xmlTag = name
xmlTag += ",omitempty" if need_omitempty?
xmlTag += ",attr"
xmlTag += ",typeattr" if need_typeattr?
tag = "%s %s `xml:\"%s\"" % [var_name, var_type, xmlTag]

jsonTag = name
jsonTag += ",omitempty" if json_omitempty?
tag += " json:\"%s\"" % [jsonTag]

io.print "%s`\n" % [tag]
end
end

Expand Down Expand Up @@ -430,7 +460,7 @@ def dump(io)
# HACK DELUXE(PN)
extension = @node.at_xpath(".//xsd:extension")
type = extension["base"].split(":", 2)[1]
io.print "Value %s `xml:\",chardata\"`\n" % type
io.print "Value %s `xml:\",chardata\" json:\"value\"`\n" % type
end

def peek
Expand Down Expand Up @@ -541,7 +571,8 @@ def dump_init(io)
end

def dump(io)
io.print "type %s struct {\n" % ucfirst(name)
ucfirstName = ucfirst(name)
io.print "type %s struct {\n" % ucfirstName
klass.dump(io) if klass
io.print "}\n\n"
end
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
)

require (
github.com/google/go-cmp v0.5.7 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/a8m/tree v0.0.0-20210115125333-10a5fd5b637d/go.mod h1:FSdwKX97koS5efg
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/dougm/pretty v0.0.0-20171025230240-2ee9d7453c02 h1:tR3jsKPiO/mb6ntzk/dJlHZtm37CPfVp1C9KIo534+4=
github.com/dougm/pretty v0.0.0-20171025230240-2ee9d7453c02/go.mod h1:7NQ3kWOx2cZOSjtcveTa5nqupVr2s6/83sG+rTlI7uA=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand All @@ -18,5 +20,6 @@ github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBO
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728 h1:sH9mEk+flyDxiUa5BuPiuhDETMbzrt9A20I2wktMvRQ=
github.com/vmware/vmw-guestinfo v0.0.0-20170707015358-25eff159a728/go.mod h1:x9oS4Wk2s2u4tS29nEaDLdzvuHdB19CvSGJjPgkZJNk=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
14 changes: 7 additions & 7 deletions govc/test/cluster.bats
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ _EOF_
assert_failure # no changes specified

# DRS override
query=".Overrides[] | select(.Name == \"DC0_C0_RP0_VM0\") | .DRS.Enabled"
query=".Overrides[] | select(.Name == \"DC0_C0_RP0_VM0\") | .DRS.enabled"

run govc cluster.override.change -vm DC0_C0_RP0_VM0 -drs-enabled=false
assert_success
Expand All @@ -211,7 +211,7 @@ _EOF_
assert_success

# DAS override
query=".Overrides[] | select(.Name == \"DC0_C0_RP0_VM0\") | .DAS.DasSettings.RestartPriority"
query=".Overrides[] | select(.Name == \"DC0_C0_RP0_VM0\") | .DAS.dasSettings.restartPriority"

[ "$(govc cluster.override.info -json | jq -r "$query")" != "high" ]

Expand All @@ -220,13 +220,13 @@ _EOF_
[ "$(govc cluster.override.info -json | jq -r "$query")" == "high" ]

# Orchestration override
query=".Overrides[] | select(.Name == \"DC0_C0_RP0_VM0\") | .Orchestration.VmReadiness.PostReadyDelay"
query=".Overrides[] | select(.Name == \"DC0_C0_RP0_VM0\") | .Orchestration.vmReadiness.postReadyDelay"

run govc cluster.override.change -vm DC0_C0_RP0_VM0 -ha-additional-delay 60
assert_success
[ "$(govc cluster.override.info -json | jq -r "$query")" == "60" ]

query=".Overrides[] | select(.Name == \"DC0_C0_RP0_VM0\") | .Orchestration.VmReadiness.ReadyCondition"
query=".Overrides[] | select(.Name == \"DC0_C0_RP0_VM0\") | .Orchestration.vmReadiness.readyCondition"

run govc cluster.override.change -vm DC0_C0_RP0_VM0 -ha-ready-condition poweredOn
assert_success
Expand All @@ -243,16 +243,16 @@ _EOF_
vcsim_env
unset GOVC_HOST

ip=$(govc object.collect -o -json host/DC0_C0/DC0_C0_H0 | jq -r .Config.Network.Vnic[].Spec.Ip.IpAddress)
ip=$(govc object.collect -o -json host/DC0_C0/DC0_C0_H0 | jq -r .Config.network.vnic[].spec.ip.ipAddress)
assert_equal 127.0.0.1 "$ip"

govc cluster.add -cluster DC0_C0 -hostname 10.0.0.42 -username user -password pass
assert_success

ip=$(govc object.collect -o -json host/DC0_C0/10.0.0.42 | jq -r .Config.Network.Vnic[].Spec.Ip.IpAddress)
ip=$(govc object.collect -o -json host/DC0_C0/10.0.0.42 | jq -r .Config.network.vnic[].spec.ip.ipAddress)

assert_equal 10.0.0.42 "$ip"
govc host.info -json '*' | jq -r .HostSystems[].Config.Network.Vnic[].Spec.Ip
govc host.info -json '*' | jq -r .HostSystems[].Config.network.vnic[].spec.ip
name=$(govc host.info -json -host.ip 10.0.0.42 | jq -r .HostSystems[].Name)
assert_equal 10.0.0.42 "$name"
}
Expand Down
2 changes: 1 addition & 1 deletion govc/test/disk.bats
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ load test_helper
run govc disk.ls
assert_success

path=$(govc disk.ls -json "$id" | jq -r .Objects[].Config.Backing.FilePath)
path=$(govc disk.ls -json "$id" | jq -r .Objects[].config.backing.filePath)
run govc datastore.rm "$path"
assert_success

Expand Down
4 changes: 2 additions & 2 deletions govc/test/fields.bats
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ load test_helper

info=$(govc vm.info -json $vm_id | jq .VirtualMachines[0].CustomValue[0])

ikey=$(jq -r .Key <<<"$info")
ikey=$(jq -r .key <<<"$info")
assert_equal $key $ikey

ival=$(jq -r .Value <<<"$info")
ival=$(jq -r .value <<<"$info")
assert_equal $val $ival

old_field=$field
Expand Down
2 changes: 1 addition & 1 deletion govc/test/host.bats
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ load test_helper
run govc host.info -host.dns $(basename "$name")
assert_failure # TODO: SearchIndex:SearchIndex does not implement: FindByDnsName

uuid=$(govc host.info -host "$name" -json | jq -r .HostSystems[].Summary.Hardware.Uuid)
uuid=$(govc host.info -host "$name" -json | jq -r .HostSystems[].Summary.hardware.uuid)
run govc host.info -host.uuid "$uuid"
assert_success

Expand Down
2 changes: 1 addition & 1 deletion govc/test/import.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ load test_helper
assert_success

# link ovf/ova to datastore so we can test with an http source
dir=$(govc datastore.info -json | jq -r .Datastores[].Info.Url)
dir=$(govc datastore.info -json | jq -r .Datastores[].Info.url)
ln -s "$GOVC_IMAGES/$TTYLINUX_NAME."* "$dir"

run govc import.spec "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ovf"
Expand Down
2 changes: 1 addition & 1 deletion govc/test/library.bats
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ load test_helper
library_id="$output"

# link ovf/ova to datastore so we can test library.import with an http source
dir=$(govc datastore.info -json | jq -r .Datastores[].Info.Url)
dir=$(govc datastore.info -json | jq -r .Datastores[].Info.url)
ln -s "$GOVC_IMAGES/$TTYLINUX_NAME."* "$dir"

run govc library.import -pull my-content "https://$(govc env GOVC_URL)/folder/$TTYLINUX_NAME.ovf"
Expand Down
8 changes: 4 additions & 4 deletions govc/test/license.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ verify_evaluation() {
}

get_key() {
jq ".[] | select(.LicenseKey == \"$1\")"
jq ".[] | select(.licenseKey == \"$1\")"
}

get_property() {
jq -r ".Properties[] | select(.Key == \"$1\") | .Value"
jq -r ".properties[] | select(.key == \"$1\") | .value"
}

get_label() {
govc license.ls -json | jq -r ".[] | select(.LicenseKey == \"$1\") | .Labels[] | select(.Key == \"$2\") | .Value"
govc license.ls -json | jq -r ".[] | select(.licenseKey == \"$1\") | .labels[] | select(.key == \"$2\") | .value"
}

get_nlabel() {
govc license.ls -json | jq ".[] | select(.LicenseKey == \"$1\") | .Labels[].Key" | wc -l
govc license.ls -json | jq ".[] | select(.licenseKey == \"$1\") | .labels[].key" | wc -l
}

@test "license.add" {
Expand Down
6 changes: 3 additions & 3 deletions govc/test/network.bats
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ load test_helper
assert_equal "VirtualE1000e" $(collapse_ws $type)

# validate each NIC has a unique MAC
macs=$(govc device.info -vm "$vm" -json ethernet-* | jq -r .Devices[].MacAddress | uniq | wc -l)
macs=$(govc device.info -vm "$vm" -json ethernet-* | jq -r .Devices[].macAddress | uniq | wc -l)
assert_equal 2 "$macs"
}

Expand Down Expand Up @@ -222,10 +222,10 @@ load test_helper
info=$(govc dvs.portgroup.info "$id" | grep VlanId: | uniq | grep 3123)
[ -n "$info" ]

info=$(govc dvs.portgroup.info -json "$id" | jq '.Port[].Config.Setting.Vlan | select(.VlanId == 3123)')
info=$(govc dvs.portgroup.info -json "$id" | jq '.Port[].config.setting.vlan | select(.vlanId == 3123)')
[ -n "$info" ]

info=$(govc dvs.portgroup.info -json "$id" | jq '.Port[].Config.Setting.Vlan | select(.VlanId == 7777)')
info=$(govc dvs.portgroup.info -json "$id" | jq '.Port[].config.setting.Vlan | select(.vlanId == 7777)')
[ -z "$info" ]

run govc object.destroy "network/${id}-ExternalNetwork" "network/${id}-InternalNetwork" "network/${id}"
Expand Down
4 changes: 2 additions & 2 deletions govc/test/session.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ load test_helper
assert_failure # NotFound

# Can't remove the current session
id=$(govc session.ls -json | jq -r .CurrentSession.Key)
id=$(govc session.ls -json | jq -r .CurrentSession.key)
run govc session.rm "$id"
assert_failure

thumbprint=$(govc about.cert -thumbprint)
id=$(govc session.ls -json -k=false -tls-known-hosts <(echo "$thumbprint") | jq -r .CurrentSession.Key)
id=$(govc session.ls -json -k=false -tls-known-hosts <(echo "$thumbprint") | jq -r .CurrentSession.key)

rm -rf "$dir"

Expand Down
4 changes: 2 additions & 2 deletions govc/test/vcsim.bats
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ EOF
run govc object.collect -s $vm summary.guest.ipAddress
assert_success "10.0.0.1"

netip=$(govc object.collect -json -s $vm guest.net | jq -r .[].Val.GuestNicInfo[].IpAddress[0])
netip=$(govc object.collect -json -s $vm guest.net | jq -r .[].val.GuestNicInfo[].ipAddress[0])
[ "$netip" = "10.0.0.1" ]

run govc vm.info -vm.ip 10.0.0.1
Expand Down Expand Up @@ -264,7 +264,7 @@ EOF
run govc object.collect -s vm/$vm summary.guest.ipAddress
assert_success "$ip"

netip=$(govc object.collect -json -s vm/$vm guest.net | jq -r .[].Val.GuestNicInfo[].IpAddress[0])
netip=$(govc object.collect -json -s vm/$vm guest.net | jq -r .[].val.GuestNicInfo[].ipAddress[0])
[ "$netip" = "$ip" ]

run govc vm.power -s $vm
Expand Down
Loading