def disassociate_address(self, public_ip): if not public_ip in self.assigned: raise exception.AddressNotAllocated() addr = self.get_host(public_ip) if addr.get('private_ip', 'available') == 'available': raise exception.AddressNotAssociated() self.deexpress(address=public_ip) addr['private_ip'] = 'available' addr['instance_id'] = 'available' addr.save()
def associate_address(self, public_ip, private_ip, instance_id): if not public_ip in self.assigned: raise exception.AddressNotAllocated() # TODO(joshua): Keep an index going both ways for addr in self.host_objs: if addr.get('private_ip', None) == private_ip: raise exception.AddressAlreadyAssociated() addr = self.get_host(public_ip) if addr.get('private_ip', 'available') != 'available': raise exception.AddressAlreadyAssociated() addr['private_ip'] = private_ip addr['instance_id'] = instance_id addr.save() self.express(address=public_ip)
def get_vlan_for_project(project_id): """ Allocate vlan IDs to individual users. """ vlan = datastore.Redis.instance().hget(VLANS_KEY, project_id) if vlan: return vlan assigned_vlans = get_assigned_vlans() # TODO(joshua) I can do this in one loop, I think for old_project_id, vlan in assigned_vlans.iteritems(): if not users.UserManager.instance().get_project(old_project_id): _rem_vlan(old_project_id) _add_vlan(project_id, vlan) return vlan for vlan in range(FLAGS.vlan_start, FLAGS.vlan_end): if not str(vlan) in assigned_vlans.values(): _add_vlan(project_id, vlan) return vlan raise exception.AddressNotAllocated("Out of VLANs")
def get_network_by_address(address): for project in users.UserManager.instance().get_projects(): net = get_project_network(project.id) if address in net.assigned: return net raise exception.AddressNotAllocated()
def deallocate_ip(self, ip_str): if not ip_str in self.assigned: raise exception.AddressNotAllocated() self._rem_host(ip_str) self.deexpress(address=ip_str)