github.com/hernad/nomad@v1.6.112/nomad/mock/node.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package mock 5 6 import ( 7 "github.com/hernad/nomad/helper/uuid" 8 "github.com/hernad/nomad/nomad/structs" 9 psstructs "github.com/hernad/nomad/plugins/shared/structs" 10 ) 11 12 func Node() *structs.Node { 13 node := &structs.Node{ 14 ID: uuid.Generate(), 15 SecretID: uuid.Generate(), 16 Datacenter: "dc1", 17 Name: "foobar", 18 Drivers: map[string]*structs.DriverInfo{ 19 "exec": { 20 Detected: true, 21 Healthy: true, 22 }, 23 "mock_driver": { 24 Detected: true, 25 Healthy: true, 26 }, 27 }, 28 Attributes: map[string]string{ 29 "kernel.name": "linux", 30 "arch": "x86", 31 "nomad.version": "0.5.0", 32 "driver.exec": "1", 33 "driver.mock_driver": "1", 34 "consul.version": "1.11.4", 35 }, 36 37 // TODO Remove once clientv2 gets merged 38 Resources: &structs.Resources{ 39 CPU: 4000, 40 MemoryMB: 8192, 41 DiskMB: 100 * 1024, 42 }, 43 Reserved: &structs.Resources{ 44 CPU: 100, 45 MemoryMB: 256, 46 DiskMB: 4 * 1024, 47 Networks: []*structs.NetworkResource{ 48 { 49 Device: "eth0", 50 IP: "192.168.0.100", 51 ReservedPorts: []structs.Port{{Label: "ssh", Value: 22}}, 52 MBits: 1, 53 }, 54 }, 55 }, 56 57 NodeResources: &structs.NodeResources{ 58 Cpu: structs.NodeCpuResources{ 59 CpuShares: 4000, 60 }, 61 Memory: structs.NodeMemoryResources{ 62 MemoryMB: 8192, 63 }, 64 Disk: structs.NodeDiskResources{ 65 DiskMB: 100 * 1024, 66 }, 67 Networks: []*structs.NetworkResource{ 68 { 69 Mode: "host", 70 Device: "eth0", 71 CIDR: "192.168.0.100/32", 72 MBits: 1000, 73 }, 74 }, 75 NodeNetworks: []*structs.NodeNetworkResource{ 76 { 77 Mode: "host", 78 Device: "eth0", 79 Speed: 1000, 80 Addresses: []structs.NodeNetworkAddress{ 81 { 82 Alias: "default", 83 Address: "192.168.0.100", 84 Family: structs.NodeNetworkAF_IPv4, 85 }, 86 }, 87 }, 88 }, 89 }, 90 ReservedResources: &structs.NodeReservedResources{ 91 Cpu: structs.NodeReservedCpuResources{ 92 CpuShares: 100, 93 }, 94 Memory: structs.NodeReservedMemoryResources{ 95 MemoryMB: 256, 96 }, 97 Disk: structs.NodeReservedDiskResources{ 98 DiskMB: 4 * 1024, 99 }, 100 Networks: structs.NodeReservedNetworkResources{ 101 ReservedHostPorts: "22", 102 }, 103 }, 104 Links: map[string]string{ 105 "consul": "foobar.dc1", 106 }, 107 Meta: map[string]string{ 108 "pci-dss": "true", 109 "database": "mysql", 110 "version": "5.6", 111 }, 112 NodeClass: "linux-medium-pci", 113 NodePool: structs.NodePoolDefault, 114 Status: structs.NodeStatusReady, 115 SchedulingEligibility: structs.NodeSchedulingEligible, 116 } 117 _ = node.ComputeClass() 118 return node 119 } 120 121 func DrainNode() *structs.Node { 122 node := Node() 123 node.DrainStrategy = &structs.DrainStrategy{ 124 DrainSpec: structs.DrainSpec{}, 125 } 126 node.Canonicalize() 127 return node 128 } 129 130 // NvidiaNode returns a node with two instances of an Nvidia GPU 131 func NvidiaNode() *structs.Node { 132 n := Node() 133 n.NodeResources.Devices = []*structs.NodeDeviceResource{ 134 { 135 Type: "gpu", 136 Vendor: "nvidia", 137 Name: "1080ti", 138 Attributes: map[string]*psstructs.Attribute{ 139 "memory": psstructs.NewIntAttribute(11, psstructs.UnitGiB), 140 "cuda_cores": psstructs.NewIntAttribute(3584, ""), 141 "graphics_clock": psstructs.NewIntAttribute(1480, psstructs.UnitMHz), 142 "memory_bandwidth": psstructs.NewIntAttribute(11, psstructs.UnitGBPerS), 143 }, 144 Instances: []*structs.NodeDevice{ 145 { 146 ID: uuid.Generate(), 147 Healthy: true, 148 }, 149 { 150 ID: uuid.Generate(), 151 Healthy: true, 152 }, 153 }, 154 }, 155 } 156 _ = n.ComputeClass() 157 return n 158 }