Issue updated 'sites' permission for Network via API

I’m hitting an issue updating a network via API. All the JSON fields seem to work and update correctly except for the “sites” setting, where the UI doesn’t show the group that should have access is checked to have access.

The API docs show the format of the JSON payload as:

payload = { "network": {
        "visibility": "private",
        "resourcePermissions": {
            "all": False,
            "sites": [2]
        },
        "cidr": "127.0.0.0/24",
        "gateway": "127.0.0.1",
        "dnsPrimary": "8.8.8.8",
        "dnsSecondary": "8.8.4.4,
        "vlanId": 9,
        "pool": 15886,
        "allowStaticOverride": False,
        "active": True,
        "dhcpServer": False,
        "applianceUrlProxyBypass": True,
        "tenants": [{ "id": 1 }]
    } }

What I’m sending is:

{ 'network': {
  'visibility': 'private', 
  'tenants': [{'id': 1}], 
  'resourcePermissions': {
    'all': False, 
    'sites': [2]
  }, 
  'pool': 15886, 
  'displayName': None, 
  'cidr': '172.0.0.0/24', 
  'gateway': '172.0.0.1', 
  'dnsPrimary': '8.8.8.8', 
  'dnsSecondary': '8.8.4.4', 
  'vlanId': 9, 
  'allowStatisOverride': False, 
  'active': True, 
  'dhcpServer': False, 
  'searchDomains': None, 
  'applianceUrlProxyBypass': True
 }
}

I’m not sure what I’m missing on why the actual group access isn’t adjusting. The “ALL” goes depending on if I set that True or False, but even leaving that out the Sites values don’t get updated.

Can you tell me what I’m missing/doing wrong? I’m hoping to have this ready by this afternoon to migrate some things, duplicating permissions and settings from existing networks, but this group part is being a pain.

Hello @rjr162!

I think the documentation may need to be updated. Here is what I am using to set them:

{
     "network": {
        "resourcePermissions": {
            "sites": [
                {
                    "id": 15
                },
                {
                    "id": 4
                }
            ],
            "all": false
        }
     }
}

Obviously, you can send the above with other changes you are submitting. When using the above, I get the following:

I figured this out by using a GET on a network that I had modified and inspecting it.

I’ve also changed the documentation, which should appear in the 7.0.6 version, once released.

I hope that helps!

2 Likes

@kgawronski

That did it!

it also made things a bit easier since I could pre-stage the “sites”: amd then just do a [‘sites’].extend() to add in the [{ ‘id’: site[‘id’] }] from my loop.

I know the API doesn’t mention the sites: values of ‘name’ and ‘default’, but does the API accept those as well?

The reason I’m asking is I could avoid my loop and just add the ‘sites’ section from my JSON call for the old network information and update the new JSON I’m sending back for the new network via the .extend()
I guess I can try and see what happens

Glad to hear it worked!

You can supply name, it won’t have any functionality but it won’t throw an error. The ID is the reference that would matter.

As for the default, I used the following to set the default (includes name example too):

{
    "network": {
        "resourcePermissions": {
            "sites": [
                {
                    "id": 15,
                    "name": "testname",
                    "default": false
                },
                {
                    "id": 4,
                    "default": true
                }
            ],
            "all": false
        }
    }
}

I’ve added the default property to the 7.0.6 documentation as well.

1 Like

Perfect! tl;dr we’re setting up more vSphere clusters which will have “networks” (portgroups) that need configured in Morpheus, and my plan is to read in one of the existing configured network values and then basically spit back to the API targeting the new matching port group to make it a super simple “copy/paste” type function. Knowing the default works in there too makes it that much easier as I can just return the full existing sites value instead of looping over to pull out only any ID values.

Thanks again!

1 Like