def id_from_network_name(name): """Returns Network's Django id, given a ganeti network name. Strips the ganeti prefix atm. Needs a better name! """ if not str(name).startswith(settings.BACKEND_PREFIX_ID): raise Network.InvalidBackendIdError(str(name)) ns = str(name).replace(settings.BACKEND_PREFIX_ID + 'net-', "", 1) if not ns.isdigit(): raise Network.InvalidBackendIdError(str(name)) return int(ns)
def process_network_status(back_network, etime, jobid, opcode, status, logmsg): if status not in [x[0] for x in BACKEND_STATUSES]: raise Network.InvalidBackendMsgError(opcode, status) back_network.backendjobid = jobid back_network.backendjobstatus = status back_network.backendopcode = opcode back_network.backendlogmsg = logmsg # Note: Network is already locked! network = back_network.network # Notifications of success change the operating state state_for_success = BackendNetwork.OPER_STATE_FROM_OPCODE.get(opcode, None) if status == rapi.JOB_STATUS_SUCCESS and state_for_success is not None: back_network.operstate = state_for_success if (status in (rapi.JOB_STATUS_CANCELED, rapi.JOB_STATUS_ERROR) and opcode == 'OP_NETWORK_ADD'): back_network.operstate = 'ERROR' back_network.backendtime = etime if opcode == 'OP_NETWORK_REMOVE': network_is_deleted = (status == rapi.JOB_STATUS_SUCCESS) if network_is_deleted or (status == rapi.JOB_STATUS_ERROR and not network_exists_in_backend(back_network)): back_network.operstate = state_for_success back_network.deleted = True back_network.backendtime = etime if status == rapi.JOB_STATUS_SUCCESS: back_network.backendtime = etime back_network.save() # Also you must update the state of the Network!! update_network_state(network)
def process_network_status(back_network, etime, jobid, opcode, status, logmsg): if status not in [x[0] for x in BACKEND_STATUSES]: raise Network.InvalidBackendMsgError(opcode, status) back_network.backendjobid = jobid back_network.backendjobstatus = status back_network.backendopcode = opcode back_network.backendlogmsg = logmsg network = back_network.network # Notifications of success change the operating state state_for_success = BackendNetwork.OPER_STATE_FROM_OPCODE.get(opcode, None) if status == 'success' and state_for_success is not None: back_network.operstate = state_for_success if status in ('canceled', 'error') and opcode == 'OP_NETWORK_ADD': back_network.operstate = 'ERROR' back_network.backendtime = etime if opcode == 'OP_NETWORK_REMOVE': if (status == 'success' or (status == 'error' and (back_network.operstate == 'ERROR' or network.action == 'DESTROY'))): back_network.operstate = state_for_success back_network.deleted = True back_network.backendtime = etime if status == 'success': back_network.backendtime = etime back_network.save() # Also you must update the state of the Network!! update_network_state(network)
def process_network_modify(back_network, etime, jobid, opcode, status, job_fields): assert (opcode == "OP_NETWORK_SET_PARAMS") if status not in [x[0] for x in BACKEND_STATUSES]: raise Network.InvalidBackendMsgError(opcode, status) back_network.backendjobid = jobid back_network.backendjobstatus = status back_network.opcode = opcode add_reserved_ips = job_fields.get("add_reserved_ips") if add_reserved_ips: network = back_network.network for ip in add_reserved_ips: network.reserve_address(ip, external=True) if status == rapi.JOB_STATUS_SUCCESS: back_network.backendtime = etime back_network.save()
def process_network_modify(back_network, etime, jobid, opcode, status, add_reserved_ips, remove_reserved_ips): assert (opcode == "OP_NETWORK_SET_PARAMS") if status not in [x[0] for x in BACKEND_STATUSES]: raise Network.InvalidBackendMsgError(opcode, status) back_network.backendjobid = jobid back_network.backendjobstatus = status back_network.opcode = opcode if add_reserved_ips or remove_reserved_ips: net = back_network.network pool = net.get_pool() if add_reserved_ips: for ip in add_reserved_ips: pool.reserve(ip, external=True) if remove_reserved_ips: for ip in remove_reserved_ips: pool.put(ip, external=True) pool.save() if status == 'success': back_network.backendtime = etime back_network.save()