Skip to main content
Question

How to execute a command on Prism Central VM in Blueprint

  • February 15, 2026
  • 0 replies
  • 0 views

In my blueprint, I need to execute a command on Prism Central VM. The command will be a script on Prism Central VM. My blueprint uses the existing Prism Central VM as the substrate. I tried different ways to execute the command but none of them worked. Could you please advise how I could do it? The script I need to run doesn’t have an API counterpart. I can run PC API from the blueprint without problems. Here are the different ways I tried and how they failed.

# SSH Endpoint

PCSSHEndpoint = Endpoint.Linux.ip(

    ["@@{calm_pc_ip}@@"],

    name="PC_SSH_Endpoint",

    port=22,

    cred=SSHCredential,

)

# ============================================================================

# METHOD 1: SSH Endpoint with Target Reference

# ============================================================================

class Method1_SSHEndpointService(Service):

    """

    Method 1: Using SSH endpoint with explicit target reference

   

    Pros: Proper SSH connection setup

    Cons: Failed with "Machine and credential are required for script execution"

          and "ssh: subsystem request failed" errors

    """

    @action

    def RunCommand(name="Method 1 SSH Endpoint"):

        """Execute command via SSH endpoint"""

        Task.Exec.ssh(

            name="SSHWithEndpoint",

            script='echo "=== Method 1: SSH Endpoint ===" \nncli cluster version',

            target=ref(PCSSHEndpoint),

            cred=ref(SSHCredential),

        )

# ============================================================================

# METHOD 2: SSH Without Endpoint (Local Execution)

# ============================================================================

class Method2_SSHLocalService(Service):

    """

    Method 2: SSH task without endpoint (attempting local execution)

   

    Pros: Simpler syntax

    Cons: Still tried to use SSH subsystem, failed with "subsystem request failed"

     """

    @action

    def RunCommand(name="Method 2 SSH Local"):

        """Execute command locally via SSH task"""

        Task.Exec.ssh(

            name="SSHLocal",

            script='#!/bin/bash\necho "=== Method 2: SSH Local ==="\nncli cluster version',

        )

# ============================================================================

# METHOD 3: Escript with Subprocess

# ============================================================================

class Method3_SubprocessService(Service):

    """

    Method 3: Using Python subprocess module in escript

   

    Pros: Standard Python approach for running commands

    Cons: subprocess module not available in Calm escript environment

          Error: "No module named 'subprocess'"

    """

    @action

    def RunCommand(name="Method 3 Subprocess"):

        """Execute command using subprocess"""

        Task.Exec.escript(

            name="SubprocessExec",

            script='import subprocess\n\nprint("=== Method 3: Subprocess ===")\nresult = subprocess.run(["ncli", "cluster", "version"], capture_output=True, text=True)\nprint(result.stdout)',

        )

# ============================================================================

# METHOD 4: Escript with Paramiko

# ============================================================================

class Method4_ParamikoService(Service):

    """

    Method 4: Using paramiko library for SSH in escript

   

    Pros: Full-featured SSH library

    Cons: paramiko not available in Calm escript environment

          Error: "No module named 'paramiko'"

    """

    @action

    def RunCommand(name="Method 4 Paramiko"):

        """Execute command using paramiko"""

        Task.Exec.escript(

            name="ParamikoExec",

            script='import paramiko\n\nprint("=== Method 4: Paramiko ===")\nssh = paramiko.SSHClient()\nssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())\nssh.connect("@@{calm_pc_ip}@@", username="admin", password="Delluser@123")\nstdin, stdout, stderr = ssh.exec_command("ncli cluster version")\nprint(stdout.read().decode())\nssh.close()',

        )

# ============================================================================

# METHOD 5: Escript with os.system()

# ============================================================================

class Method5_OsSystemService(Service):

    """

    Method 5: Using os.system() for direct command execution

   

    Pros: Simple, built-in Python function

    Cons: os module not available in Calm escript environment

          Error: "No module named 'os'" or similar restriction

    """

 

    @action

    def RunCommand(name="Method 5 os_system"):

        """Execute command using os.system()"""

        Task.Exec.escript(

            name="OsSystemExec",

            script='import os\n\nprint("=== Method 5: os.system() ===")\nos.system("ncli cluster version")\nos.system("cluster status")',

        )

# ============================================================================

# METHOD 6: Shell Script with Task.Exec.ssh()

# ============================================================================

class Method6_ShellScriptService(Service):

   

    """

    Method 6: Pure bash script using Task.Exec.ssh() without target

   

    Pros: No Python dependencies, native shell execution

    Cons: Still uses SSH subsystem, failed with "subsystem request failed"

    """

 

    @action

    def RunCommand(name="Method 6 Shell Script"):

        """Execute bash script"""

        Task.Exec.ssh(

            name="ShellScript",

            script='#!/bin/bash\necho "=== Method 6: Shell Script ==="\nncli cluster version\nncli cluster info\ncluster status',

        )