How can I find out the actual Tenant and read the Customer Number?

We are running a Master Tenant and several Sub Tenants. All tenants are created with the Advanced Options of Account Number, Account Name and Customer Number. We need this information very early in a Provisiong Workflow - Configuration Phase to set a Hostname based on the Customer Number for the Spec.

We are running a Powershell script in that Workflow and read the Customer Number with a Rest API call on the endpoint “/api/accounts&name=customerName”. Unfortunately, we only found out how to fill the variable customerName manually before the script runs - that is, we put in the appropriate Tenant Name from case to case depending on the Tenant where we are logged in…

We could not figure out how to read the actual Tenant Name where we are logged into automatically. Within “Edit Task” of the Powershell script we saw variables like <%=tenant%> or <%=account%>, but we could not manage to deliver output from those.

Is there any way to find out the Tenant Name where I am actually logged in and read the Customer Number, both automatically in a script?

Any idea or help is greatly appreciated!

Thank you,
Kai

Hi Kai. It looks like accountNumber is available as a pre-provision var for instance and host naming, so could a hostname policy help, or at least give you the data and you then mutate it?

https://docs.morpheusdata.com/en/latest/troubleshooting/Variables_Examples.html?highlight=variables#pre-provision-vars

I’m sure I’ve missed some of the nuance, but just wanted to flag that, in case you haven’t seen the resource.

accountName, accountNumber and customerNumber, all three are available as pre-provision vars.

2 Likes

Hello Ollie,
hello Deepti,

Thank you for your very quick response. I will check this out and come back here to mark it as solution as early as I got it managed. I know, you already point in the right direction …

Thank you,
Kai

1 Like

Hi again,

I have managed to use the variables ${accountName} or ${customerNumber} within an Instance Naming Policy - but I cannot find a way to put the same or similar variables in a Powershell script and use it in the Configuration Phase of a Provisioning Workflow.

Since this script is a two line script like the following, can you try to get it running:

$customerName = ${accountName}
Write-Output ("Customer Name: " + $customerName)

The script like above runs without any accountName filled …

What I had in mind, was using a naming policy, and then parsing it from the spec in the config phase

For example in Python, printing the morpheus object I see there is both hostName and computedHostName with the policy implemented.

print(morpheus)

Gives me this:

{
   "spec":{
      "hostName":"${customerNumber}-${cloudName.toLowerCase()}-${instance.instanceContext.toLowerCase()}-${groupCode}-${type.toLowerCase()}-${sequence+100} ",
      "computedHostName":"99999-vmware-1-dev-all-clouds-ubuntu-102-",

    ....
    }
}

The aim would be to strip the customerNumber from the computed hostname and use as required.

Like, you I can’t see a way to get customerNumber, accountNumber, or accountName independently of using them in a naming policy.

1 Like

Hi Ollie,

I see your answer as solution, since one could use this way to extract the customerNumber in a script now and move on in the same script … Thank you.

Although I am also thinking about raising an idea in the appropriate section of this forum to find any easier way to read the information of accountName, accountNumber and customerNumber from anywhere at any time, since these values are really independent of any other component like an Instance, App, Cloud, …

Thank you,
Kai

1 Like

I agree, it would be nice as a readily available variable. How I’ve used this in PowerShell:

$morphUrl = "<%=morpheus.applianceUrl%>"
$morphToken  = "<%=morpheus.apiAccessToken%>"
$morphTenant = "<%=accountId%>"
$headers=@{}
$headers.Add("accept", "application/json")
$headers.Add("authorization", "Bearer $morphToken")

#Print Customer Number
((Invoke-WebRequest -Uri "$($morphUrl)api/accounts/$morphTenant" -Method GET -Headers $headers).content | ConvertFrom-Json).account.customerNumber
1 Like

Hi Chris,

I have tested the code lines within my environment and it works out fine! Hence, this is also a solution to the question - or like the music group U2 would say: Even Better Then The Real Thing.

Thank you,
Kai

1 Like