VMware Aria

  • 1.  Create vRO python script to create vm snapshot - error get vm details using composite type

    Posted Oct 08, 2024 06:11 PM

    I'm ceating a vRO python script to create vm snapshot,

    I used composite type to select vm from vcenter.

    As I got errors, I only tested to print the input values are correct

    Code:

    from pyVmomi import vim
    def handler(context, inputs):

        print(inputs)
        print(context)
        vm_n = inputs['vmName']
        s_s_n = inputs['sn_name']
        d = inputs['description']
        print (vm_n, s_s_n, d)

    I got the following log:

    2024-10-07 13:01:04.909 +03:00info__item_stack:/item1
    2024-10-07 13:01:08.723 +03:00info{'sn_name': 'vro', 'description': 'this snapshot was created by vRO'}
    2024-10-07 13:01:08.724 +03:00info{'executionId': '3188fb5c-e51f-49f0-be0b-648826ef02e0', 'returnType': None, 'vcoUrl': 'http://localhost:8280/vco', 'getToken': <function getTokenFactory.<locals>.getToken at 0x7f38ce5b9c60>}
    2024-10-07 13:01:08.725 +03:00errorTraceback (most recent call last):
    2024-10-07 13:01:08.729 +03:00error File "/run/vco-polyglot/index.py", line 110, in <module>
    2024-10-07 13:01:08.730 +03:00error ret = handler(context, inputs)
    2024-10-07 13:01:08.731 +03:00error File "/run/vco-polyglot/function/handler.py", line 8, in handler
    2024-10-07 13:01:08.732 +03:00error vm_n = inputs['vmName']
    2024-10-07 13:01:08.733 +03:00errorKeyError: 'vmName'
    2024-10-07 13:01:09.833 +03:00errorError in (Workflow:create vm snapshot with python / Scriptable task (item1)#12759) Wrapped ch.dunes.scripting.server.polyglot.PolyglotRunnerException: 'vmName'
    2024-10-07 13:01:09.880 +03:00errorWorkflow execution stack: *** item: 'create vm snapshot with python/item1', state: 'failed', business state: 'null', exception: 'Wrapped ch.dunes.scripting.server.polyglot.PolyglotRunnerException: 'vmName' (Workflow:create vm snapshot with python / Scriptable task (item1)#12759)' workflow: 'create vm snapshot with python' (70b213d4-e274-443f-8ea9-8035369e5c8f) | 'attribute': name=vm_name_tmp type=string value= | 'input': name=vmName type=VC:VirtualMachine value=dunes://service.dunes.ch/CustomSDKObject?id='10.34.12.20%2Cid:vm-25486'&dunesName='VC:VirtualMachine' | 'input': name=sn_name type=string value=vro | 'input': name=description type=string value=this snapshot was created by vRO | 'output': name=snapshotName type=string value=null *** End of execution stack.
    Any advice how to use composite type in python script?
    Thanks


  • 2.  RE: Create vRO python script to create vm snapshot - error get vm details using composite type
    Best Answer

    Posted Oct 11, 2024 12:37 AM
    Edited by MOHAMED ZAGHLOUL Oct 13, 2024 04:23 AM

    Hello @MOHAMED ZAGHLOUL,

    composite types in Python are dictionaries. You can use the following approach to get the name of a VM from VC:VirtualMachine object:

    import json
    
    def handler(context, inputs):
    
        print inputs["in_vm"]["name"]
    
        outputs = {
            "status": "done"
        }
    
        return outputs

    This works as an action.

    In a scriptable task of a workflow the same approach is not possible, inputs is empty.

    Unfortunately, I don't have an answer to that at the moment. But it seems that complex data types are not supported in this scenario.

    I tried it on the same way described here in the blog What's new in vRealize Orchestrator 8.1 and with the string data type it works.

    As workaround you can build an action, as described above, and use it in the workflow as an action element, this works without any problems.

    Best regards
    Stefan



    ------------------------------
    More interesting information at https://blog.stschnell.de
    ------------------------------



  • 3.  RE: Create vRO python script to create vm snapshot - error get vm details using composite type

    Posted Oct 13, 2024 04:28 AM

    Hello Stefan Schnell

    I tested it using the workaround, used it in a workflow as an action element, and it works fine.

    Thanks for your help




  • 4.  RE: Create vRO python script to create vm snapshot - error get vm details using composite type

    Posted Oct 12, 2024 11:21 AM

    As far as I know, this is correct.  I have typically used a Native Javascript action to pull out the fields I wanted from the complex object, and then passed those into the other languages for processing.