[Libvirt-cim] [PATCH 01/10] live.full_hostname: Adjust mechanism to get FQDN

Xu Wang gesaint at linux.vnet.ibm.com
Thu May 8 09:01:00 UTC 2014


于 2014年04月14日 23:05, John Ferlan 写道:
>
> On 04/14/2014 02:15 AM, Xu Wang wrote:
>> 于 2014年04月05日 00:12, John Ferlan 写道:
>>> Rather than default to socket.gethostbyaddr(socket.gethostname())[0] to
>>> get full_hostname(), go through a sequence of steps to get a more
>>> correct result
>>>
>>> NOTE:
>>> See http://www.redhat.com/archives/libvirt-cim/2013-November/msg00082.html
>>> for more details and history.
>>>
>>> Signed-off-by: John Ferlan <jferlan at redhat.com>
>>> ---
>>>    lib/VirtLib/live.py | 11 ++++++++---
>>>    1 file changed, 8 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/lib/VirtLib/live.py b/lib/VirtLib/live.py
>>> index c929e71..e9cafc1 100644
>>> --- a/lib/VirtLib/live.py
>>> +++ b/lib/VirtLib/live.py
>>> @@ -100,6 +100,11 @@ def hostname(server):
>>>        return out
>>>    
>>>    def full_hostname(server):
>>> -    """To return the fully qualifiec domain name(FQDN) of the system"""
>>> -
>>> -    return socket.gethostbyaddr(socket.gethostname())[0]
>>> +    """To return the fully qualified domain name(FQDN) of the system"""
>>> +
>>> +    if socket.getfqdn().find('.') >= 0:
>>> +        return socket.getfqdn()
>>> +    elif socket.gethostname().find('.') >= 0:
>>> +        return socket.gethostname()
>>> +    else:
>>> +        return socket.gethostbyaddr(server)[1][0]
>> I got an error here. The content of my /etc/hosts is,
>>
>> # cat /etc/hosts
>> 127.0.0.1 RH64wenchao localhost localhost.localdomain localhost4
>> localhost4.localdomain4 #RH64wenchao
>>
> I don't see the same results if I add a different name to /etc/hosts. I
> didn't restart my network and that may make a difference.  I did restart
> my tog-pegasus, but that shouldn't make a difference, but who knows at
> this point.
>
> There's 3 places that use the returned data.  I'll play with this some
> more and see what happens
>
> John
Dear John,
   I installed several absolutely new systems to test it, and got 
different results.
I have a question here. Why don't we use socket.gethostname() directly? 
It seems
work well on my systems. Is there any other situation it could not handle?

Thanks,
   Xu Wang
>> And I got an failed result,
>>
>> # CIM_NS=root/virt CIM_USER=root CIM_PASS=****** ./runtests libvirt-cim
>> -i localhost -c -d -v KVM -g HostSystem -t 01_enum.py
>> Starting test suite: libvirt-cim
>> Cleaned log files.
>>
>> Testing KVM hypervisor
>> --------------------------------------------------------------------
>> HostSystem - 01_enum.py: FAIL
>> ERROR - Exp KVM_HostSystem, got KVM_HostSystem
>> ERROR - Exp localhost.localdomain, got RH64wenchao
>> CIM_ERR_INVALID_CLASS: Linux_ComputerSystem
>> --------------------------------------------------------------------
>>
>> It means that @host and @hs[0].Name get the different value. I think it
>> may happened when a computer
>> has more than one hostname. My suggestion is @host make a string match
>> with content of every element
>> of @hs[] to check if @host is contained in it.
>>
>> Thanks,
>> Xu Wang
>>
>>
>> _______________________________________________
>> Libvirt-cim mailing list
>> Libvirt-cim at redhat.com
>> https://www.redhat.com/mailman/listinfo/libvirt-cim
>>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim




More information about the Libvirt-cim mailing list