Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when working with endpoint targets in blueprint tasks #177

Closed
nx-sbourdeaud opened this issue May 25, 2021 · 2 comments
Closed

Errors when working with endpoint targets in blueprint tasks #177

nx-sbourdeaud opened this issue May 25, 2021 · 2 comments
Labels
bug Something isn't working P1 Critical

Comments

@nx-sbourdeaud
Copy link

I have a blueprint which is targeting an existing endpoint in a pre-create task.
When I decompile that blueprint using calm-dsl, it targets the substrate instead of the existing endpoint.

In a blueprint, if I use syntax like:
target_endpoint=Endpoint.use_existing(CALM_UTILITY_ENDPOINT),
in the blueprint.py file in the pre_create action definition and I then try to create the blueprint with calm create bp, I get the following error:
[ERROR] [calm.dsl.builtins.models.runbook:134] type object '_Endpointbcec9383' has no attribute 'use_existing'
This is using calm.dsl==3.0.0a0 (latest available as of today afaik)

@nx-sbourdeaud
Copy link
Author

I was missing the following import statement for the calm create error:
from calm.dsl.runbooks import CalmEndpoint as Endpoint

The decompile error/issue is still accurate and needs to be resolved.

abhijeetkaurav1st pushed a commit that referenced this issue Mar 9, 2023
(cherry picked from commit eaeed628ba19b6b1435e2da072f48f004eb4c0a5)
@abhijeetkaurav1st abhijeetkaurav1st added bug Something isn't working P1 Critical labels Mar 17, 2023
dwivediprab pushed a commit that referenced this issue Mar 15, 2024
### Summary
Added support in action tasks to render endpoints.
When decompiling tasks, if they contain `exec_target_reference` we
should use those instead of the `target_any_local_reference` to get the
endpoint.
open issue: #177

decompiled the below blueprint with Task1 having an explicit endpoint
and Task2 having empty endpoint

![Screenshot 2023-10-09 at 11 27 42
AM](https://github.com/ideadevice/calm-dsl/assets/89129891/82f68ab9-b625-4108-aa5a-9938fadac061)

result of decompile:
```
# THIS FILE IS AUTOMATICALLY GENERATED.
# Disclaimer: Please test this file before using in production.
"""
Generated blueprint DSL (.py)
"""

import json  # no_qa
import os  # no_qa

from calm.dsl.builtins import *  # no_qa
from calm.dsl.runbooks import CalmEndpoint as Endpoint

# Secret Variables

BP_CRED_c1_PASSWORD = read_local_file("BP_CRED_c1_PASSWORD")

# Credentials
BP_CRED_c1 = basic_cred(
    "admin",
    BP_CRED_c1_PASSWORD,
    name="c1",
    type="PASSWORD",
    default=True,
)
# Endpoints
ep2 = Endpoint.use_existing("ep2")

class Service1(Service):

    pass

class vmcalm_timeResources(AhvVmResources):

    memory = 1
    vCPUs = 1
    cores_per_vCPU = 1
    disks = [
        AhvVmDisk.Disk.Scsi.cloneFromImageService(
            "Centos7HadoopMaster.qcow2", bootable=True
        )
    ]
    nics = [
        AhvVmNic.NormalNic.ingress(
            "abc", cluster="auto_cluster_prod_4f683249d95b", ip_endpoints=["10.1.0.9"]
        ),
        AhvVmNic.NormalNic.ingress(
            "vlan.154", cluster="auto_cluster_prod_4f683249d95b"
        ),
    ]

class vmcalm_time(AhvVm):

    name = "vm-@@{calm_time}@@"
    resources = vmcalm_timeResources
    cluster = Ref.Cluster(name="auto_cluster_prod_4f683249d95b")

class VM1(Substrate):

    account = Ref.Account("NTNX_LOCAL_AZ")
    os_type = "Linux"
    provider_type = "AHV_VM"
    provider_spec = vmcalm_time

    readiness_probe = readiness_probe(
        connection_type="SSH",
        disabled=True,
        retries="5",
        connection_port=22,
        address="@@{platform.status.resources.nic_list[0].ip_endpoint_list[0].ip}@@",
        delay_secs="0",
    )

class Package1(Package):

    services = [ref(Service1)]

class d2d34557_deployment(Deployment):

    min_replicas = "1"
    max_replicas = "1"
    default_replicas = "1"

    packages = [ref(Package1)]
    substrate = ref(VM1)

class Default(Profile):

    environments = [Ref.Environment(name="Default Environment")]
    deployments = [d2d34557_deployment]

    @action
    def UntitledAction1(name="Untitled Action1"):

        CalmTask.Exec.ssh(
            name="Task1",
            filename=os.path.join(
                "scripts", "Profile_Default_Action_UntitledAction1_Task_Task1.sh"
            ),
            target=ref(ep2),
        )

        CalmTask.Exec.ssh(
            name="Task2",
            filename=os.path.join(
                "scripts", "Profile_Default_Action_UntitledAction1_Task_Task2.sh"
            ),
            target=ref(Service1),
        )

class test_nic_bp(Blueprint):

    services = [Service1]
    packages = [Package1]
    substrates = [VM1]
    profiles = [Default]
    credentials = [BP_CRED_c1]

class BpMetadata(Metadata):

    categories = {"TemplateType": "Vm"}

```

(cherry picked from commit 2e2b06e61c2cf9bc52f725db0f83d46fbfd5d190)
@dwivediprab
Copy link
Contributor

Issue is fixed in DSL v3.7.2.2 release, Hence closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1 Critical
Projects
None yet
Development

No branches or pull requests

3 participants