def _validate_external_server_nics(network_ids, port_ids): new_nic_nodes = \ [node_instance_id for node_instance_id, runtime_props in ctx.capabilities.get_all().iteritems() if runtime_props.get( OPENSTACK_TYPE_PROPERTY) in (PORT_OPENSTACK_TYPE, NETWORK_OPENSTACK_TYPE) and not is_external_resource_by_properties( _get_properties_by_node_instance_id(node_instance_id))] # NOQA if new_nic_nodes: raise NonRecoverableError( "Can't connect new port and/or network nodes to a server node " "with '{0}'=True".format(USE_EXTERNAL_RESOURCE_PROPERTY)) nc = _neutron_client() server_id = ctx.instance.runtime_properties[OPENSTACK_ID_PROPERTY] connected_ports = nc.list_ports(device_id=server_id)['ports'] # not counting networks connected by a connected port since allegedly # the connection should be on a separate port connected_ports_networks = {port['network_id'] for port in connected_ports if port['id'] not in port_ids} connected_ports_ids = {port['id'] for port in connected_ports} disconnected_networks = [network_id for network_id in network_ids if network_id not in connected_ports_networks] disconnected_ports = [port_id for port_id in port_ids if port_id not in connected_ports_ids] if disconnected_networks or disconnected_ports: raise NonRecoverableError( 'Expected external resources to be connected to external server {' '0}: Networks - {1}; Ports - {2}'.format(server_id, disconnected_networks, disconnected_ports))
def _validate_external_server_nics(neutron_client, network_ids, port_ids): # validate no new nics are being assigned to an existing server (which # isn't possible on Openstack) new_nic_nodes = \ [node_instance_id for node_instance_id, runtime_props in ctx.capabilities.get_all().iteritems() if runtime_props.get( OPENSTACK_TYPE_PROPERTY) in (PORT_OPENSTACK_TYPE, NETWORK_OPENSTACK_TYPE) and not is_external_resource_by_properties( _get_properties_by_node_instance_id(node_instance_id))] if new_nic_nodes: raise NonRecoverableError( "Can't connect new port and/or network nodes to a server node " "with '{0}'=True".format(USE_EXTERNAL_RESOURCE_PROPERTY)) # validate all expected connected networks and ports are indeed already # connected to the server. note that additional networks (e.g. the # management network) may be connected as well with no error raised if not network_ids and not port_ids: return server_id = get_openstack_id(ctx) connected_ports = neutron_client.list_ports(device_id=server_id)['ports'] # not counting networks connected by a connected port since allegedly # the connection should be on a separate port connected_ports_networks = { port['network_id'] for port in connected_ports if port['id'] not in port_ids } connected_ports_ids = {port['id'] for port in connected_ports} disconnected_networks = [ network_id for network_id in network_ids if network_id not in connected_ports_networks ] disconnected_ports = [ port_id for port_id in port_ids if port_id not in connected_ports_ids ] if disconnected_networks or disconnected_ports: raise NonRecoverableError( 'Expected external resources to be connected to external server {' '0}: Networks - {1}; Ports - {2}'.format(server_id, disconnected_networks, disconnected_ports))
def _validate_external_server_nics(network_ids, port_ids): # validate no new nics are being assigned to an existing server (which # isn't possible on Openstack) new_nic_nodes = \ [node_instance_id for node_instance_id, runtime_props in ctx.capabilities.get_all().iteritems() if runtime_props.get( OPENSTACK_TYPE_PROPERTY) in (PORT_OPENSTACK_TYPE, NETWORK_OPENSTACK_TYPE) and not is_external_resource_by_properties( _get_properties_by_node_instance_id(node_instance_id))] if new_nic_nodes: raise NonRecoverableError( "Can't connect new port and/or network nodes to a server node " "with '{0}'=True".format(USE_EXTERNAL_RESOURCE_PROPERTY)) # validate all expected connected networks and ports are indeed already # connected to the server. note that additional networks (e.g. the # management network) may be connected as well with no error raised if not network_ids and not port_ids: return nc = _neutron_client() server_id = ctx.instance.runtime_properties[OPENSTACK_ID_PROPERTY] connected_ports = nc.list_ports(device_id=server_id)['ports'] # not counting networks connected by a connected port since allegedly # the connection should be on a separate port connected_ports_networks = {port['network_id'] for port in connected_ports if port['id'] not in port_ids} connected_ports_ids = {port['id'] for port in connected_ports} disconnected_networks = [network_id for network_id in network_ids if network_id not in connected_ports_networks] disconnected_ports = [port_id for port_id in port_ids if port_id not in connected_ports_ids] if disconnected_networks or disconnected_ports: raise NonRecoverableError( 'Expected external resources to be connected to external server {' '0}: Networks - {1}; Ports - {2}'.format(server_id, disconnected_networks, disconnected_ports))
def _validate_external_server_keypair(nova_client): keypair_id = get_openstack_id_of_single_connected_node_by_openstack_type( ctx, KEYPAIR_OPENSTACK_TYPE, True) if not keypair_id: return keypair_instance_id = \ [node_instance_id for node_instance_id, runtime_props in ctx.capabilities.get_all().iteritems() if runtime_props.get(OPENSTACK_ID_PROPERTY) == keypair_id][0] keypair_node_properties = _get_properties_by_node_instance_id( keypair_instance_id) if not is_external_resource_by_properties(keypair_node_properties): raise NonRecoverableError( "Can't connect a new keypair node to a server node " "with '{0}'=True".format(USE_EXTERNAL_RESOURCE_PROPERTY)) server = get_server_by_context(nova_client) if keypair_id == _get_keypair_name_by_id(nova_client, server.key_name): return raise NonRecoverableError( "Expected external resources server {0} and keypair {1} to be " "connected".format(server.id, keypair_id))
def _validate_external_server_keypair(nova_client): keypair_id = get_openstack_id_of_single_connected_node_by_openstack_type( ctx, KEYPAIR_OPENSTACK_TYPE, True) if not keypair_id: return keypair_instance_id = \ [node_instance_id for node_instance_id, runtime_props in ctx.capabilities.get_all().iteritems() if runtime_props.get(OPENSTACK_ID_PROPERTY) == keypair_id][0] keypair_node_properties = _get_properties_by_node_instance_id( keypair_instance_id) if not is_external_resource_by_properties(keypair_node_properties): raise NonRecoverableError( "Can't connect a new keypair node to a server node " "with '{0}'=True".format(USE_EXTERNAL_RESOURCE_PROPERTY)) server = get_server_by_context(nova_client) if keypair_id == _get_keypair_name_by_id(nova_client, server.key_name): return raise NonRecoverableError( "Expected external resources server {0} and keypair {1} to be " "connected".format(server.id, keypair_id))