// AddVnic creates a new virtual NIC on this machine
AddVnic creates a new virtual NIC on this machine
// AddVnic creates a new virtual NIC on this machine
func (v *VirtualMachine) AddVnic(name, mac string) (*Vnic, error) {
	settingsData, err := utils.GetResourceAllocSettings(v.mgr.con, "", SyntheticEthernetPortSettingDataClass)
	if err != nil {
		return nil, errors.Wrap(err, "utils.GetResourceAllocSettings")
	}
	if err := settingsData.Set("ElementName", name); err != nil {
		return nil, errors.Wrap(err, "set ElementName")
	}
	newID, err := utils.UUID4()
	if err != nil {
		return nil, errors.Wrap(err, "UUID4")
	}
	if err := settingsData.Set("VirtualSystemIdentifiers", []string{fmt.Sprintf("{%s}", newID)}); err != nil {
		return nil, errors.Wrap(err, "set VirtualSystemIdentifiers")
	}
	if mac != "" {
		mac = strings.Replace(mac, ":", "", -1)
		mac = strings.Replace(mac, "-", "", -1)
		if err := settingsData.Set("Address", mac); err != nil {
			return nil, errors.Wrap(err, "set Address")
		}
		if err := settingsData.Set("StaticMacAddress", true); err != nil {
			return nil, errors.Wrap(err, "set StaticMacAddress")
		}
	}
	dataText, err := settingsData.GetText(1)
	if err != nil {
		return nil, errors.Wrap(err, "GetText")
	}
	resVnic, err := utils.AddResourceSetting(v.mgr.svc, []string{dataText}, v.path)
	if err != nil {
		return nil, errors.Wrap(err, "utils.AddResourceSetting")
	}
	return &Vnic{
		mgr:    v.mgr,
		path:   resVnic[0],
		vmPath: v.path,
	}, nil
}
func ( v * VirtualMachine ) AddVnic ( name , mac string ) ( * Vnic , error ) { settingsData , err := utils . GetResourceAllocSettings ( v . mgr . con , " " , SyntheticEthernetPortSettingDataClass ) if err != nil { return nil , errors . Wrap ( err , " " ) } if err := settingsData . Set ( " " , name ) ; err != nil { return nil , errors . Wrap ( err , " " ) } newID , err := utils . UUID4 ( ) if err != nil { return nil , errors . Wrap ( err , " " ) } if err := settingsData . Set ( " " , [ ] string { fmt . Sprintf ( " " , newID ) } ) ; err != nil { return nil , errors . Wrap ( err , " " ) } if mac != " " { mac = strings . Replace ( mac , " " , " " , - 1 ) mac = strings . Replace ( mac , " " , " " , - 1 ) if err := settingsData . Set ( " " , mac ) ; err != nil { return nil , errors . Wrap ( err , " " ) } if err := settingsData . Set ( " " , true ) ; err != nil { return nil , errors . Wrap ( err , " " ) } } dataText , err := settingsData . GetText ( 1 ) if err != nil { return nil , errors . Wrap ( err , " " ) } resVnic , err := utils . AddResourceSetting ( v . mgr . svc , [ ] string { dataText } , v . path ) if err != nil { return nil , errors . Wrap ( err , " " ) } return & Vnic { mgr : v . mgr , path : resVnic [ 0 ] , vmPath : v . path , } , nil }
AddVnic creates a new virtual NIC on this machine
AddVnic creates a new virtual NIC on this machine