forked from nutanix/calm-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blueprint.py
117 lines (82 loc) · 3.26 KB
/
blueprint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from calm.dsl.builtins import AhvVmDisk, AhvVmNic, AhvVmGC
from calm.dsl.builtins import ref, basic_cred, AhvVmResources, AhvVm
from calm.dsl.builtins import vm_disk_package, read_local_file
from calm.dsl.builtins import Service, Package, Substrate
from calm.dsl.builtins import Profile, Blueprint
from calm.dsl.builtins import CalmVariable, CalmTask, action
from calm.dsl.builtins import Brownfield as BF
CENTOS_KEY = read_local_file(".tests/keys/centos")
CENTOS_PUBLIC_KEY = read_local_file(".tests/keys/centos_pub")
INSTANCE_NAME = read_local_file("brownfield_instance_name")
Centos = basic_cred("centos", CENTOS_KEY, name="Centos", type="KEY", default=True)
Era_Disk = vm_disk_package(
name="era_disk",
config={
# By default image type is set to DISK_IMAGE
"image": {
"source": "http://download.nutanix.com/era/1.1.1/ERA-Server-build-1.1.1-340d9db1118eac81219bec98507d4982045d8799.qcow2"
}
},
)
class AhvVmService(Service):
"""Sample mysql service"""
ENV = CalmVariable.Simple("DEV")
class AhvVmPackage(Package):
"""Example package with variables, install tasks and link to service"""
foo = CalmVariable.Simple("bar")
services = [ref(AhvVmService)]
@action
def __install__():
CalmTask.Exec.ssh(name="Task1", script="echo @@{foo}@@")
class MyAhvVmResources(AhvVmResources):
memory = 4
vCPUs = 2
cores_per_vCPU = 1
disks = [
AhvVmDisk.Disk.Scsi.cloneFromVMDiskPackage(Era_Disk, bootable=True),
]
nics = [AhvVmNic("vlan.0")]
guest_customization = AhvVmGC.CloudInit(
config={
"users": [
{
"name": "centos",
"ssh-authorized-keys": [CENTOS_PUBLIC_KEY],
"sudo": ["ALL=(ALL) NOPASSWD:ALL"],
}
]
}
)
serial_ports = {0: False, 1: False, 2: True, 3: True}
class MyAhvVm(AhvVm):
resources = MyAhvVmResources
categories = {"AppFamily": "Backup", "AppType": "Default"}
class AhvVmSubstrate(Substrate):
"""AHV VM config given by reading a spec file"""
provider_spec = MyAhvVm
class AhvVmDeployment(BF.Deployment):
"""Sample deployment pulling in service and substrate references"""
packages = [ref(AhvVmPackage)]
substrate = ref(AhvVmSubstrate)
# Note: If multiple instance with same name exists, send ip_address or instance_id too
# Ex: instance = [BF.Vm.Ahv(name=<instance_name>, ip_address = [ip1, ip2], instance_id = 'instance_id')]
instances = [
BF.Vm.Ahv(INSTANCE_NAME)
]
class AhvVmProfile(Profile):
"""Sample application profile with variables"""
nameserver = CalmVariable.Simple("10.40.64.15", label="Local DNS resolver")
foo1 = CalmVariable.Simple("bar1", runtime=True)
foo2 = CalmVariable.Simple("bar2", runtime=True)
deployments = [AhvVmDeployment]
@action
def test_profile_action():
"""Sample description for a profile action"""
CalmTask.Exec.ssh(name="Task5", script='echo "Hello"', target=ref(AhvVmService))
class AhvBlueprint(Blueprint):
"""Sample Bp that used ahv_vm_helpers"""
credentials = [Centos]
services = [AhvVmService]
packages = [AhvVmPackage, Era_Disk]
substrates = [AhvVmSubstrate]
profiles = [AhvVmProfile]