The idea with that snippet is to fail gracefully if the module isn't
installed, either displaying a user-readable error (please install
library-name to use this module) or, if reasonable, fall back to some other
functionality. You'll notice further down, that the Netconf class (but not
the Cli class) has the following snippet

if not HAS_JXMLEASE:
>     raise NetworkError(
>         msg='jxmlease is required but does not appear to be installed. '
>         'It can be installed using `pip install jxmlease`'
>     )
>

This handles the actual issue without throwing an ImportError at the user,
and gives them a concrete suggestion at a solution. This is only for
Netconf, as Cli does not depend on jxmlease, and therefore should not be
gated by that lib.

On Mon, Oct 17, 2016 at 10:57 PM, <jacky.gao2...@gmail.com> wrote:

>  Hi Peter,
>      Thanks for the answer.
>
>      I  find that the current ansible version does not include
>  netconf_config module.
>
>      And Junos modules  using the below code "try" to depend other python
> lib, we will using the same style to resolve the third party lib dependency
>  question. If we expect HUAWEI data center switch modules will be ansible
> core modules. Does it work ok?
>
> try: import jxmlease
>
> HAS_JXMLEASE = True
>
> except ImportError:
>
> HAS_JXMLEASE = False
>
>
>
> 在 2016年9月30日星期五 UTC+8上午11:53:46,jacky....@gmail.com写道:
>
>> Now we using ncclient netconf lib to develop huawei datacenter switch
>> ansible module;
>>
>> But we hope our switch ansible module will be ansible core module, and I
>> think it's better that ansible do not need to add new dependency library.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-devel+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to