HPE Morpheus Enterprise
1827712 Members
2616 Online
109967 Solutions
New Discussion

Re: Edit Instance Configuration Before Deployment

 
SOLVED
Go to solution
KoreyG
Valued Contributor

Edit Instance Configuration Before Deployment

Good morning!

I’m attempting to edit a GCP instance deployment to attach a public IP in the Configuration Phase of a Workflow using Python. I feel I’m close but something is just not clicking for it to stick I think. This is my example code with the IP changed (task outputs as JSON):

import json
newIP="255.255.255.255"
morpheus['spec']['config']['externalIpType']=newIP
morpheus['spec']['server']['config']['externalIpType']=newIP
morpheus['spec']['customOptions']['externalIpType']=newIP
json.dumps(morpheus)

I’ve also tried not doing the output of JSON and just modifying the dictionary. Through my various tests, the config data from using the GUI to choose the IP and from injecting my code above, end up being almost identical (except for the unique values) at the end of the task output.

If I print the morpheus variable on the instance after deployment using a task, I see the externalIpType was not set like it showed in the task output. Is there a way to “apply” the changes that I’m missing?

15 REPLIES 15
Not applicable

Re: Edit Instance Configuration Before Deployment

I have time in an hour if you want to look at it together.

cbunge
HPE Pro

Re: Edit Instance Configuration Before Deployment

it’s literally complaining on step 1 saying it can’t monitor for keywords. Wonder if any flow is triggering now

KoreyG
Valued Contributor

Re: Edit Instance Configuration Before Deployment

Maybe they are having an issue right now. I can try it again later or tomorrow.

cbunge
HPE Pro

Re: Edit Instance Configuration Before Deployment

last successful and history don’t align either

cbunge
HPE Pro

Re: Edit Instance Configuration Before Deployment

odd… I honestly think M$ broke flows

Not applicable

Re: Edit Instance Configuration Before Deployment

Has to be its own comment?

KoreyG
Valued Contributor

Re: Edit Instance Configuration Before Deployment

Mine is running.  I don't trigger on keywords/Teams though:
KoreyG
Valued Contributor

Re: Edit Instance Configuration Before Deployment

Thanks, Jabro! I'll take you up on that. I'll hit you up in a little while.
Not applicable

Re: Edit Instance Configuration Before Deployment

better go check mine

KoreyG
Valued Contributor

Re: Edit Instance Configuration Before Deployment

Mine was.

cbunge
HPE Pro

Re: Edit Instance Configuration Before Deployment

Not applicable

Re: Edit Instance Configuration Before Deployment

I have played a bit with the externalIp and I think I have some code on it somewhere

Not applicable

Re: Edit Instance Configuration Before Deployment

huh.
Season 5 Whatever GIF by Paramount+ (GIF Image)
KoreyG
Valued Contributor
Solution

Re: Edit Instance Configuration Before Deployment

Thanks for the help, Jabro! Here is the final result that worked, for getting the changes to apply. Basically I was missing the print() so the output would go to standard out. This would require the output type of the task to be JSON.

import json
newIP="255.255.255.255"
morpheus['spec']['config']['externalIpType']=newIP
morpheus['spec']['server']['config']['externalIpType']=newIP
morpheus['spec']['customOptions']['externalIpType']=newIP
print(json.dumps(morpheus))

Below is another example using PWSH. Note that Python stores all of the values in a single variable of morpheus but other languages can work differently. In this case, PWSH stores the spec as its own variable, so we work with it directly:

  $newIP = '255.255.255.255'
  $configObject = '<%=spec.encodeAsJson().toString()%>' | ConvertFrom-Json -Depth 10

  $configObject.config.externalIpType = $newIP
  $configObject.server.config.externalIpType = $newIP
  $configObject.customOptions.externalIpType = $newIP

  $configJson = $configObject | ConvertTo-Json -Depth 10

  $spec = @"
  {
      "spec": $configJson
  }
  "@

  Write-Host $spec -NoNewline
Not applicable

Re: Edit Instance Configuration Before Deployment

Similar one with the logic of a selection of a custom option to set value of another which is hidden input type

import json
# Declare the lifecycle and OU Name option list as a variable with contents
updatedLifecycle={"P":"PROD", "U":"UAT"}
updatedOU={"P":"Prod", "U":"NON-Prod"}

configspec = morpheus['spec']
env=configspec['customOptions']['Env']

# Check if the value if env is present in lifecycle and OU Name
if env in updatedLifecycle and env in updatedOU:
    # Set the value of lifecycle and ou name option type based on the value of env selected by user
    configspec['config']['customOptions']['LifecycleRole'] = updatedLifecycle[env]
    configspec['server']['config']['customOptions']['LifecycleRole'] = updatedLifecycle[env]
    configspec['customOptions']['customOptions']['LifecycleRole'] = updatedLifecycle[env]
    configspec['config']['customOptions']['LifecycleRole'] = updatedLifecycle[env]
    configspec['customOptions']['LifecycleRole'] = updatedLifecycle[env]
    configspec['config']['customOptions']['OUName'] = updatedOU[env]
    configspec['server']['config']['customOptions']['OUName'] = updatedOU[env]
    configspec['customOptions']['customOptions']['OUName'] = updatedOU[env]
    configspec['config']['customOptions']['OUName'] = updatedOU[env]
    configspec['customOptions']['OUName'] = updatedOU[env]
    newspec = {}
    newspec['spec'] = configspec
    print(json.dumps(newspec))