def detachip(ipname, vmname, istty, api): """call: 'detach ip IP from VM' description: 'Detach the given IP from the instance its attached to, allowing it to be freed or attached to a different instance instead.' args: 'IP: The IP address or friendly name you want to detach. .VM: The name of the instance that the ip is currently attached to.' errors: 'VM does not exist: Returns exit code 3 .Invalid IP or no matching friendly IP name found: Returns exit code 4' """ vm = getvmby(vmname, api, what='hostname') if vm is None: if istty: print "VM %s does not exist" % vmname return 3 # look up ip by friendly name ip = get_ip(ipname, api, istty) if not ip: if istty: print 'IP address invalid, or no matching friendly name found.' return 4 vmid = vm['vm_id'] api.detachip(ip=ip, vmid=vmid) if istty: print "Detached %s from %s" % (ipname, vmname)
def destroyip(ipname, istty, api): """call: 'destroy ip IP' description: 'Unallocate the given IP, which must not be locked (in use by a VM). .Once an IP has been unallocated, there is no guarentee .you can get the same one back again. .Note that unlocked IPs still incur a charge until they have been destroyed.' args: 'IP: The IP address or friendly name to unallocate.' errors: 'IP is invalid, or no matching friendly name found: Returns exit code 3' """ ip = get_ip(ipname, api, istty) if not ip: if istty: print '%s not a valid address and no matching friendly name found' return 3 api.dropip(ip=ip) if istty: print "Destroyed ip %s" % ipname