-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 351b5c0 Author: abhijeetkaurav1st <abhijeet.kaurav@nutanix.com> Date: Thu Dec 16 14:14:30 2021 +0530 Minor fixes for undefined attributes at profile model for version setup < 3.3.0. commit 7ea5982 Author: Abhijeet Singh Kaurav <abhijeet.kaurav@nutanix.com> Date: Wed Dec 15 19:03:06 2021 +0530 Added support for get_runbook_action and macro in ahv-disk-images (#206) * Allow macro in image names * Adding example that shows macor usage in vm-disk-image and vm-nic * Adding helper get_runbook_action for getting action out of imported runbook * Adding exsiting machine example and minor improvements * minor fixes in models * Fixing runbook examples commit bc9dc6a Author: Abhijeet Singh Kaurav <abhijeet.kaurav@nutanix.com> Date: Mon Dec 13 20:25:01 2021 +0530 Use ASCENDING order for list_all query (#205) fixes #200
- Loading branch information
1 parent
6e59fa6
commit 67c0d97
Showing
14 changed files
with
353 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
""" | ||
This blueprint uses macro in nic and disk | ||
""" | ||
|
||
import os # no_qa | ||
|
||
from calm.dsl.builtins import * # no_qa | ||
from examples.AHV_MACRO_BLUEPRINT.sample_runbook import DslSetVariableRunbook | ||
|
||
|
||
# Secret Variables | ||
CRED_USERNAME = read_local_file("cred_username") | ||
CRED_PASSWORD = read_local_file("cred_password") | ||
|
||
|
||
class Service1(Service): | ||
"""Sample Service""" | ||
|
||
# disk image uuid to be used in disk image | ||
Custom_disk_uuid = CalmVariable.Simple.string( | ||
"e7b96d85-f41b-40a1-bd23-310b7de14eb1" | ||
) | ||
|
||
|
||
class Package1(Package): | ||
"""Sample package""" | ||
|
||
services = [ref(Service1)] | ||
|
||
|
||
class VmResources(AhvVmResources): | ||
|
||
memory = 2 | ||
vCPUs = 2 | ||
cores_per_vCPU = 2 | ||
disks = [ | ||
AhvVmDisk.Disk.Scsi.cloneFromImageService( | ||
"@@{Service1.Custom_disk_uuid}@@", bootable=True | ||
) | ||
] | ||
nics = [AhvVmNic.NormalNic.ingress("@@{custom_nic.uuid}@@")] | ||
|
||
|
||
class VMSubstrate(Substrate): | ||
"""Sample Substrate""" | ||
|
||
provider_spec = ahv_vm( | ||
name="vm-@@{calm_array_index}@@-@@{calm_time}@@", resources=VmResources | ||
) | ||
|
||
@action | ||
def __pre_create__(): | ||
CalmTask.SetVariable.escript( | ||
name="Pre_create task1", | ||
filename=os.path.join("scripts", "pre_create_script.py"), | ||
target=ref(VMSubstrate), | ||
variables=["custom_nic"], | ||
) | ||
|
||
|
||
class MacroBlueprintDeployment(Deployment): | ||
"""Sample Deployment""" | ||
|
||
packages = [ref(Package1)] | ||
substrate = ref(VMSubstrate) | ||
|
||
|
||
class MacroBlueprintProfile(Profile): | ||
"""Sample Profile""" | ||
|
||
foo1 = CalmVariable.Simple("bar1", runtime=True) | ||
foo2 = CalmVariable.Simple("bar2", runtime=True) | ||
deployments = [MacroBlueprintDeployment] | ||
|
||
# For profile, actions task_target_mapping is compulsory | ||
http_task_action = get_runbook_action( | ||
DslSetVariableRunbook, | ||
targets={ | ||
"Task1": ref(Service1), | ||
"Task2": ref(Service1), | ||
"Task3": ref(Service1), | ||
} | ||
) | ||
|
||
@action | ||
def test_profile_action(): | ||
"""Sample description for a profile action""" | ||
CalmTask.Exec.ssh(name="Task5", script='echo "Hello"', target=ref(Service1)) | ||
|
||
|
||
class MacroBlueprint(Blueprint): | ||
"""Blueprint using macro in disk and nics""" | ||
|
||
services = [Service1] | ||
packages = [Package1] | ||
substrates = [VMSubstrate] | ||
profiles = [MacroBlueprintProfile] | ||
credentials = [basic_cred(CRED_USERNAME, CRED_PASSWORD, default=True)] |
Oops, something went wrong.