""" Calm Runbook Sample for running http tasks """ from calm.dsl.runbooks import read_local_file from calm.dsl.runbooks import runbook, Ref from calm.dsl.runbooks import RunbookTask as Task, basic_cred from calm.dsl.runbooks import CalmEndpoint as Endpoint from calm.dsl.builtins.models.helper.common import get_vmware_account_from_datacenter linux_ip = read_local_file(".tests/runbook_tests/vm_ip") windows_ip = read_local_file(".tests/runbook_tests/windows_vm_ip") AHV_LINUX_ID = read_local_file(".tests/runbook_tests/ahv_linux_id") AHV_LINUX_VM_NAME = read_local_file(".tests/runbook_tests/ahv_linux_vm_name") AHV_LINUX_VM_NAME_PREFIX = read_local_file( ".tests/runbook_tests/ahv_linux_vm_name_prefix" ) # AHV_WINDOWS_ID = read_local_file(".tests/runbook_tests/ahv_windows_id") VMWARE_LINUX_ID = read_local_file(".tests/runbook_tests/vmware_linux_id") VMWARE_LINUX_VM_NAME = read_local_file(".tests/runbook_tests/vmware_linux_vm_name") VMWARE_LINUX_VM_NAME_PREFIX = read_local_file( ".tests/runbook_tests/vmware_linux_vm_name_prefix" ) CRED_USERNAME = read_local_file(".tests/runbook_tests/username") CRED_WINDOWS_USERNAME = read_local_file(".tests/runbook_tests/windows_username") CRED_PASSWORD = read_local_file(".tests/runbook_tests/password") HTTP_AUTH_USERNAME = read_local_file(".tests/runbook_tests/auth_username") HTTP_AUTH_PASSWORD = read_local_file(".tests/runbook_tests/auth_password") HTTP_URL = read_local_file(".tests/runbook_tests/url")
""" Calm HTTP Endpoint Sample with Auth """ from calm.dsl.runbooks import read_local_file from calm.dsl.runbooks import CalmEndpoint as Endpoint AUTH_USERNAME = read_local_file(".tests/runbook_tests/auth_username") AUTH_PASSWORD = read_local_file(".tests/runbook_tests/auth_password") URL = read_local_file(".tests/runbook_tests/url") DslHTTPEndpoint = Endpoint.HTTP(URL, verify=True, auth=Endpoint.Auth(AUTH_USERNAME, AUTH_PASSWORD))
from calm.dsl.runbooks import read_local_file, basic_cred from calm.dsl.runbooks import CalmEndpoint as Endpoint linux_ip = read_local_file(".tests/runbook_tests/vm_ip") CRED_USERNAME = read_local_file(".tests/runbook_tests/username") CRED_PASSWORD = read_local_file(".tests/runbook_tests/password") LinuxCred = basic_cred(CRED_USERNAME, CRED_PASSWORD, name="linux_cred") LinuxEndpoint = Endpoint.Linux.ip([linux_ip], cred=LinuxCred)
""" Calm DSL While Task Example """ import json from calm.dsl.runbooks import runbook from calm.dsl.runbooks import RunbookTask as Task, Status, RunbookVariable as Variable from calm.dsl.runbooks import CalmEndpoint as Endpoint from calm.dsl.runbooks import read_local_file, basic_cred linux_ip = read_local_file(".tests/runbook_tests/vm_ip") windows_ip = read_local_file(".tests/runbook_tests/windows_vm_ip") CRED_USERNAME = read_local_file(".tests/runbook_tests/username") CRED_WINDOWS_USERNAME = read_local_file(".tests/runbook_tests/windows_username") CRED_PASSWORD = read_local_file(".tests/runbook_tests/password") URL = read_local_file(".tests/runbook_tests/url") AUTH_USERNAME = read_local_file(".tests/runbook_tests/auth_username") AUTH_PASSWORD = read_local_file(".tests/runbook_tests/auth_password") LinuxCred = basic_cred(CRED_USERNAME, CRED_PASSWORD, name="linux_cred") WindowsCred = basic_cred(CRED_WINDOWS_USERNAME, CRED_PASSWORD, name="windows_cred") linux_endpoint = Endpoint.Linux.ip([linux_ip], cred=LinuxCred) windows_endpoint = Endpoint.Windows.ip([windows_ip], cred=WindowsCred) http_endpoint = Endpoint.HTTP( URL, verify=False, auth=Endpoint.Auth(AUTH_USERNAME, AUTH_PASSWORD) ) @runbook
""" Calm VM Endpoint Example with Static Filter """ from calm.dsl.runbooks import read_local_file from calm.dsl.runbooks import basic_cred, Ref from calm.dsl.runbooks import CalmEndpoint as Endpoint CRED_USERNAME = read_local_file(".tests/runbook_tests/username") CRED_PASSWORD = read_local_file(".tests/runbook_tests/password") AHV_LINUX_ID = read_local_file(".tests/runbook_tests/ahv_linux_id") LinuxCred = basic_cred(CRED_USERNAME, CRED_PASSWORD, name="endpoint_cred") AHVStaticVMEndpoint = Endpoint.Linux.vm( vms=[Ref.Vm(name="hitesh1")], cred=LinuxCred, account=Ref.Account("NTNX_LOCAL_AZ"), ) def main(): print(AHVStaticVMEndpoint.json_dumps(pprint=True)) if __name__ == "__main__": main()
""" Calm HTTP Endpoint Sample without Auth """ from calm.dsl.runbooks import read_local_file from calm.dsl.runbooks import CalmEndpoint as Endpoint URL = read_local_file(".tests/runbook_tests/url") DslHTTPEndpoint = Endpoint.HTTP( URL, retries=1, retry_interval=2, timeout=50, verify=True ) def main(): print(DslHTTPEndpoint.json_dumps(pprint=True)) if __name__ == "__main__": main()
""" import uuid import pytest from calm.dsl.runbooks import read_local_file from calm.dsl.runbooks import runbook from calm.dsl.runbooks import ( RunbookTask as Task, RunbookVariable as Variable, basic_cred, ) from calm.dsl.runbooks import CalmEndpoint as Endpoint from utils import read_test_config, change_uuids, get_project_id_from_name linux_ip = read_local_file(".tests/runbook_tests/vm_ip") windows_ip = read_local_file(".tests/runbook_tests/windows_vm_ip") CRED_USERNAME = read_local_file(".tests/runbook_tests/username") CRED_WINDOWS_USERNAME = read_local_file( ".tests/runbook_tests/windows_username") CRED_PASSWORD = read_local_file(".tests/runbook_tests/password") HTTP_AUTH_USERNAME = read_local_file(".tests/runbook_tests/auth_username") HTTP_AUTH_PASSWORD = read_local_file(".tests/runbook_tests/auth_password") HTTP_URL = read_local_file(".tests/runbook_tests/url1") RBAC_PROJECT = read_local_file(".tests/runbook_tests/rbac_project") http_endpoint = Endpoint.HTTP(HTTP_URL, verify=True) LinuxCred = basic_cred(CRED_USERNAME, CRED_PASSWORD, name="endpoint_cred")
""" Calm Runbooks with VM endpoints """ from calm.dsl.runbooks import read_local_file from calm.dsl.runbooks import runbook, Ref from calm.dsl.runbooks import RunbookTask as Task, basic_cred from calm.dsl.runbooks import CalmEndpoint as Endpoint from calm.dsl.builtins.models.helper.common import get_vmware_account_from_datacenter AHV_POWER_ON = read_local_file(".tests/runbook_tests/vm_actions_ahv_on") AHV_POWER_OFF = read_local_file(".tests/runbook_tests/vm_actions_ahv_off") VMWARE_POWER_ON = read_local_file(".tests/runbook_tests/vm_actions_vmware_on") VMWARE_POWER_OFF = read_local_file( ".tests/runbook_tests/vm_actions_vmware_off") CRED_USERNAME = read_local_file(".tests/runbook_tests/username") CRED_PASSWORD = read_local_file(".tests/runbook_tests/password") LinuxCred = basic_cred(CRED_USERNAME, CRED_PASSWORD, name="endpoint_cred") VMWARE_ACCOUNT_NAME = get_vmware_account_from_datacenter() AHVPoweredOnVM = Endpoint.Linux.vm( vms=[Ref.Vm(uuid=AHV_POWER_ON)], cred=LinuxCred, account=Ref.Account("NTNX_LOCAL_AZ"), ) AHVPoweredOffVM = Endpoint.Linux.vm( vms=[Ref.Vm(uuid=AHV_POWER_OFF)], cred=LinuxCred, account=Ref.Account("NTNX_LOCAL_AZ"),