Esempio n. 1
0
func (v *Validator) networkHelper(ctx context.Context, path string) (string, error) {
	defer trace.End(trace.Begin(path))

	net, err := v.getNetwork(ctx, path)
	if err != nil {
		return "", err
	}
	moref := net.Reference()
	return moref.String(), nil
}
Esempio n. 2
0
// suggestNetwork suggests all networks
// incStdNets includes standard Networks in addition to DPGs
func (v *Validator) suggestNetwork(flag string, incStdNets bool) {
	defer trace.End(trace.Begin(flag))

	log.Infof("Suggesting valid networks for %s", flag)

	var validNets []string

	nets, err := v.Session.Finder.NetworkList(v.Context, "*")
	if err != nil {
		log.Errorf("Unable to list networks: %s", err)
		return
	}

	if len(nets) == 0 {
		log.Info("No networks found")
		return
	}

	for _, net := range nets {
		switch o := net.(type) {
		case *object.DistributedVirtualPortgroup:
			if v.isNetworkNameValid(o.InventoryPath, flag) {
				// Filter out DVS uplink
				if !v.isDVSUplink(net.Reference()) {
					validNets = append(validNets, path.Base(o.InventoryPath))
				}
			}
		case *object.Network:
			if incStdNets && v.isNetworkNameValid(o.InventoryPath, flag) {
				validNets = append(validNets, path.Base(o.InventoryPath))
			}
		}
	}

	if len(validNets) == 0 {
		log.Info("No valid networks found")
		return
	}

	log.Infof("Suggested values for %s:", flag)
	for _, n := range validNets {
		log.Infof("  %q", n)
	}
}
Esempio n. 3
0
func (v *Validator) dpgHelper(ctx context.Context, path string) (types.ManagedObjectReference, error) {
	defer trace.End(trace.Begin(path))

	net, err := v.getNetwork(ctx, path)
	if err != nil {
		return types.ManagedObjectReference{}, err
	}

	// ensure that the type of the network is a Distributed Port Group if the target is a vCenter
	// if it's not then any network suffices
	if v.IsVC() {
		_, dpg := net.(*object.DistributedVirtualPortgroup)
		if !dpg {
			return types.ManagedObjectReference{}, fmt.Errorf("%q is not a Distributed Port Group", path)
		}
	}

	return net.Reference(), nil
}