2015-08-11 21:27:14 +00:00
|
|
|
package mock
|
|
|
|
|
2015-09-07 22:23:03 +00:00
|
|
|
import "github.com/hashicorp/nomad/nomad/structs"
|
2015-08-11 21:27:14 +00:00
|
|
|
|
|
|
|
func Node() *structs.Node {
|
|
|
|
node := &structs.Node{
|
2015-09-07 22:23:03 +00:00
|
|
|
ID: structs.GenerateUUID(),
|
2015-08-11 21:27:14 +00:00
|
|
|
Datacenter: "dc1",
|
|
|
|
Name: "foobar",
|
|
|
|
Attributes: map[string]string{
|
2015-09-07 02:47:02 +00:00
|
|
|
"kernel.name": "linux",
|
|
|
|
"arch": "x86",
|
|
|
|
"version": "0.1.0",
|
|
|
|
"driver.exec": "1",
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 4.0,
|
|
|
|
MemoryMB: 8192,
|
|
|
|
DiskMB: 100 * 1024,
|
|
|
|
IOPS: 150,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
&structs.NetworkResource{
|
|
|
|
Public: true,
|
|
|
|
CIDR: "192.168.0.100/32",
|
|
|
|
ReservedPorts: []int{22},
|
|
|
|
MBits: 1000,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Reserved: &structs.Resources{
|
|
|
|
CPU: 0.1,
|
|
|
|
MemoryMB: 256,
|
|
|
|
DiskMB: 4 * 1024,
|
|
|
|
},
|
|
|
|
Links: map[string]string{
|
|
|
|
"consul": "foobar.dc1",
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"pci-dss": "true",
|
|
|
|
},
|
|
|
|
NodeClass: "linux-medium-pci",
|
|
|
|
Status: structs.NodeStatusReady,
|
|
|
|
}
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
func Job() *structs.Job {
|
|
|
|
job := &structs.Job{
|
2015-09-07 22:23:03 +00:00
|
|
|
ID: structs.GenerateUUID(),
|
2015-08-14 05:07:01 +00:00
|
|
|
Name: "my-job",
|
|
|
|
Type: structs.JobTypeService,
|
|
|
|
Priority: 50,
|
|
|
|
AllAtOnce: false,
|
|
|
|
Datacenters: []string{"dc1"},
|
2015-08-11 21:27:14 +00:00
|
|
|
Constraints: []*structs.Constraint{
|
|
|
|
&structs.Constraint{
|
|
|
|
Hard: true,
|
2015-08-28 08:30:47 +00:00
|
|
|
LTarget: "$attr.kernel.name",
|
2015-08-11 21:27:14 +00:00
|
|
|
RTarget: "linux",
|
|
|
|
Operand: "=",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TaskGroups: []*structs.TaskGroup{
|
|
|
|
&structs.TaskGroup{
|
|
|
|
Name: "web",
|
|
|
|
Count: 10,
|
|
|
|
Tasks: []*structs.Task{
|
|
|
|
&structs.Task{
|
|
|
|
Name: "web",
|
2015-08-29 23:24:01 +00:00
|
|
|
Driver: "exec",
|
2015-08-11 21:27:14 +00:00
|
|
|
Config: map[string]string{
|
2015-08-29 23:24:01 +00:00
|
|
|
"command": "/bin/date",
|
|
|
|
"args": "+%s",
|
2015-08-11 21:27:14 +00:00
|
|
|
},
|
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 0.5,
|
|
|
|
MemoryMB: 256,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"elb_check_type": "http",
|
|
|
|
"elb_check_interval": "30s",
|
|
|
|
"elb_check_min": "3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"owner": "armon",
|
|
|
|
},
|
2015-08-13 23:25:59 +00:00
|
|
|
Status: structs.JobStatusPending,
|
|
|
|
CreateIndex: 42,
|
|
|
|
ModifyIndex: 99,
|
2015-08-11 21:27:14 +00:00
|
|
|
}
|
|
|
|
return job
|
|
|
|
}
|
|
|
|
|
|
|
|
func Eval() *structs.Evaluation {
|
|
|
|
eval := &structs.Evaluation{
|
2015-09-07 22:23:03 +00:00
|
|
|
ID: structs.GenerateUUID(),
|
2015-08-11 21:27:14 +00:00
|
|
|
Priority: 50,
|
|
|
|
Type: structs.JobTypeService,
|
2015-09-07 22:23:03 +00:00
|
|
|
JobID: structs.GenerateUUID(),
|
2015-08-11 21:27:14 +00:00
|
|
|
Status: structs.EvalStatusPending,
|
|
|
|
}
|
|
|
|
return eval
|
|
|
|
}
|
|
|
|
|
|
|
|
func Alloc() *structs.Allocation {
|
|
|
|
alloc := &structs.Allocation{
|
2015-09-07 22:23:03 +00:00
|
|
|
ID: structs.GenerateUUID(),
|
|
|
|
EvalID: structs.GenerateUUID(),
|
2015-08-29 23:24:01 +00:00
|
|
|
NodeID: "foo",
|
|
|
|
TaskGroup: "web",
|
2015-08-11 21:27:14 +00:00
|
|
|
Resources: &structs.Resources{
|
|
|
|
CPU: 1.0,
|
|
|
|
MemoryMB: 1024,
|
|
|
|
DiskMB: 1024,
|
|
|
|
IOPS: 10,
|
|
|
|
Networks: []*structs.NetworkResource{
|
|
|
|
&structs.NetworkResource{
|
|
|
|
Public: true,
|
|
|
|
CIDR: "192.168.0.100/32",
|
|
|
|
ReservedPorts: []int{12345},
|
|
|
|
MBits: 100,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-08-25 23:19:21 +00:00
|
|
|
Job: Job(),
|
|
|
|
DesiredStatus: structs.AllocDesiredStatusRun,
|
|
|
|
ClientStatus: structs.AllocClientStatusPending,
|
2015-08-11 21:27:14 +00:00
|
|
|
}
|
|
|
|
alloc.JobID = alloc.Job.ID
|
|
|
|
return alloc
|
|
|
|
}
|
|
|
|
|
|
|
|
func Plan() *structs.Plan {
|
|
|
|
return &structs.Plan{
|
|
|
|
Priority: 50,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func PlanResult() *structs.PlanResult {
|
|
|
|
return &structs.PlanResult{}
|
|
|
|
}
|