Beispiel #1
0
 def migrate_macs(self):
     """2. Migrate the m.mac_address -> q.quark_mac_addresses
     This is the next simplest but the relationship between quark_networks
     and quark_mac_addresses may be complicated to set up (if it exists)
     """
     """Only migrating the first mac_address_range from melange."""
     import netaddr
     mac_range = self.melange_session.query(
         melange.MacAddressRanges).first()
     cidr = mac_range.cidr
     init_id(self.json_data, 'mac_ranges', mac_range.id)
     try:
         cidr, first_address, last_address = to_mac_range(cidr)
     except ValueError as e:
         set_reason(self.json_data, mac_range.id, "mac_ranges", e.message)
         self.log.critical(e.message)
         return None
     except netaddr.AddrFormatError as afe:
         set_reason(self.json_data, mac_range.id, "mac_ranges", afe.message)
         self.log.critical(afe.message)
         return None
     q_range = quarkmodels.MacAddressRange(
         id=mac_range.id,
         cidr=cidr,
         created_at=mac_range.created_at,
         first_address=first_address,
         next_auto_assign_mac=first_address,
         last_address=last_address)
     self.add_to_session(q_range, 'mac_ranges', q_range.id)
     res = self.melange_session.query(melange.MacAddresses).all()
     no_network_count = 0
     for mac in res:
         init_id(self.json_data, 'macs', mac.address)
         if mac.interface_id not in self.interface_network:
             no_network_count += 1
             r = "mac.interface_id {0} not in self.interface_network"\
                 .format(mac.interface_id)
             set_reason(self.json_data, 'macs', mac.address, r)
             continue
         tenant_id = self.interface_tenant[mac.interface_id]
         q_mac = quarkmodels.MacAddress(tenant_id=tenant_id,
                                        created_at=mac.created_at,
                                        mac_address_range_id=mac_range.id,
                                        address=mac.address)
         q_port = self.port_cache[mac.interface_id]
         q_port.mac_address = q_mac.address
         self.add_to_session(q_mac, 'macs', q_mac.address)
     self.log.info("skipped {0} mac addresses".format(
         str(no_network_count)))  # noqa
Beispiel #2
0
def mac_address_range_create(context, **range_dict):
    new_range = models.MacAddressRange()
    new_range.update(range_dict)
    context.session.add(new_range)
    return new_range