當前位置: 首頁>>代碼示例>>Golang>>正文


Golang property.DefaultCollector函數代碼示例

本文整理匯總了Golang中github.com/vmware/govmomi/property.DefaultCollector函數的典型用法代碼示例。如果您正苦於以下問題:Golang DefaultCollector函數的具體用法?Golang DefaultCollector怎麽用?Golang DefaultCollector使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了DefaultCollector函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: run

func (p *eventProcessor) run(ctx context.Context, tail bool) error {
    if len(p.tailers) == 0 {
        return nil
    }

    var err error
    var collectors []types.ManagedObjectReference
    for _, t := range p.tailers {
        collectors = append(collectors, t.collector)
    }

    if len(p.tailers) > 1 {
        // create and populate a ListView
        viewMgr := view.NewManager(p.mgr.Client())
        var listView *view.ListView
        listView, err = viewMgr.CreateListView(ctx, collectors)
        if err != nil {
            return err
        }

        count := 0
        // Retrieve the property from the objects in the ListView
        err = property.WaitForView(ctx, property.DefaultCollector(p.mgr.Client()), listView.Reference(), collectors[0], []string{latestPageProp}, func(c types.ManagedObjectReference, pc []types.PropertyChange) bool {
            if err = p.process(c, pc); err != nil {
                return false
            }

            count++
            if count == len(collectors) && !tail {
                return true
            }

            return false
        })

        return err
    }

    // only one object to follow
    err = property.Wait(ctx, property.DefaultCollector(p.mgr.Client()), collectors[0], []string{latestPageProp}, func(pc []types.PropertyChange) bool {
        if err = p.process(collectors[0], pc); err != nil {
            return false
        }

        if !tail {
            return true
        }

        return false
    })

    return err
}
開發者ID:vmware,項目名稱:vic,代碼行數:53,代碼來源:processor.go

示例2: DetachDisk

func (cmd *vmdk) DetachDisk(vm *object.VirtualMachine) (string, error) {
    ctx := context.TODO()
    var mvm mo.VirtualMachine

    pc := property.DefaultCollector(cmd.Client)
    err := pc.RetrieveOne(ctx, vm.Reference(), []string{"config.hardware"}, &mvm)
    if err != nil {
        return "", err
    }

    spec := new(configSpec)
    dsFile := spec.RemoveDisk(&mvm)

    task, err := vm.Reconfigure(ctx, spec.ToSpec())
    if err != nil {
        return "", err
    }

    err = task.Wait(ctx)
    if err != nil {
        return "", err
    }

    return dsFile, nil
}
開發者ID:vmware,項目名稱:vic,代碼行數:25,代碼來源:vmdk.go

示例3: Run

func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
    client, err := cmd.Client()
    if err != nil {
        return err
    }

    ns, err := cmd.HostNetworkSystem()
    if err != nil {
        return err
    }

    var mns mo.HostNetworkSystem

    pc := property.DefaultCollector(client)
    err = pc.RetrieveOne(context.TODO(), ns.Reference(), []string{"networkInfo.vswitch"}, &mns)
    if err != nil {
        return err
    }

    tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)

    for i, s := range mns.NetworkInfo.Vswitch {
        if i > 0 {
            fmt.Fprintln(tw)
        }
        fmt.Fprintf(tw, "Name:\t%s\n", s.Name)
        fmt.Fprintf(tw, "Portgroup:\t%s\n", cmd.keys("key-vim.host.PortGroup-", s.Portgroup))
        fmt.Fprintf(tw, "Pnic:\t%s\n", cmd.keys("key-vim.host.PhysicalNic-", s.Pnic))
        fmt.Fprintf(tw, "MTU:\t%d\n", s.Mtu)
        fmt.Fprintf(tw, "Ports:\t%d\n", s.NumPorts)
        fmt.Fprintf(tw, "Ports Available:\t%d\n", s.NumPortsAvailable)
    }

    return tw.Flush()
}
開發者ID:jak-atx,項目名稱:vic,代碼行數:35,代碼來源:info.go

示例4: LocalDatastores

func (h *Helper) LocalDatastores(ctx context.Context, cr *object.ComputeResource) ([]*object.Datastore, error) {
    // List datastores for compute resource
    dss, err := cr.Datastores(ctx)
    if err != nil {
        return nil, err
    }

    // Filter local datastores
    var ldss []*object.Datastore
    for _, ds := range dss {
        var mds mo.Datastore
        err = property.DefaultCollector(h.c).RetrieveOne(ctx, ds.Reference(), nil, &mds)
        if err != nil {
            return nil, err
        }

        switch i := mds.Info.(type) {
        case *types.VmfsDatastoreInfo:
            if i.Vmfs.Local != nil && *i.Vmfs.Local == true {
                break
            }
        default:
            continue
        }

        ds.InventoryPath = mds.Name
        ldss = append(ldss, ds)
    }

    return ldss, nil
}
開發者ID:vmware,項目名稱:vic,代碼行數:31,代碼來源:helper.go

示例5: Hosts

func (c ComputeResource) Hosts(ctx context.Context) ([]*HostSystem, error) {
    var cr mo.ComputeResource

    err := c.Properties(ctx, c.Reference(), []string{"host"}, &cr)
    if err != nil {
        return nil, err
    }

    if len(cr.Host) == 0 {
        return nil, nil
    }

    var hs []mo.HostSystem
    pc := property.DefaultCollector(c.Client())
    err = pc.Retrieve(ctx, cr.Host, []string{"name"}, &hs)
    if err != nil {
        return nil, err
    }

    var hosts []*HostSystem

    for _, h := range hs {
        host := NewHostSystem(c.Client(), h.Reference())
        host.InventoryPath = path.Join(c.InventoryPath, h.Name)
        hosts = append(hosts, host)
    }

    return hosts, nil
}
開發者ID:vmware,項目名稱:vic,代碼行數:29,代碼來源:compute_resource.go

示例6: waitForNetworkingActive

func waitForNetworkingActive(client *govmomi.Client, datacenter, name string) resource.StateRefreshFunc {
    return func() (interface{}, string, error) {
        dc, err := getDatacenter(client, datacenter)
        if err != nil {
            log.Printf("[ERROR] %#v", err)
            return nil, "", err
        }
        finder := find.NewFinder(client.Client, true)
        finder = finder.SetDatacenter(dc)

        vm, err := finder.VirtualMachine(context.TODO(), name)
        if err != nil {
            log.Printf("[ERROR] %#v", err)
            return nil, "", err
        }

        var mvm mo.VirtualMachine
        collector := property.DefaultCollector(client.Client)
        if err := collector.RetrieveOne(context.TODO(), vm.Reference(), []string{"summary"}, &mvm); err != nil {
            log.Printf("[ERROR] %#v", err)
            return nil, "", err
        }

        if mvm.Summary.Guest.IpAddress != "" {
            log.Printf("[DEBUG] IP address with DHCP: %v", mvm.Summary.Guest.IpAddress)
            return mvm.Summary, "active", err
        } else {
            log.Printf("[DEBUG] Waiting for IP address")
            return nil, "pending", err
        }
    }
}
開發者ID:mafrosis,項目名稱:terraform,代碼行數:32,代碼來源:resource_vsphere_virtual_machine.go

示例7: WaitForIP

func (v VirtualMachine) WaitForIP(ctx context.Context) (string, error) {
    var ip string

    p := property.DefaultCollector(v.c)
    err := property.Wait(ctx, p, v.Reference(), []string{"guest.ipAddress"}, func(pc []types.PropertyChange) bool {
        for _, c := range pc {
            if c.Name != "guest.ipAddress" {
                continue
            }
            if c.Op != types.PropertyChangeOpAssign {
                continue
            }
            if c.Val == nil {
                continue
            }

            ip = c.Val.(string)
            return true
        }

        return false
    })

    if err != nil {
        return "", err
    }

    return ip, nil
}
開發者ID:higebu,項目名稱:terraform,代碼行數:29,代碼來源:virtual_machine.go

示例8: IpAddress

// IpAddress attempts to find the guest IP address using esxcli.
// ESX hosts must be configured with the /Net/GuestIPHack enabled.
// For example:
// $ govc host.esxcli -- system settings advanced set -o /Net/GuestIPHack -i 1
func (g *GuestInfo) IpAddress(vm *object.VirtualMachine) (string, error) {
    const any = "0.0.0.0"
    var mvm mo.VirtualMachine

    pc := property.DefaultCollector(g.c)
    err := pc.RetrieveOne(context.TODO(), vm.Reference(), []string{"runtime.host", "config.uuid"}, &mvm)
    if err != nil {
        return "", err
    }

    h, err := g.hostInfo(mvm.Runtime.Host)
    if err != nil {
        return "", err
    }

    // Normalize uuid, esxcli and mo.VirtualMachine have different formats
    uuid := strings.Replace(mvm.Config.Uuid, "-", "", -1)

    if wid, ok := h.wids[uuid]; ok {
        res, err := h.Run([]string{"network", "vm", "port", "list", "--world-id", wid})
        if err != nil {
            return "", err
        }

        for _, val := range res.Values {
            if ip, ok := val["IPAddress"]; ok {
                if ip[0] != any {
                    return ip[0], nil
                }
            }
        }
    }

    return any, nil
}
開發者ID:hmahmood,項目名稱:govmomi,代碼行數:39,代碼來源:guest_info.go

示例9: WaitForMAC

// WaitForMac will wait until VM get mac for all attached nics.
// Returns map "Virtual Network Name": "nic MAC address"
func (vm VirtualMachine) WaitForMAC(ctx context.Context) (map[string]string, error) {
    devices, err := vm.Device(ctx)
    if err != nil {
        log.Errorf("Unable to get device listing for VM")
        return nil, err
    }

    nics := devices.SelectByType(&types.VirtualEthernetCard{})
    macs := make(map[string]string)
    // device name:network name
    nicMappings := make(map[string]string)
    for _, nic := range nics {
        if n, ok := nic.(types.BaseVirtualEthernetCard); ok {
            netName, err := vm.getNetworkName(ctx, n)
            if err != nil {
                log.Errorf("failed to get network name: %s", err)
                return nil, err
            }
            macs[netName] = ""

            nicMappings[devices.Name(nic)] = netName
        } else {
            log.Errorf("Failed to get network name of vNIC: %v", nic)
            return nil, err
        }
    }

    p := property.DefaultCollector(vm.Session.Vim25())

    // Wait for all NICs to have a MacAddress, which may not be generated yet.
    err = property.Wait(ctx, p, vm.Reference(), []string{"config.hardware.device"}, func(pc []types.PropertyChange) bool {
        for _, c := range pc {
            if c.Op != types.PropertyChangeOpAssign {
                continue
            }

            changedDevices := c.Val.(types.ArrayOfVirtualDevice).VirtualDevice
            for _, device := range changedDevices {
                if nic, ok := device.(types.BaseVirtualEthernetCard); ok {
                    mac := nic.GetVirtualEthernetCard().MacAddress
                    if mac == "" {
                        continue
                    }
                    netName := nicMappings[devices.Name(device)]
                    macs[netName] = mac
                }
            }
        }
        for key, value := range macs {
            if value == "" {
                log.Debugf("Didn't get mac address for nic on %s, continue", key)
                return false
            }
        }
        return true
    })
    return macs, err
}
開發者ID:kjplatz,項目名稱:vic,代碼行數:60,代碼來源:vm.go

示例10: TestWaitForUpdates

func TestWaitForUpdates(t *testing.T) {
    folder := esx.RootFolder
    s := New(NewServiceInstance(esx.ServiceContent, folder))

    ts := s.NewServer()
    defer ts.Close()

    ctx := context.Background()

    c, err := govmomi.NewClient(ctx, ts.URL, true)
    if err != nil {
        t.Fatal(err)
    }

    cb := func(once bool) func([]types.PropertyChange) bool {
        return func(pc []types.PropertyChange) bool {
            if len(pc) != 1 {
                t.Fail()
            }

            c := pc[0]
            if c.Op != types.PropertyChangeOpAssign {
                t.Fail()
            }
            if c.Name != "name" {
                t.Fail()
            }
            if c.Val.(string) != folder.Name {
                t.Fail()
            }

            return once
        }
    }

    pc := property.DefaultCollector(c.Client)
    props := []string{"name"}

    err = property.Wait(ctx, pc, folder.Reference(), props, cb(true))
    if err != nil {
        t.Error(err)
    }

    // incremental updates not yet suppported
    err = property.Wait(ctx, pc, folder.Reference(), props, cb(false))
    if err == nil {
        t.Error("expected error")
    }

    // test object not found
    Map.Remove(folder.Reference())

    err = property.Wait(ctx, pc, folder.Reference(), props, cb(true))
    if err == nil {
        t.Error("expected error")
    }
}
開發者ID:jak-atx,項目名稱:vic,代碼行數:57,代碼來源:property_collector_test.go

示例11: Run

func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
    c, err := cmd.Client()
    if err != nil {
        return err
    }

    finder, err := cmd.Finder()
    if err != nil {
        return err
    }

    args := f.Args()
    if len(args) == 0 {
        args = []string{"*"}
    }

    var props []string
    res := infoResult{
        finder: finder,
        ctx:    ctx,
    }

    if !cmd.OutputFlag.JSON {
        props = []string{
            "name",
            "vmFolder",
            "hostFolder",
            "datastoreFolder",
            "networkFolder",
            "datastore",
            "network",
        }
    }

    for _, arg := range args {
        objects, err := finder.DatacenterList(ctx, arg)
        if err != nil {
            return err
        }
        res.objects = append(res.objects, objects...)
    }

    if len(res.objects) != 0 {
        refs := make([]types.ManagedObjectReference, 0, len(res.objects))
        for _, o := range res.objects {
            refs = append(refs, o.Reference())
        }

        pc := property.DefaultCollector(c)
        err = pc.Retrieve(ctx, refs, props, &res.Datacenters)
        if err != nil {
            return err
        }
    }

    return cmd.WriteResult(&res)
}
開發者ID:vmware,項目名稱:vic,代碼行數:57,代碼來源:info.go

示例12: getVirtualMachineManagedObjectReference

func getVirtualMachineManagedObjectReference(ctx context.Context, c *govmomi.Client, vm *object.VirtualMachine, field string, dst interface{}) error {
    collector := property.DefaultCollector(c.Client)

    // Retrieve required field from VM object
    err := collector.RetrieveOne(ctx, vm.Reference(), []string{field}, dst)
    if err != nil {
        return err
    }
    return nil
}
開發者ID:ncdc,項目名稱:kubernetes,代碼行數:10,代碼來源:vsphere.go

示例13: List

func (m Manager) List(ctx context.Context) ([]types.LicenseManagerLicenseInfo, error) {
    var mlm mo.LicenseManager

    err := property.DefaultCollector(m.c).RetrieveOne(ctx, m.Reference(), []string{"licenses"}, &mlm)
    if err != nil {
        return nil, err
    }

    return mlm.Licenses, nil
}
開發者ID:MerlinDMC,項目名稱:machine,代碼行數:10,代碼來源:manager.go

示例14: Run

func (cmd *info) Run(f *flag.FlagSet) error {
    if f.NArg() == 0 {
        return flag.ErrHelp
    }

    c, err := cmd.Client()
    if err != nil {
        return err
    }

    ctx := context.TODO()

    finder, err := cmd.Finder()
    if err != nil {
        return err
    }

    var res infoResult
    var props []string

    if cmd.OutputFlag.JSON {
        props = nil
    } else {
        props = []string{
            "name",
            "config.cpuAllocation",
            "config.memoryAllocation",
            "runtime.cpu",
            "runtime.memory",
        }
    }

    for _, arg := range f.Args() {
        objects, err := finder.ResourcePoolList(ctx, arg)
        if err != nil {
            return err
        }
        res.objects = append(res.objects, objects...)
    }

    if len(res.objects) != 0 {
        refs := make([]types.ManagedObjectReference, 0, len(res.objects))
        for _, o := range res.objects {
            refs = append(refs, o.Reference())
        }

        pc := property.DefaultCollector(c)
        err = pc.Retrieve(ctx, refs, props, &res.ResourcePools)
        if err != nil {
            return err
        }
    }

    return cmd.WriteResult(&res)
}
開發者ID:hickeng,項目名稱:govmomi,代碼行數:55,代碼來源:info.go

示例15: Run

func (cmd *info) Run(f *flag.FlagSet) error {
    c, err := cmd.Client()
    if err != nil {
        return err
    }

    ctx := context.TODO()

    var res infoResult
    var props []string

    if cmd.OutputFlag.JSON {
        props = nil // Load everything
    } else {
        props = []string{"summary"} // Load summary
    }

    // We could do without the -host flag, leaving it for compat
    host, err := cmd.HostSystemIfSpecified()
    if err != nil {
        return err
    }

    // Default only if there is a single host
    if host == nil && f.NArg() == 0 {
        host, err = cmd.HostSystem()
        if err != nil {
            return err
        }
    }

    if host != nil {
        res.objects = append(res.objects, host)
    } else {
        res.objects, err = cmd.HostSystems(f.Args())
        if err != nil {
            return err
        }
    }

    if len(res.objects) != 0 {
        refs := make([]types.ManagedObjectReference, 0, len(res.objects))
        for _, o := range res.objects {
            refs = append(refs, o.Reference())
        }

        pc := property.DefaultCollector(c)
        err = pc.Retrieve(ctx, refs, props, &res.HostSystems)
        if err != nil {
            return err
        }
    }

    return cmd.WriteResult(&res)
}
開發者ID:kristinn,項目名稱:govmomi,代碼行數:55,代碼來源:info.go


注:本文中的github.com/vmware/govmomi/property.DefaultCollector函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。