Makemanaged API Call

I am using the Morpheus API, using the pyMorpheus Python API wrapper. I am trying to convert a bunch of VMs to managed en masse, so that I don’t have to manually add 60+ VMs that are being provisioned into vCenter by an external vendor’s provisioning system.

The code to make the VM managed is working, but I need to be able to set the Instance Type, the Layout, Plan, etc. which is not working. So the VMs are coming in as vCenter VMs, when I want/need them to be Perimeta Metaswitch VMs (I have already added that Instance Type, Layout, etc).

The inability I am having to pull this off, I am unsure if this is an API limitation or defect or if there is something I am not doing correctly in the API.

Here is an example of what I am doing in the API:

options = [('name', 'Morpheus-Migrate-Test-VM9')]
results = morpheus.call("get", "instances", options=options)
pprint.pprint("GET INSTANCE RESULTS")
pprint.pprint(results)

pprint.pprint("Updating Instance")
for instance in results['instances']:
   instnc = {
      "instance": {
         "id": instance["id"],
         "group": {
            "id": 1,
         },
         "instanceType": {
            "id": 114,
            "code": "FORTIMANAGER",
            "category": "network",
            "name": "Fortinet FortiManager"
         },
         "layout": {
            "id": 1402,
            "name": "Fortinet FortiManager Std Layout",
            "provisionTypeId": 6,
            "provisionTypeCode": "vmware"
        }
     }
   }
   jinst = json.dumps(instnc)
   append = "instances" + "/" + str(instance["id"])
   options = []
   results = morpheus.call("put", append, options=options, jsonpayload=jinst)
   pprint.pprint("PUT INSTANCES RESULTS")
   pprint.pprint(results)

Hi there,

The options you are trying to configure should be done within the make-managed or install-agent API calls. These options are not currently documented so I will get an example here and then add the required options to our documentation.

Thanks!

Hi @Wittling_Mark_CCI-At,

Below is an example body for a PUT /api/servers/<serverid>/install-agent or /api/servers/<serverid>/make-managed API call.

{
  "server": {
    "serverOs": {
      "id": 30
    },
    "sshUsername": "user",
    "sshPassword": "password",
    "config": {
        "customOptions": {"customOption1":"hello world!", "customOption2" : "good bye!"},
        "metadata" : [
            {"name":"tag1", "value": "test1"},
            {"name":"tag2", "value": "test2"}
        ]
    },
    "provisionSiteId": 19,
    "account" : {
        "id": 1
    },
    "plan" : {
        "id": 1953
    },
    "sshPort" : 22
  },
  "instanceTypeId": 13,
   "layout" : 410,
   "installAgent" : false,
   "manualAgentInstall": true
}

I will work to get this documented on our API docs and included in our CLI options.

Apologies for the wait.

Kind regards,

Chris

Please also note that the metadata updates will be supported from 5.4.16 onwards.

Cool. Let me code that up today and see if that helps get the layout and plan set the way we want it! Thanks!

Did some more work on this. What I am able to do now, is to create an “Instance”, and it now has the right group, plan, layout. That’s awesome. It shows up in the GUI.

I noticed in the GUI, that the Cloud was blank, and the icon for Discovered/Managed was still the Discovered icon.

As I was investigating this from jumping the json of the newly created instance, I am noticing that while the instance is created, it is not mapped to a Cloud, nor is it mapped to a Server. Some other fields are also blank as well (Containers, ConnectionInfo, and the ContainerDetails which has all of the server stuff listed.

Here is what the GUI looks like:

I actually tried to update the instance with the Group, Cloud and the Server ID.
{"instance": {"id": 149, "group": {"id": 3}, "cloud": {"id": 4}, "servers": [359]}}

This API call takes and applies the Group. But it ignored the cloud and servers array I added to the json.

'Invoking Instances API Call to update instance with new group'
'Update Instances API Call Results...'
{'instance': {'accountId': 1,
              'apps': [],
              'autoScale': False,
              'config': {'brownfield': True, 'customOptions': {}},
              'configGroup': None,
              'configId': None,
              'configRole': None,
              'connectionInfo': [],
              'containers': [],
              'controllers': [],
              'coresPerSocket': 1,
              'createdBy': {'id': 1, 'username': 'admin'},
              'currentDeployId': None,
              'customOptions': {},
              'dateCreated': '2023-03-01T20:39:41Z',
              'description': None,
              'domainName': None,
              'environment': None,
              'environmentPrefix': None,
              'errorMessage': None,
              'evars': [],
              'expireCount': 0,
              'expireDate': None,
              'expireDays': None,
              'expireWarningDate': None,
              'expireWarningSent': False,
              'firewallEnabled': False,
              'group': {'id': 3, 'name': 'Voice Engineering SBC'},
              'hostName': None,
              'hourlyCost': 0.0,
              'hourlyPrice': 0.0,
              'id': 149,
              'instanceContext': None,
              'instancePrice': None,
              'instanceThreshold': None,
              'instanceType': {'category': 'network',
                               'code': 'METASWITCH',
                               'id': 116,
                               'name': 'Metaswitch Perimeta 5.1'},
              'instanceVersion': '5.1',
              'interfaces': [],
              'isBusy': None,
              'isScalable': None,
              'labels': [],
              'lastUpdated': '2023-03-01T20:39:41Z',
              'layout': {'id': 1404,
                         'name': 'Metaswitch ISC Layout',
                         'provisionTypeCode': 'vmware',
                         'provisionTypeId': 6},
              'locked': False,
              'maxCores': 1,
              'maxCpu': None,
              'maxMemory': 4294967296,
              'maxStorage': 8589934592,
              'name': 'Morpheus-Migrate-Test-VM14',
              'networkLevel': 'container',
              'notes': None,
              'owner': {'id': 1, 'username': 'admin'},
              'plan': {'code': 'VSBCISCMSC20440',
                       'id': 480,
                       'name': 'VSBC-METASWITCH-2-04-40'},
              'powerSchedule': None,
              'removalDate': None,
              'renewDays': None,
              'servers': [],
              'shutdownCount': 0,
              'shutdownDate': None,
              'shutdownDays': None,
              'shutdownRenewDays': None,
              'shutdownWarningDate': None,
              'shutdownWarningSent': False,
              'status': 'running',
              'statusDate': None,
              'statusEta': None,
              'statusMessage': None,
              'statusPercent': None,
              'tags': [],
              'tenant': {'id': 1, 'name': 'psp6dsnfvmorf-admin'},
              'userStatus': None,
              'uuid': '1e7ffd83-a0c5-4338-9a71-dff8ac44e5de',
              'volumes': []},
 'success': True}

So the net effect here, is that it is creating this floating concept of an instance, that isn’t properly tied or connected to the other relational objects (container, server, etc).

Okay. Problem solved, I think.

The reason the Server wasn’t being populated, was because I had not assigned a Node Type (which has a Virtual Image) to the Layout. I can see why the Node Type/Virtual Image would need to be there for Provisioning, but given that I am only “converting” an already-running Discovered instance to Managed, I am not sure why it should be necessary, so I didn’t populate that.

So. I exported the OVF from the other environment, saved it, re-uploaded it to the new vCenter environment, converted it to a template, then added the Virtual Image mapping, then added the Node Type. And voila’ the make-managed API call worked fine.

Another thing to look into, is that Metaswitch uses the same VM template, to spin up the ISC and MSC variants of their solution. So I have, in Morpheus, something that looks like this:

Instance Type=Metaswitch Perimeta 5.1
Layout=Metaswitch ISC
NodeType=Metaswitch ISC → points to Virtual Image MetaswitchPerimeta51
Layout=Metaswitch MSC
NodeType=Metaswitch MSC → points to the SAME virtual image MetaswitchPerimeta51 above

I need to make sure Morpheus is going to allow me to use two Layout/NodeTypes to use the SAME virtual image. It seems to me like it is working, so I am optimistic about that.