Comment 6 for bug 1667794

Revision history for this message
NidhiMittalHada (nidhimittal19) wrote :

Hello Matt,

Kindly see analysis below and suggest.

When we execute
stack@ubuntu14-OptiPlex-3020:~/openstack_install/devstack$ nova --debug host-evacuate wipro .
.
.
DEBUG (session:347) REQ: curl -g -i -X GET http://10.141.67.190:8774/v2.1/os-hypervisors/wipro/servers -H "OpenStack-API-Version: compute 2.46" -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-OpenStack-Nova-API-Version: 2.46" -H "X-Auth-Token: {SHA1}9e9230a54eff2444ac32fa054c6bab3dbe446df9" >>>>>>>>>>>>>>>>>>>>>>>>>>

nova api that's being called is this
https://developer.openstack.org/api-ref/compute/?expanded=search-hypervisor-detail,list-hypervisor-servers-detail#list-hypervisor-servers
Where it clearly states: "List all servers belong to each hypervisor whose host name is matching a given hypervisor host name or portion of it."

Another available api for hostname match is https://developer.openstack.org/api-ref/compute/?expanded=search-hypervisor-detail,list-hypervisor-servers-detail#search-hypervisor
which states: "Search hypervisor by a given hypervisor host name or portion of it."

There is no api available at present where hostname is matched not as a pattern. PCMIIW.

Hence it can't be just fixed in client as it is.

Solution: I thought we can fix it by changing only http://10.141.67.190:8774/v2.1/os-hypervisors/wipro/servers api to match hostname as exact so that https://developer.openstack.org/api-ref/compute/?expanded=search-hypervisor-detail,list-hypervisor-servers-detail#search-hypervisor remains unaffected.
This I still have to change in nova server code, I will use an additional function parameter to specify if exact match is desired or a pattern match is desired.

But then http://10.141.67.190:8774/v2.1/os-hypervisors/wipro/servers is being used by many other commands than just host-evacuate.
Which all will be affected.

Listing commands that will be affected are .

Function in novaclient from where we call api
   def search(self, hypervisor_match, servers=False): >>>>>>>>>>>>>>.servers is False by default
        """
        Get a list of matching hypervisors.
        :param servers: If True, server information is also retrieved.
        """
        target = 'servers' if servers else 'search'
        url = ('/os-hypervisors/%s/%s' %
               (parse.quote(hypervisor_match, safe=''), target)) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
        return self._list(url, 'hypervisors')

we are passing servers as true in these cli commands.

Servers = True
==============================================
1.
do_host_meta(cs, args):
    """Set or Delete metadata on all instances of a host."""
    hypervisors = cs.hypervisors.search(args.host, servers=True)

2.
@utils.arg(
    'hostname',
    metavar='<hostname>',
    help=_('The hypervisor hostname (or pattern) to search for.')) def do_hypervisor_servers(cs, args):
    """List servers belonging to specific hypervisors."""
    hypers = cs.hypervisors.search(args.hostname, servers=True)

3.
def do_host_evacuate(cs, args):
    """Evacuate all instances from failed host."""

    hypervisors = cs.hypervisors.search(args.host, servers=True)

4.
def do_host_evacuate_live(cs, args):
    """Live migrate all instances of the specified host
    to other available hosts.
    """
    hypervisors = cs.hypervisors.search(args.host, servers=True)
    response = []

5.
def do_host_servers_migrate(cs, args):
    """Cold migrate all instances off the specified host to other available
    hosts.
    """

    hypervisors = cs.hypervisors.search(args.host, servers=True)
    response = []
    for hyper in hypervisors:

Servers = false
===============
1.
def _do_hypervisor_list(cs, matching=None, limit=None, marker=None):
    columns = ['ID', 'Hypervisor hostname', 'State', 'Status']
    if matching:
        utils.print_list(cs.hypervisors.search(matching), columns)

Please suggest what is better solution?

1)Modifying http://10.141.67.190:8774/v2.1/os-hypervisors/wipro/servers api code in nova server side code - to match hostname as exact not as a pattern
We can code so that http://10.141.67.190:8774/v2.1/os-hypervisors/wipro/search remains unaffected.

2)We should introduce a new parameter in servers api which from cli which directs that exact match is to be
done in url.
http://10.141.67.190:8774/v2.1/os-hypervisors/wipro/servers?exact_match=true
and query parameter then interpreted in server side code and behave as desired.
In this case we will have choice to not affect at undesired commands.

Thanks
Nidhi