VMware Aria Automation Orchestrator

 View Only
Expand all | Collapse all

How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

  • 1.  How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 17, 2019 09:23 AM

    I have the following problem :

    Some of my colleagues have deploy some VMs by vRA and change the IP address in the Guest OS after the deployment.

    So the IP address displayed on the VM properties is not correct, and it's the same for the IP address reserved in the network profile range.

    I know how to update the IP address displayed in the properties, it's quite simple, I have build a workflow to update the custom property "VirtualMachine.Network0.Address".

    But this action doesn't update the IP address in the network profile ip addresses range, so I have to do it.

    I tried to do this by REST API like this:

    1) First, I get the network profile properties in an XML object :

    GET /iaas-proxy-provider/api/network/profiles/"networkprofileID"

    {
      "@type": "ExternalNetworkProfile",
      "id": "4860fc89-1518-4a0e-8047-7162a1bc61c8",
      "name": "TEST-NET1",
      "description": "Configured by vRO",
      "createdDate": "2018-01-17T14:37:03.000Z",
      "lastModifiedDate": "2018-01-17T14:37:03.000Z",
      "isHidden": false,
      "definedRanges": [
        {
          "id": "d5e88c81-3195-4afb-83db-6ad0cca88ac3",
          "name": "range",
          "description": "Configured by vRO",
          "beginIPv4Address": "1.252.128.34",
          "endIPv4Address": "1.252.128.62",
          "state": "UNALLOCATED",
          "createdDate": "2018-01-17T14:37:03.000Z",
          "lastModifiedDate": "2019-05-16T15:27:45.000Z",
          "definedAddresses": [

          {

              "id": "675e6ec3-a498-44da-a16f-52d92fb150f0",

              "staticIPv4RangeId": "d5e88c81-3195-4afb-83db-6ad0cca88ac3",

              "IPv4Address": "1.252.128.38",

              "IPSortValue": 33325094,

              "state": "UNALLOCATED",

              "stateValue": 1,

              "createdDate": "2018-01-17T14:37:03.000Z",

              "lastModifiedDate": "2018-01-17T14:37:03.000Z"

            },
            {
              "id": "f80cc5ed-6be6-4845-b1cb-3ea8b3036a0e",
              "staticIPv4RangeId": "d5e88c81-3195-4afb-83db-6ad0cca88ac3",
              "virtualMachineId": "6526b667-fcf9-4be9-aa47-98c0dc95a79a",
              "virtualMachineName": "test-000094",
              "IPv4Address": "1.252.128.45",
              "IPSortValue": 33325101,
              "state": "ALLOCATED",
              "stateValue": 0,
              "createdDate": "2018-01-17T14:37:03.000Z",
              "lastModifiedDate": "2018-01-17T14:37:03.000Z"
            },

    2) Then I parse the "defineAddresses" section and  update the XML subnode object to free an IP address like :

    defineAddress.state              = "UNALLOCATED"

    defineAddress.stateValue         = 1

    delete defineAddress.virtualMachineId

    delete defineAddress.virtualMachineName

    3) And a run a PUT REST API request to update the network profile, the return code is 204 meaning than the update is succeed,  BUT if I perform a new GET or check in the vRA web  console, the update was not performed.

    Any idea on this behavior ?

    is it possible to perform an ip address allocation or unallocation by another way or trick ?  (excepted by a SQL query in the database of course, because I find this method ugly and unsupported)

    Thanks for your help

    Regards



  • 2.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 17, 2019 12:20 PM

    There's not a supported way to do this. That's one reason network profiles are too basic to be used in production. Your real problem is of course this:

    Some of my colleagues have deploy some VMs by vRA and change the IP address in the Guest OS after the deployment.

    They shouldn't be doing that, so tell them to stop :smileyhappy: Seriously though, that's not what a cloud management platform was built to allow (people going behind the scenes making custom changes).



  • 3.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 20, 2019 07:30 AM

    Hi daphnissov


    I'm totally agree with you, my colleagues shouldn't change the IP address in the Guest OS,

    but ... they did,  and now i have to fix their foolishness.

    Maybe moving from internal IPAM to an external could be be the best solution, but currently it seems to me to complex to migrate 3000 Vms  (only 200 vms are concerned)

    So, any other proposition ?

    Thanks



  • 4.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 20, 2019 12:18 PM

    Sorry, I don't have any good ideas. Network profiles are just so basic that there's not a whole lot you can do with them and very little flexibility. Your best option may be to remove from vRA management those VMs your colleagues re-IPd and import them back in as something else.



  • 5.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 17, 2019 06:51 PM

    Yes, the network profiles are horrid.  Stay away from them in almost all cases.  We maneuvered around them long ago... I always fear something is going to come back to bite us but so far it hasn't.  Hopefully in the next version they will make some changes to make them more useful and/or dynamic.

    Paul



  • 6.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 18, 2019 10:19 AM
    How do you allocate IP addresses then?


  • 7.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 18, 2019 12:28 PM

    External IPAM.



  • 8.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 18, 2019 05:39 PM

    We also do it all with our external ipam.  We use event subscriptions to update the ipam appropriately during deploy and destroy operations and update the properties of the vm as well.



  • 9.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 20, 2019 07:31 AM

    I just integrated external IPAM as a provider (using the SDK), so far it worked.

     

    That is why I'm asking what issues I can expect.



  • 10.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 18, 2019 12:32 PM

    Hopefully in the next version they will make some changes to make them more useful and/or dynamic.

    Having worked with the vRA.NEXT release, all I will say is this:  Don't get your hopes up :smileyhappy:



  • 11.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 18, 2019 05:36 PM

    Good to know... hopefully everything we have in place now will play nicely with the new releases!



  • 12.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 18, 2019 10:17 AM
    Is this vRA internal IPAM? This should be possible with an external one.


  • 13.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 22, 2019 08:21 AM

    Hi jacquesperrin.

    I do have the same problem, people changing IP of a deployed VM. I do not have a solution for allocating an IP (my users uses IP's outside the vRA Networkprofiles with they set a new IP. But the old IP's are still stuck.  Anyway, this is the action I use to clean up the IP (used in vRA 7.3)

     

    function FindAndDestroyIP(IP){ var entitySetName = "StaticIPv4Addresses"; var host = Server.findAllForType("vCAC:vCACHost")[0]; var model = "ManagementModelEntities.svc";    var property = new Properties();    property.put("IPv4Address",IP); var computeResources = vCACEntityManager.readModelEntitiesByCustomFilter(host.id, model, entitySetName, property, null);      var entityKeyId = ""; if ( computeResources.length == 0) {    ErrTextStep1 = "No machine found with IP: "+IP+" in vRA";  return false; } else if ( computeResources.length != 1) {    ErrTextStep1 = "OUCH, Multiple machines found with IP: "+IP+" in vRA";  return false; }     System.log("HostID "+computeResources[0].hostId); System.log("modelName = "+computeResources[0].modelName); System.log("entitySetName = "+computeResources[0].entitySetName); System.log("entityIdString = "+computeResources[0].keyString);   // entity key is needed for the delete action entityKeyId = computeResources[0].keyString; var Props = computeResources[0].getProperties(); var Links = computeResources[0].getLinks(host);  // Links = Array of Properties   System.log("Removing: "+entityKeyId);            try          {       vCACEntityManager.deleteModelEntityBySerializedKey(host.id , model , entitySetName , entityKeyId, null);        }          catch(e)          {       System.warn(e);              return false;        }          return true;}

     

    This will release the IP from the internal IPAM database. You would also need to update the Custom Properties of the VM to reflect the new IP.



  • 14.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted May 22, 2019 11:32 AM

    Just for readability here is the same function (i think), in a slightly more readable format:

    function FindAndDestroyIP(IP) {

        var entitySetName = "StaticIPv4Addresses";

        var host = Server.findAllForType("vCAC:vCACHost")[0];

        var model = "ManagementModelEntities.svc";

        var property = new Properties();

        property.put("IPv4Address", IP);

        var computeResources = vCACEntityManager.readModelEntitiesByCustomFilter(host.id, model, entitySetName, property, null);

        var entityKeyId = "";

        if (computeResources.length == 0) {

            ErrTextStep1 = "No machine found with IP: " + IP + " in vRA";

            return false;

        } else if (computeResources.length != 1) {

            ErrTextStep1 = "OUCH, Multiple machines found with IP: " + IP + " in vRA";

            return false;

        }

        System.log("HostID " + computeResources[0].hostId);

        System.log("modelName = " + computeResources[0].modelName);

        System.log("entitySetName = " + computeResources[0].entitySetName);

        System.log("entityIdString = " + computeResources[0].keyString); // entity key is needed for the delete action

        entityKeyId = computeResources[0].keyString;

        var Props = computeResources[0].getProperties();

        var Links = computeResources[0].getLinks(host); // Links = Array of Properties

        System.log("Removing: " + entityKeyId);

        try {

            vCACEntityManager.deleteModelEntityBySerializedKey(host.id, model, entitySetName, entityKeyId, null);

        } catch (e) {

            System.warn(e);

            return false;

        }

        return true;

    }



  • 15.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?
    Best Answer

    Posted May 23, 2019 02:14 PM

    Hi GeiAll  and Mads Fog Albrechtslund

    Thanks for your answer, even if the deletion of the IP address in the network profile was not exactly what I wanted, you gave me the way to find the solution.

    The workflow below, unallocates an IP address in an IP range of a network profile, now I have to work on another one to reallocate the IP address to a VM ...

    Thanks again my friends ...

    System.log("Unallocate IP address")
    System.log("+-- IP address : [" + ipAddress + "]")

    // Check inputs
    if (!ipAddress)
    {
      throw "IP address is invalid"
    }

    var vraHost       = Server.findAllForType("vCAC:vCACHost")[0
    var entitySetName = "StaticIPv4Addresses"
    var model         = "ManagementModelEntities.svc" 

    var filter        = new Properties() 
    filter.put("IPv4Address", ipAddress) 
    var vmEntities = vCACEntityManager.readModelEntitiesByCustomFilter(vraHost.id, model, entitySetName, filter, null) 
    if (vmEntities.length > 1)
    {
      throw "Multiple machines found with this IP"
    }

    if (vmEntities.length == 0)

      System.warn("No machine found") 
    }
    else

      var vmEntity = vmEntities[0]
      System.log("+-- HostID : [" + vmEntity.hostId + "]") 
      System.log("+-- Model name : [" + vmEntity.modelName + "]") 
      System.log("+-- Entity set name : [" + vmEntity.entitySetName + "]")
      System.log("+-- Entity key : [" + vmEntity.keyString + "]")

      var vmEntityProperties = vmEntity.getProperties()
      var vmEntityLinks      = vmEntity.getLinks(vraHost)

      System.log("+-- Current properties :")
      System.log(JSON.stringify(vmEntityProperties, null, 2))
      System.log(JSON.stringify(vmEntityLinks, null, 2))

      try
      { 
        // Update properties
        vmEntityProperties.StaticIPv4AddressState = 1
        vmEntityLinks.VirtualMachine = []
       
        // Show properties updated
        vCACEntityManager.updateModelEntityBySerializedKey(vraHost.id, vmEntity.modelName, vmEntity.entitySetName, vmEntity.keyString, vmEntityProperties, vmEntityLinks , null)
      }
      catch (err)
      { 
        System.error("An error occurded when trying to unallocate IP addrees, reason : " + err)
      } 
    }



  • 16.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted Apr 08, 2021 10:08 AM

      did you find a way to ALLOCATE?

    I am searching for that because we need to bulk-import machines that have an IP address inside the Network Profile's internal ipam range.

    It kinda works when I set vmEntityProperties.StaticIPv4AddressState = 0 (defines ALLOCATED), but how do I set the vmEntityLinks.VirtualMachine to the correct VM?



  • 17.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted Aug 04, 2023 07:32 AM

    vRA8.9 : Do we have anyway to allocate / release an IP address from Network Profiles (Internal PAM) in vRA 8 .

    Using VRO workflow or VRA REST API .

     



  • 18.  RE: How to allocate/unallocate an IP address in a network profile IP addresses range by vRO ?

    Posted Aug 03, 2023 12:10 PM

    Hi ,

    vRA8.9 : Do we have anyway to allocate / release an IP address from Network Profiles (Internal PAM) in vRA 8 .

    Using VRO workflow or VRA REST API .