Пример #1
0
func treatPhysical(port *guest.NIC, mode *xmlinput.Mode, templatesDir string) (string, error) {
	var err error
	var tempData string

	switch mode.Type {
	case xmlinput.ConTypePassthrough:
		if tempData, err = processTemplatePassthrough(port, TmpltPassthrough); err != nil {
			return "", utils.FormatError(err)
		}
	case xmlinput.ConTypeSRIOV:
		if tempData, err = processTemplatePassthrough(port, TmpltSriovPassthrough); err != nil {
			return "", utils.FormatError(err)
		}
	case xmlinput.ConTypeDirect:
		if tempData, err = metadata.ProcessNetworkTemplate(mode, TmpltDirect,
			&DirectData{port.HostNIC.Name, mode.VnicDriver, port.PCIAddr.Domain, port.PCIAddr.Bus,
				port.PCIAddr.Slot, port.PCIAddr.Function}, templatesDir); err != nil {
			return "", utils.FormatError(err)
		}
	}
	return tempData, nil
}
Пример #2
0
// SetNetworkData is responsible for adding to the metadata appropriate entries
// related to the network configuration
func (m meta) SetNetworkData(mapping *guest.Config, templatesDir string, i interface{}) (string, error) {
	var data string
	for i, network := range mapping.Networks {
		list := mapping.NICLists[i]
		for _, mode := range network.Modes {
			for _, port := range list {
				switch port.HostNIC.Type {
				case host.NicTypePhys:
					if mode.Type == xmlinput.ConTypePassthrough || mode.Type == xmlinput.ConTypeDirect {
						out, err := treatPhysical(port, mode, templatesDir)
						if err != nil {
							return "", utils.FormatError(err)
						}
						data += out
					}

				case host.NicTypePhysVF:
					if mode.Type == xmlinput.ConTypeSRIOV {
						out, err := treatPhysical(port, mode, templatesDir)
						if err != nil {
							return "", utils.FormatError(err)
						}
						data += out
					}

				case host.NicTypeOVS:
					if mode.Type == xmlinput.ConTypeOVS {
						tempData, err := metadata.ProcessNetworkTemplate(mode, TmpltBridgedOVS,
							&BridgedOVSData{port.HostNIC.Name, mode.VnicDriver, port.PCIAddr.Domain,
								port.PCIAddr.Bus, port.PCIAddr.Slot, port.PCIAddr.Function}, templatesDir)
						if err != nil {
							return "", utils.FormatError(err)
						}
						data += tempData
					}

				case host.NicTypeBridge:
					if mode.Type == xmlinput.ConTypeBridged {
						tempData, err := metadata.ProcessNetworkTemplate(mode, TmpltBridged,
							&BridgedData{port.HostNIC.Name, mode.VnicDriver, port.PCIAddr.Domain,
								port.PCIAddr.Bus, port.PCIAddr.Slot, port.PCIAddr.Function}, templatesDir)
						if err != nil {
							return "", utils.FormatError(err)
						}
						data += tempData
					}

				case host.NicTypeVirtualNetwork:
					if mode.Type == xmlinput.ConTypeVirtualNetwork {
						tempData, err := metadata.ProcessNetworkTemplate(mode, TmpltVirtNetwork,
							&VirtNetwork{port.HostNIC.Name, mode.VnicDriver, port.PCIAddr.Domain,
								port.PCIAddr.Bus, port.PCIAddr.Slot, port.PCIAddr.Function}, templatesDir)
						if err != nil {
							return "", utils.FormatError(err)
						}
						data += tempData
					}
				}
			}
		}
	}
	return data, nil
}