VMware Cloud Community
giffjo
Contributor
Contributor

REST API Add Cloud Zone to project

I am trying to create a project using the API and even though I can get it to work I cannot get cloud zones to populate. I know the format and I know the zoneID but it is not showing in the actual UI when I check on projects. What am I doing wrong. 

            "zones": [

                {

                    "zoneId": "MY ID For Cloud Zone",

                    "priority": 0,

                    "maxNumberInstances": 0,

                    "allocatedInstancesCount": 2,

                    "memoryLimitMB": 0,

                    "allocatedMemoryMB": 0,

                    "cpuLimit": 0,

                    "allocatedCpu": 0,

                    "storageLimitGB": 0,

                    "allocatedStorageGB": 250.0

                }

            ],

 

I enter the right cloud zone ID and it just doesn't populate cloud zones at all. Any help is appreciated. 

Labels (4)
Reply
0 Kudos
3 Replies
RebeccaW
Enthusiast
Enthusiast

For onprem 8.8 this looks to be not in Project API but in IaaS API /iaas/api/projects. The Project api POST looks to not have a section for setting the zones just the base Project shell.

In IaaS API instead of zones it is listed as zoneAssignmentConfigurations. Not sure if the url is similar for SaaS version but for onprem check with the swagger to check https://<your vra url>/iaas/api/swagger/ui/#/Project/createProject

Reply
0 Kudos
Ankush11s
VMware Employee
VMware Employee


Have a look at below sample 

    def add_Cloudzone_Project(self, projectid, cloudzoneid):
        url = f'https://{self.vrafqdn}/iaas/api/projects/{projectid}?apiVersion={self.apiversion}'
        headers = {
            'accept': "application/json",
            'content-type': "application/json",
            'authorization': self.vratoken()
        }
        existing_data = requests.get(url=url, headers=headers, verify=False)
        if existing_data.status_code == 200:
            if existing_data.json():
                payload = {
                    "zoneAssignmentConfigurations": existing_data.json()['zones']
                }
                new_zone = {
                    "storageLimitGB": 0,
                    "cpuLimit": 0,
                    "memoryLimitMB": 0,
                    "zoneId": f'{cloudzoneid}',
                    "maxNumberInstances": 0,
                    "priority": 0
                }
                payload['zoneAssignmentConfigurations'].append(new_zone)
                output = requests.patch(url=url, headers=headers, data=json.dumps(payload), verify=False)
                if output.status_code == 200:
                    print(f'Adding Cloud zone: {cloudzoneid} is successful')
                    print(output.json())
Reply
0 Kudos
Ankush11s
VMware Employee
VMware Employee

Also to note , if there are existing cloud zone , we need to add those also in body .

Tags (1)
Reply
0 Kudos