VMware Aria Automation Orchestrator

 View Only
  • 1.  Tip: Temporary Data Storage in a PowerShell Container at Runtime

    Posted Mar 01, 2023 10:07 AM
    Edited by Stefan Schnell May 07, 2024 12:28 AM

    Based on the discussion about Access vRO Filesystem using Polyglot from  here an approach how to store data in a PowerShell container at the runtime.

    The interesting thing about this approach is that the PowerShell CmdLets do not work, but calling the dotNET methods works fine. It's not clear to me if it is a bug or a feature.

    Another interesting thing is that it seems to be necessary to create a directory, in this example temp. Writing directly to /run/vco-polyglot/function did not succeed in my case. 

    Here the commented code:

     

    # Begin-----------------------------------------------------------------
    
    function Handler($context, $inputs) {
      $inputsString = $inputs | ConvertTo-Json -Compress;
      # Write-Host "Inputs were $($inputsString)";
    
      # Create temp directory in /run/vco-polyglot--------------------------
      [System.String]$directory = "temp";
      # New-Item -ItemType "directory" -Force -Path "$($directory)";
      if ([System.IO.Directory]::Exists($directory) -eq $false) {
        Write-Host "Create directory $($directory)";
        [System.IO.Directory]::CreateDirectory($directory);
      }
    
      # Create file Test.txt in temp directory with text--------------------
      [System.String]$writeText = "This is a test";
      [System.String]$path = "$($directory)/Test.txt";
      [System.IO.File]::WriteAllText($path, $writeText);
    
      # List all files in temp directory------------------------------------
      [System.String[]]$files = [System.IO.Directory]::GetFiles($directory);
      forEach ($file in $files) {
        Write-Host $file;
      }
    
      # Read the content from the Text.txt file in temp directory-----------
      [System.String]$readText = [System.IO.File]::ReadAllText($path);
      Write-Host $readText;
    
      # Delete directory temp-----------------------------------------------
      if ([System.IO.Directory]::Exists($directory)) {
        Write-Host "Delete directory $($directory)";
        [System.IO.Directory]::Delete($directory, $true);
      }
    
      $output = @{status = "done"}
      return $output;
    }
    
    # End-------------------------------------------------------------------

     

    Here my test result with the vRealize Automation 8.5.1.18666:

    fileInPSContainer.jpg

    Conclusion

    In a PowerShell container we have the possibility, by using dotNET methods, to access the file system in the path /run/vco-polyglot/function. This can be very helpful for certain requirements. However, we must not forget that the container with its content is also deleted at the end of the automation process. That is why this approach can only be used for temporary storage.



  • 2.  RE: Tip: Temporary Data Storage in a PowerShell Container at Runtime

    Posted Sep 18, 2023 03:43 PM

    The root filesystem of the container is writeable:

    function Handler($context, $inputs) {
    
        $dir = New-Item -ItemType "directory" -Force -Path "/mydata"
        Get-Date | Out-File -FilePath "/mydata/date.txt"
        Get-Content -Path "/mydata/date.txt" | Write-Host
    
        return @{}
    }

    xian__0-1695051754586.png

    You can use it in Python as well, if needed.



  • 3.  RE: Tip: Temporary Data Storage in a PowerShell Container at Runtime

    Posted Sep 20, 2023 01:31 PM

    Hello ,

    thank you very much for your reply and experience sharing.

    Interesting that it works now. I tried it at HOL with release 8.5.1 a longer time ago and I tried it now with release 8.13.1. It didn't work then, but now it works, good to know.

    Best regards
    Stefan



  • 4.  RE: Tip: Temporary Data Storage in a PowerShell Container at Runtime

    Posted May 13, 2024 09:14 AM

    Hi Krisztian,

    What is the location of root file system?. is it "/" or '/root'?

    Regards,

    Aravind




  • 5.  RE: Tip: Temporary Data Storage in a PowerShell Container at Runtime

    Posted May 22, 2024 09:26 AM

    Hi,

    it's "/"




  • 6.  RE: Tip: Temporary Data Storage in a PowerShell Container at Runtime

    Posted May 22, 2024 09:26 AM

    Hi Aravind,

    it's /

    HTH




  • 7.  RE: Tip: Temporary Data Storage in a PowerShell Container at Runtime

    Posted May 22, 2024 09:26 AM

    Hi Aravind,

    it's "/"

    Hope that helps.