Created
May 11, 2020 15:27
-
-
Save jortel/611c2d49aa75b8a343b8ba9ab14afa0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (p *Provider) Watch() error { | |
pc := property.DefaultCollector(p.client.Client) | |
ospec := types.ObjectSpec{ | |
Obj: p.client.ServiceContent.RootFolder, | |
Skip: types.NewBool(true), | |
SelectSet: []types.BaseSelectionSpec{ | |
&types.TraversalSpec{ | |
SelectionSpec: types.SelectionSpec{ | |
Name: "traverseFolders", | |
}, | |
Type: "Folder", | |
Path: "childEntity", | |
Skip: types.NewBool(true), | |
SelectSet: []types.BaseSelectionSpec{ | |
&types.TraversalSpec{ | |
Type: "HostSystem", | |
Path: "vm", | |
Skip: types.NewBool(false), | |
}, | |
&types.TraversalSpec{ | |
Type: "ComputeResource", | |
Path: "host", | |
Skip: types.NewBool(true), | |
SelectSet: []types.BaseSelectionSpec{ | |
&types.TraversalSpec{ | |
Type: "HostSystem", | |
Path: "vm", | |
Skip: types.NewBool(false), | |
}, | |
}, | |
}, | |
&types.TraversalSpec{ | |
Type: "Datacenter", | |
Path: "hostFolder", | |
Skip: types.NewBool(true), | |
SelectSet: []types.BaseSelectionSpec{ | |
&types.SelectionSpec{ | |
Name: "traverseFolders", | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
} | |
pspec := []types.PropertySpec{ | |
{ | |
Type: VirtualMachine, | |
PathSet: []string{ | |
"summary", | |
}, | |
}, | |
} | |
filter := &property.WaitFilter{ | |
CreateFilter: types.CreateFilter{ | |
This: pc.Reference(), | |
Spec: types.PropertyFilterSpec{ | |
ObjectSet: []types.ObjectSpec{ospec}, | |
PropSet: pspec, | |
}, | |
}, | |
Options: &types.WaitOptions{ | |
MaxWaitSeconds: types.NewInt32(5), | |
MaxObjectUpdates: 100, | |
}, | |
} | |
handler := func(updateSet []types.ObjectUpdate) bool { | |
for _, update := range updateSet { | |
fmt.Println(update) | |
} | |
return false | |
} | |
err := property.WaitForUpdates(p.ctx, pc, filter, handler) | |
if err != nil { | |
fmt.Println(err.Error()) | |
return err | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment