CloudStack provides APIs using which a public IP can be acquired and assigned to virtual machines. A CloudStack admin, domain admin or a user can use CloudMonkey CLI to do the following steps:
- First, use the associateIpAddress API Acquires and associates a public IP to an account
- Then use the enableStaticNat API to enable Static NAT for the given address
In the below example, 192.168.64.106 is being acquired and associated with the IP address 10.1.1.97.
cloudmonkey> associate ipaddress \ networkid=aa30e739-0dbd-44f3-8642-fa6c60a06ae0 accountid = ed219959-b923-4d7f-8b45-0416bebf5732 cmd = org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd created = 2013-12-29T08:44:33+0530 jobid = 21b56968-c0b7-42b5-be14-dae29ee5ba11 jobprocstatus = 0 jobresult: ipaddress: id = 1205ac26-884c-4060-90bd-22fbf6a81d79 account = shanker allocated = 2013-12-29T08:44:33+0530 associatednetworkid = aa30e739-0dbd-44f3-8642-fa6c60a06ae0 associatednetworkname = sysVLAN domain = sysCredence domainid = f84afe24-5a54-4d98-9067-2a8a61489e02 forvirtualnetwork = True ipaddress = 192.168.64.106 isportable = False issourcenat = False isstaticnat = False issystem = False networkid = 56e13894-ac11-44a9-b4b5-bc4d772add03 physicalnetworkid = 1fca3b97-ae83-4c6d-b9db-b31d77f78ce5 state = Allocating tags: zoneid = 15944836-0b1e-4077-a4e0-9ee32306679e
cloudmonkey> enable staticnat \ ipaddressid=67f16c0b-25a1-4ec8-8701-674a40d3091f \ vmguestip=10.1.1.97 \ virtualmachineid=d70a8740-6c09-4a1d-bc45-948c8aa9986a success = true
You can verify the changes using the UI also.