def _db_connect(): # If you really need to do another migration before all of this goes into # quantum, and you need to access the DB, this is what you need: oparser = optparse.OptionParser(version="%%prog %s" % version.version_string()) create_options(oparser) (options, args) = config.parse_options(oparser) conf, app = config.Config.load_paste_app('melange', options, args) db_api.configure_db(conf, ipv4.plugin(), mac.plugin())
def delete(self): mac_address, ips = db.db_api.delete_interface(self) if mac_address: if mac_address.mac_range: plugin = mac.plugin() generator = plugin.get_generator(mac_address.mac_range) generator.mac_removed(mac_address.address) # NOTE(jkoelker) notify that the mac was deleted mac_address._notify_fields("delete") for ip in ips: # NOTE(jkoelker) notify that the ips were deallocated ip._notify_fields("update")
def allocate_mac(self, **kwargs): generator = mac.plugin().get_generator(self) if generator.is_full(): raise NoMoreMacAddressesError() max_retry_count = int(config.Config.get("mac_allocation_retries", 10)) for retries in range(max_retry_count): next_address = generator.next_mac() try: return MacAddress.create(address=next_address, mac_address_range_id=self.id, **kwargs) except exception.DBConstraintError as error: LOG.debug("MAC allocation retry count:{0}".format(retries + 1)) LOG.exception(error) if generator.is_full(): raise NoMoreMacAddressesError() raise ConcurrentAllocationError( _("Cannot allocate mac address at this time"))
def delete(self): if self.mac_range: generator = mac.plugin().get_generator(self.mac_range) generator.mac_removed(self.address) super(MacAddress, self).delete()
from melange.common import config from melange.db import db_api from melange.ipam import models from melange.db.sqlalchemy import session from melange.openstack.common import config as openstack_config oparser = optparse.OptionParser() openstack_config.add_common_options(oparser) openstack_config.add_log_options(oparser) (options, args) = openstack_config.parse_options(oparser) if len(args) < 1: sys.exit("Please include the connection string for the nova DB") try: conf = config.load_app_environment(optparse.OptionParser()) db_api.configure_db(conf, ipv4.plugin(), mac.plugin()) nova_engine = session._create_engine({'sql_connection': args[0]}) instances = nova_engine.execute("select id,uuid from instances") melange_session = session.get_session() print "-----" for instance in instances: print "updating %(id)s with %(uuid)s" % instance session._ENGINE.execute("update interfaces set " "device_id='%(uuid)s' " "where device_id=%(id)s" % instance) except RuntimeError as error: sys.exit("ERROR: %s" % error)