package node

// Node summary
type RecordNode struct {
	// Consumption
	Consumption ConsumptionInfo `json:"consumption"`

	// CPU Info
	CpuInfo CpuInfo `json:"cpuInfo"`

	// CPU Allocation Ratio
	CPUAllocationRatio uint64 `json:"cpu_allocation_ratio"`

	// DPDK info
	DPDK DPDK `json:"dpdk"`

	// GID
	GID uint64 `json:"gid"`

	// Node ID
	ID uint64 `json:"id"`

	// IPAddr
	IPAddr []string `json:"ipaddr"`

	// Isolated Cpus
	IsolatedCpus []interface{} `json:"isolatedCpus"`

	// MemAllocationRatio
	MemAllocationRatio uint64 `json:"mem_allocation_ratio"`

	// Name
	Name string `json:"name"`

	// NeedReboot
	NeedReboot bool `json:"needReboot"`

	// Netaddr
	NetAddr NetAddr `json:"netaddr"`

	// Network mode
	NetworkMode string `json:"networkmode"`

	// Nic Info
	NicInfo ListNicInfo `json:"nicInfo"`

	// NumaTopology
	NumaTopology NumaTopologyInfo `json:"numaTopology"`

	// ReservedCPUs
	ReservedCPUs []interface{} `json:"reservedCpus"`

	// Reserved CPU
	ReservedCPU uint64 `json:"reserved_cpu"`

	// Reserved RAM
	ReservedRAM uint64 `json:"reserved_ram"`

	// Roles
	Roles []string `json:"roles"`

	// SriovEnabled
	SriovEnabled bool `json:"sriovEnabled"`

	// Status
	Status string `json:"status"`

	// To active
	ToActive Role `json:"to_active"`

	// To installing
	ToInstalling Role `json:"to_installing"`

	// To maintenance
	ToMaintenance Role `json:"to_maintenance"`

	// To restricted
	ToRestricted Role `json:"to_restricted"`

	// Version
	Version string `json:"version"`

	// Zone ID
	ZoneID uint64 `json:"zoneId"`

	// OpenvSwitch Bridges
	OpenvSwitchBridges []string `json:"openvswitch_bridges"`

	// Description
	Description string `json:"description"`

	// SDN Hypervisor Name
	SDNHypervisorName string `json:"sdn_hypervisor_name"`

	// CPU used by the node
	UsableCPUs []string `json:"usable_cpus"`

	// AutoStart
	AutoStart bool `json:"autostart"`

	// AutoStart Count
	AutoStartCount uint64 `json:"autostart_count"`
}

// Resource consumption of the node
type ConsumptionInfo struct {
	// Consumed resources
	Consumed ConsumedResourcesInfo `json:"consumed"`

	// Free resources
	Free FreeResourcesInfo `json:"free"`

	// Hostname
	Hostname string `json:"hostname"`

	// Reserved resources
	Reserved ResourcesInfo `json:"reserved"`

	// Total resources
	Total FreeResourcesInfo `json:"total"`
}

// Free Resources Info
type FreeResourcesInfo struct {
	// RAM
	RAM float64 `json:"RAM"`

	// VCPU
	VCPU uint64 `json:"vCPUs"`
}

// Resources Info
type ResourcesInfo struct {
	// RAM
	RAM uint64 `json:"RAM"`
}

// Consumed Resources Info
type ConsumedResourcesInfo struct {
	// RAM
	RAM uint64 `json:"RAM"`

	// Computes
	Computes uint64 `json:"computes"`

	// Routers
	Routers uint64 `json:"routers"`

	// VCPU
	VCPU uint64 `json:"vCPU"`
}

// Information about node CPU
type CpuInfo struct {
	// Clock Speed
	ClockSpeed float64 `json:"clockSpeed"`

	// CoreCount
	CoreCount uint64 `json:"coreCount"`

	// PhysCount
	PhysCount uint64 `json:"physCount"`

	// Thread count
	ThreadCount uint64 `json:"threadCount"`

	// Flags
	Flags []string `json:"flags"`

	// Model name
	ModelName string `json:"model_name"`

	// Max supported generation
	MaxSupportedGeneration string `json:"max_supported_generation"`
}

// Main information about node
type ItemNode struct {
	// Additional packages
	AdditionalPkgs []interface{} `json:"additionalpkgs"`

	// CPU Info
	CpuInfo CpuInfo `json:"cpuInfo"`

	// Description
	Description string `json:"description"`

	// DPDK
	DPDK DPDK `json:"dpdk"`

	// GID
	GID uint64 `json:"gid"`

	// GUID
	GUID string `json:"guid"`

	// Hostkey
	HostKey string `json:"hostkey"`

	// ID
	ID uint64 `json:"id"`

	// IPAddr
	IPAddr []string `json:"ipaddr"`

	// Isolated Cpus
	IsolatedCpus []interface{} `json:"isolatedCpus"`

	// Last check
	LastCheck uint64 `json:"lastcheck"`

	// Machine ID
	MachineID string `json:"machine_id"`

	// Machine GUID
	MachineGUID string `json:"machineguid"`

	// Mainboard SN
	MainboardSN string `json:"mainboardSN"`

	// Memory
	Memory uint64 `json:"memory"`

	// Milestones
	Milestones uint64 `json:"milestones"`

	// Model
	Model string `json:"model"`

	// Name
	Name string `json:"name"`

	// NeedReboot
	NeedReboot bool `json:"needReboot"`

	// NetAddr
	NetAddr ListNetAddr `json:"netaddr"`

	// Network mode
	NetworkMode string `json:"networkmode"`

	// Nic Info
	NicInfo ListNicInfo `json:"nicInfo"`

	// Node UUID
	NodeUUID string `json:"nodeUUID"`

	// NumaTopology
	NumaTopology NumaTopologyInfo `json:"numaTopology"`

	// PeerBackup
	PeerBackup uint64 `json:"peer_backup"`

	// PeerLog
	PeerLog uint64 `json:"peer_log"`

	// PeerStats
	PeerStats uint64 `json:"peer_stats"`

	// Pgpus
	Pgpus []uint64 `json:"pgpus"`

	// PublicKeys
	PublicKeys []string `json:"publickeys"`

	// Release
	Release string `json:"release"`

	// ReservedCPUs
	ReservedCPUs []interface{} `json:"reservedCpus"`

	// Reserved CPU
	ReservedCPU uint64 `json:"reserved_cpu"`

	// Reserved RAM
	ReservedRAM uint64 `json:"reserved_ram"`

	// Roles
	Roles []string `json:"roles"`

	// SDN Hypervisor Name
	SDNHypervisorName string `json:"sdn_hypervisor_name"`

	// Seps
	Seps []uint64 `json:"seps"`

	// SerialNum
	SerialNum string `json:"serialNum"`

	// SriovEnabled
	SriovEnabled bool `json:"sriovEnabled"`

	// Status
	Status string `json:"status"`

	// Tags
	Tags []string `json:"tags"`

	// Type
	Type string `json:"type"`

	//UEFI Firmware File
	UEFIFirmwareFile string `json:"uefiFirmwareFile"`

	// Version
	Version string `json:"version"`

	// Zone ID
	ZoneID uint64 `json:"zoneId"`

	// OpenvSwitch Bridges
	OpenvSwitchBridges []string `json:"openvswitch_bridges"`

	// APIUrl
	APIUrl string `json:"apiUrl"`

	// Drivers
	Drivers []string `json:"drivers"`

	// Old Compat LVM ID
	OldCompatLVMID uint64 `json:"old_compat_lvm_id"`

	// CPU Allocation ratio
	CPUAllocationRatio uint64 `json:"cpu_allocation_ratio"`

	// MemAllocationRatio
	MemAllocationRatio uint64 `json:"mem_allocation_ratio"`

	// Packages
	Packages map[string]PackageInfo `json:"packages"`

	// CPU used by the node
	UsableCPUs []string `json:"usable_cpus"`

	// AutoStart
	AutoStart bool `json:"autostart"`

	// AutoStart Count
	AutoStartCount uint64 `json:"autostart_count"`

	// PCI devices attached to the node
	PCIDevices []ItemPCIDevice `json:"pci_devices"`
}

type PackageInfo struct {
	// Installed size
	InstalledSize string `json:"installed_size"`
	// Version
	Ver string `json:"ver"`
}

// Numa Topology Info
type NumaTopologyInfo struct {
	// NodeNum
	NodeNum uint64 `json:"nodenum"`

	// Nodes
	Nodes map[string]NodeInfo `json:"nodes"`
}

// Node Info from NumaTopologyInfo
type NodeInfo struct {
	// CPUList
	CPUList []uint64 `json:"cpulist"`

	// Memory
	Memory ItemMemory `json:"memory"`
}

type ItemMemory struct {
	// 1G
	OneG uint64 `json:"1G"`

	// 1G available
	OneGAvailable uint64 `json:"1G_available"`

	// 1G free
	OneGFree uint64 `json:"1G_free"`

	// 1G reserved
	OneGReserved uint64 `json:"1G_reserved"`

	// 1G used
	OneGUsed uint64 `json:"1G_used"`

	// 1G DPDK reserved
	OneGDPDKReserved uint64 `json:"1G_dpdk_reserved"`

	// 2M
	TwoM uint64 `json:"2M"`

	// 2M available
	TwoMAvailable uint64 `json:"2M_available"`

	// 2M free
	TwoMFree uint64 `json:"2M_free"`

	// 2M reserved
	TwoMReserved uint64 `json:"2M_reserved"`

	// 2M used
	TwoMUsed uint64 `json:"2M_used"`

	// Total
	Total uint64 `json:"total"`
}

type ListNicInfo []ItemNicInfo

// Item Nic Info
type ItemNicInfo struct {
	// Driver
	Driver string `json:"driver"`

	// MaxVFS
	MaxVFS uint64 `json:"maxvfs"`

	// NumaNode
	NumaNode int64 `json:"numaNode"`

	// NumVFS
	NumVFS uint64 `json:"numvfs"`

	// OSName
	OSName string `json:"osName"`

	// PCISlot
	PCISlot string `json:"pciSlot"`

	// VFList
	VFList []interface{} `json:"vflist"`
}

type ListNetAddr []ItemNetAddr

// Item Net Addr
type ItemNetAddr struct {
	// CIDR
	CIDR []string `json:"cidr"`

	// Index
	Index uint64 `json:"index"`

	// IP
	IP []string `json:"ip"`

	// Mac
	Mac string `json:"mac"`

	// MTU
	MTU uint64 `json:"mtu"`

	// Name
	Name string `json:"name"`
}

// List of nodes
type ListNodes struct {
	// Data
	Data []ItemNode `json:"data"`

	// Entry count
	EntryCount uint64 `json:"entryCount"`
}

// Net address
type NetAddr struct {
	// Name
	Name string `json:"name"`

	// IP list backplane1 node
	IP []string `json:"ip"`
}

// DPDK info
type DPDK struct {
	// Bridges
	Bridges Bridges `json:"bridges"`

	// ovs dpdk cores
	OVSDPDKCores []uint64 `json:"ovs_dpdk_cores"`

	// hp memory
	HPMemory map[string]uint64 `json:"hp_memory"`
}

// Bridges
type Bridges struct {
	Backplane1 Backplane1 `json:"backplane1"`
}

// Backplane1
type Backplane1 struct {
	Interfaces []string `json:"interfaces"`
	NumaNode   int64    `json:"numa_node"`
}

// Role
type Role struct {
	Actor  string `json:"actor"`
	Reason string `json:"reason"`
	Time   uint64 `json:"time"`
}

// PCI device info
type ItemPCIDevice struct {
	// Hardware path
	HWPath string `json:"hw_path"`

	// Current driver
	CurrentDriver string `json:"current_driver"`

	// NUMA node
	NUMANode uint64 `json:"numa_node"`

	// Product ID
	ProductID string `json:"product_id"`

	// Product name
	ProductName string `json:"product_name"`

	// Vendor ID
	VendorID string `json:"vendor_id"`

	// Vendor name
	VendorName string `json:"vendor_name"`

	// IOMMU group
	IOMMUGroup uint64 `json:"iommu_group"`
}

// List of PCI devices
type ListPCIDevices struct {
	// Data
	Data []ItemPCIDevice `json:"data"`

	// Entry count
	EntryCount uint64 `json:"entryCount"`
}

// Response for PCI device driver binding actions
type RecordPCIDeviceDriver struct {
	// Success
	Success bool `json:"success"`

	// Message
	Message string `json:"message"`

	// Result
	Result interface{} `json:"result"`
}

// Information about SSH Identity
type SSHIdentity struct {
	//Host name of the client
	HostName string `json:"host_name"`

	//SSH host key of the client
	HostKey string `json:"host_key"`

	//Array of SSH public keys of the client
	PublicKeys []string `json:"public_keys"`
}

// Full network configuration of a node
type RecordNodeNetworkInfo struct {
	// System-level information about all network interfaces on the node
	SystemNetworksInfo map[string]SystemNetworkInfo `json:"system_networks_info"`

	// Raw OVS ports data
	OVSNetworksInfo []OVSNetworkInfo `json:"ovs_networks_info"`

	// VM network interface connections
	LibvirtNetworksInfo []LibvirtNetworkInfo `json:"libvirt_networks_info"`

	// Assembled network topology of the node
	Topology NetworkTopology `json:"topology"`
}

// System network interface
type SystemNetworkInfo struct {
	// MTU value
	MTU uint64 `json:"mtu"`

	// Interface link speed
	Speed int64 `json:"speed"`

	// Linux bridge ID
	BridgeID string `json:"bridge_id"`

	// Bridge port ID
	BPortID string `json:"bport_id"`

	// MAC address
	MAC string `json:"mac"`
}

// OVS port information
type OVSNetworkInfo struct {
	// Bridge name
	BridgeName string `json:"bridge_name"`

	// Bridge tag
	BridgeTag string `json:"bridge_tag"`

	// Interface UUID
	InterfaceUUID string `json:"interface_uuid"`

	// Interface type
	InterfaceType string `json:"interface_type"`

	// Interface name
	InterfaceName string `json:"interface_name"`

	// Interface MTU value
	InterfaceMTU uint64 `json:"interface_mtu"`

	// Interface IP address
	InterfaceIP string `json:"interface_ip"`

	// Interface MAC address
	InterfaceMAC string `json:"interface_mac"`

	// Interface peer name
	InterfacePeer string `json:"interface_peer"`
}

// VM network interface connection
type LibvirtNetworkInfo struct {
	// VM name
	VMName string `json:"vm_name"`

	// Host-side interface name used by the VM
	Interface string `json:"interface"`

	// Interface type
	InterfaceType string `json:"interface_type"`

	// Name of the bridge the VM interface is attached to
	InterfaceSource string `json:"interface_source"`
}

// Assembled network topology of the node
type NetworkTopology struct {
	// Map of all network interfaces by name with their topology details and connections
	Interfaces map[string]TopologyInterface `json:"interfaces"`
}

// Interface and its role in the network topology
type TopologyInterface struct {
	// Interface type
	Type string `json:"type"`

	// Interface MTU value
	MTU uint64 `json:"mtu"`

	// Interface link speed
	Speed int64 `json:"speed"`

	// Connections to VMs and to bridges
	Connections TopologyInterfaceConnections `json:"connections"`

	// VLANs associated with the interface
	VLANs []string `json:"vlans"`

	// Linux bridge ID
	BridgeID string `json:"bridge_id"`

	// Port configuration of this bridge
	BridgeInfo *TopologyBridgeInfo `json:"bridge_info"`

	// Peer bridges connected to this bridge via patch ports
	BridgeConnections []TopologyBridgeRef `json:"bridge_connections"`

	// Names of interfaces attached to this bridge as ports
	ConnectedInterfaces []string `json:"connected_interfaces"`

	// Peer interface name
	Peer string `json:"peer"`

	// OVS UUID
	UUID string `json:"uuid"`
}

// Lists what is connected to this interface
type TopologyInterfaceConnections struct {
	// VMs connected to this interface
	VMs []TopologyVMConnection `json:"vms"`

	// Bridges this interface is attached to
	Bridges []TopologyBridgeAttachment `json:"bridges"`
}

// VM connected to a bridge or interface
type TopologyVMConnection struct {
	// VM name
	Name string `json:"name"`

	// Host-side interface name
	VMInterface string `json:"vm_interface"`

	// VM interface type
	VMInterfaceType string `json:"vm_interface_type"`

	// Connection type
	ConnectionType string `json:"connection_type"`

	// Via bridge
	ViaBridge string `json:"via_bridge"`
}

// How interface is attached to a bridge
type TopologyBridgeAttachment struct {
	// Bridge name
	Name string `json:"name"`

	// Bridge type
	Type string `json:"type"`

	// Attachment method
	Via string `json:"via"`

	// Port details
	PortInfo *TopologyPortInfo `json:"port_info"`

	// Linux bridge port ID
	BPortID string `json:"bport_id"`
}

// Bridge port entry
type TopologyPortInfo struct {
	// Port name
	Name string `json:"name"`

	// Port type
	Type string `json:"type"`

	// MTU value
	MTU uint64 `json:"mtu"`

	// VLAN tag
	VLAN string `json:"vlan"`

	// OVS UUID of the port
	UUID string `json:"uuid"`
}

// OVS bridge port configuration
type TopologyBridgeInfo struct {
	// Bridge type
	Type string `json:"type"`

	// List of ports on this bridge
	Ports []TopologyBridgePort `json:"ports"`
}

// Port on an OVS bridge
type TopologyBridgePort struct {
	// Port name
	Name string `json:"name"`

	// Port type
	Type string `json:"type"`

	// MTU value
	MTU uint64 `json:"mtu"`

	// VLAN tag
	VLAN string `json:"vlan"`

	// UUID
	UUID string `json:"uuid"`

	// IP address
	IP string `json:"ip"`

	// MAC address
	MAC string `json:"mac"`
}

// Peer bridge connected via a patch port
type TopologyBridgeRef struct {
	// Name of the peer bridge
	Name string `json:"name"`

	// Name of the patch port used to connect to the peer bridge
	Via string `json:"via"`

	// VLAN tag on the patch connection
	VLAN string `json:"vlan"`
}
