github.com/jmitchell/nomad@v0.1.3-0.20151007230021-7ab84c2862d8/nomad/mock/mock.go (about) 1 package mock 2 3 import "github.com/hashicorp/nomad/nomad/structs" 4 5 func Node() *structs.Node { 6 node := &structs.Node{ 7 ID: structs.GenerateUUID(), 8 Datacenter: "dc1", 9 Name: "foobar", 10 Attributes: map[string]string{ 11 "kernel.name": "linux", 12 "arch": "x86", 13 "version": "0.1.0", 14 "driver.exec": "1", 15 }, 16 Resources: &structs.Resources{ 17 CPU: 4000, 18 MemoryMB: 8192, 19 DiskMB: 100 * 1024, 20 IOPS: 150, 21 Networks: []*structs.NetworkResource{ 22 &structs.NetworkResource{ 23 Device: "eth0", 24 CIDR: "192.168.0.100/32", 25 MBits: 1000, 26 }, 27 }, 28 }, 29 Reserved: &structs.Resources{ 30 CPU: 100, 31 MemoryMB: 256, 32 DiskMB: 4 * 1024, 33 Networks: []*structs.NetworkResource{ 34 &structs.NetworkResource{ 35 Device: "eth0", 36 IP: "192.168.0.100", 37 ReservedPorts: []int{22}, 38 MBits: 1, 39 }, 40 }, 41 }, 42 Links: map[string]string{ 43 "consul": "foobar.dc1", 44 }, 45 Meta: map[string]string{ 46 "pci-dss": "true", 47 }, 48 NodeClass: "linux-medium-pci", 49 Status: structs.NodeStatusReady, 50 } 51 return node 52 } 53 54 func Job() *structs.Job { 55 job := &structs.Job{ 56 Region: "global", 57 ID: structs.GenerateUUID(), 58 Name: "my-job", 59 Type: structs.JobTypeService, 60 Priority: 50, 61 AllAtOnce: false, 62 Datacenters: []string{"dc1"}, 63 Constraints: []*structs.Constraint{ 64 &structs.Constraint{ 65 Hard: true, 66 LTarget: "$attr.kernel.name", 67 RTarget: "linux", 68 Operand: "=", 69 }, 70 }, 71 TaskGroups: []*structs.TaskGroup{ 72 &structs.TaskGroup{ 73 Name: "web", 74 Count: 10, 75 Tasks: []*structs.Task{ 76 &structs.Task{ 77 Name: "web", 78 Driver: "exec", 79 Config: map[string]string{ 80 "command": "/bin/date", 81 "args": "+%s", 82 }, 83 Resources: &structs.Resources{ 84 CPU: 500, 85 MemoryMB: 256, 86 Networks: []*structs.NetworkResource{ 87 &structs.NetworkResource{ 88 MBits: 50, 89 DynamicPorts: []string{"http"}, 90 }, 91 }, 92 }, 93 }, 94 }, 95 Meta: map[string]string{ 96 "elb_check_type": "http", 97 "elb_check_interval": "30s", 98 "elb_check_min": "3", 99 }, 100 }, 101 }, 102 Meta: map[string]string{ 103 "owner": "armon", 104 }, 105 Status: structs.JobStatusPending, 106 CreateIndex: 42, 107 ModifyIndex: 99, 108 } 109 return job 110 } 111 112 func Eval() *structs.Evaluation { 113 eval := &structs.Evaluation{ 114 ID: structs.GenerateUUID(), 115 Priority: 50, 116 Type: structs.JobTypeService, 117 JobID: structs.GenerateUUID(), 118 Status: structs.EvalStatusPending, 119 } 120 return eval 121 } 122 123 func Alloc() *structs.Allocation { 124 alloc := &structs.Allocation{ 125 ID: structs.GenerateUUID(), 126 EvalID: structs.GenerateUUID(), 127 NodeID: "foo", 128 TaskGroup: "web", 129 Resources: &structs.Resources{ 130 CPU: 500, 131 MemoryMB: 256, 132 Networks: []*structs.NetworkResource{ 133 &structs.NetworkResource{ 134 Device: "eth0", 135 IP: "192.168.0.100", 136 ReservedPorts: []int{12345}, 137 MBits: 100, 138 DynamicPorts: []string{"http"}, 139 }, 140 }, 141 }, 142 TaskResources: map[string]*structs.Resources{ 143 "web": &structs.Resources{ 144 CPU: 500, 145 MemoryMB: 256, 146 Networks: []*structs.NetworkResource{ 147 &structs.NetworkResource{ 148 Device: "eth0", 149 IP: "192.168.0.100", 150 ReservedPorts: []int{5000}, 151 MBits: 50, 152 DynamicPorts: []string{"http"}, 153 }, 154 }, 155 }, 156 }, 157 Job: Job(), 158 DesiredStatus: structs.AllocDesiredStatusRun, 159 ClientStatus: structs.AllocClientStatusPending, 160 } 161 alloc.JobID = alloc.Job.ID 162 return alloc 163 } 164 165 func Plan() *structs.Plan { 166 return &structs.Plan{ 167 Priority: 50, 168 } 169 } 170 171 func PlanResult() *structs.PlanResult { 172 return &structs.PlanResult{} 173 }