def update_associations(client, latest_state, connection_id, lag_id): changed = False if 'lagId' in latest_state and lag_id != latest_state['lagId']: disassociate_connection_and_lag(client, connection_id, lag_id=latest_state['lagId']) changed = True if (changed and lag_id) or (lag_id and 'lagId' not in latest_state): associate_connection_and_lag(client, connection_id, lag_id) changed = True return changed
def update_associations(client, latest_state, connection_id, lag_id): changed = False if 'lagId' in latest_state and lag_id != latest_state['lagId']: disassociate_connection_and_lag(client, connection_id, lag_id=latest_state['lagId']) changed = True if (changed and lag_id) or (lag_id and 'lagId' not in latest_state): associate_connection_and_lag(client, connection_id, lag_id) changed = True return changed
def ensure_absent(client, lag_id, lag_name, force_delete, delete_with_disassociation, wait, wait_timeout): lag_id = lag_exists(client, lag_id, lag_name) if not lag_id: return False latest_status = lag_status(client, lag_id) # determinine the associated connections and virtual interfaces to disassociate virtual_interfaces, connections = get_connections_and_virtual_interfaces( client, lag_id) # If min_links is not 0, there are associated connections, or if there are virtual interfaces, ask for force_delete if any((latest_status['minimumLinks'], virtual_interfaces, connections)) and not force_delete: raise DirectConnectError( msg= "There are a minimum number of links, hosted connections, or associated virtual interfaces for LAG {0}. " "To force deletion of the LAG use delete_force: True (if the LAG has virtual interfaces they will be deleted). " "Optionally, to ensure hosted connections are deleted after disassocation use delete_with_disassocation: True " "and wait: True (as Virtual Interfaces may take a few moments to delete)" .format(lag_id), last_traceback=None, response=None) # update min_links to be 0 so we can remove the LAG update_lag(client, lag_id, None, 0, len(connections), wait, wait_timeout) # if virtual_interfaces and not delete_vi_with_disassociation: Raise failure; can't delete while vi attached for connection in connections: disassociate_connection_and_lag(client, connection['connectionId'], lag_id) if delete_with_disassociation: delete_connection(client, connection['connectionId']) for vi in virtual_interfaces: delete_virtual_interface(client, vi['virtualInterfaceId']) start_time = time.time() while True: try: delete_lag(client, lag_id) except DirectConnectError as e: if ('until its Virtual Interfaces are deleted' in e.exception.response) and (time.time() - start_time < wait_timeout) and wait: continue else: return True
def ensure_absent(client, lag_id, lag_name, force_delete, delete_with_disassociation, wait, wait_timeout): lag_id = lag_exists(client, lag_id, lag_name) if not lag_id: return False latest_status = lag_status(client, lag_id) # determinine the associated connections and virtual interfaces to disassociate virtual_interfaces, connections = get_connections_and_virtual_interfaces(client, lag_id) # If min_links is not 0, there are associated connections, or if there are virtual interfaces, ask for force_delete if any((latest_status['minimumLinks'], virtual_interfaces, connections)) and not force_delete: raise DirectConnectError(msg="There are a minimum number of links, hosted connections, or associated virtual interfaces for LAG {0}. " "To force deletion of the LAG use delete_force: True (if the LAG has virtual interfaces they will be deleted). " "Optionally, to ensure hosted connections are deleted after disassocation use delete_with_disassocation: True " "and wait: True (as Virtual Interfaces may take a few moments to delete)".format(lag_id), last_traceback=None, response=None) # update min_links to be 0 so we can remove the LAG update_lag(client, lag_id, None, 0, len(connections), wait, wait_timeout) # if virtual_interfaces and not delete_vi_with_disassociation: Raise failure; can't delete while vi attached for connection in connections: disassociate_connection_and_lag(client, connection['connectionId'], lag_id) if delete_with_disassociation: delete_connection(client, connection['connectionId']) for vi in virtual_interfaces: delete_virtual_interface(client, vi['virtualInterfaceId']) start_time = time.time() while True: try: delete_lag(client, lag_id) except DirectConnectError as e: if ('until its Virtual Interfaces are deleted' in e.response) and (time.time() - start_time < wait_timeout) and wait: continue else: return True