NetApp / ontap-rest-python

This repository contains sample code illustrating how to access the ONTAP REST API using Python. This Repository also contains ONTAPI Usage reporting code that helps to identify ONTAPI usage in your environment using ONTAP REST APIs.
BSD 3-Clause "New" or "Revised" License
60 stars 41 forks source link

ImportError: cannot import name 'Argument' from 'utils' when running #32

Closed ashwinwriter closed 2 years ago

ashwinwriter commented 2 years ago

Hi,

Sorry if it's a dumb question, I am new to python scripts. I am getting this errors when running sample scripts from repository.

ontap-rest-python/volume_operations.py at master · NetApp/ontap-rest-python · GitHub

Error: File "//volume_operations.py", line 23, in from utils import Argument, parse_args, setup_logging, setup_connection, get_size ImportError: cannot import name 'Argument' from 'utils' (/usr/local/lib/python3.9/site-packages/utils/init.py) [root@centos9 /]#

Many thanks!

github-actions[bot] commented 2 years ago

Thank you for reporting an issue! If you haven't already joined our Slack community, then we invite you to do so. This is a great place to get help and ask questions from our community.

RobertBlackhart commented 2 years ago

It sounds like, from the /usr/local/lib/python3.9/site-packages/utils path in your error, that you have a package called "utils" installed. But the utils in the example scripts refers to the utils.py file here: https://github.com/NetApp/ontap-rest-python/blob/master/examples/python_client_library/utils.py

So the expectation of the example script is that you are running it from the examples/python_client_library directory so that it can import that local utils.py file.

ashwinwriter commented 2 years ago

Hi Rob,

Thank you for replying so quick. I didn't expect that. Much appreciated.

Your observation makes sense. I am absolutely new to this new stuff (scripting to be honest).

So, what I did is, I copied the 'utils.py' content, copied it to the /location of my centos9 and saved it as utils.py, and I ran it.

[root@centos9 /]# python3.9 utils.py It worked, no complain.

Next, I ran the volume_operations script and hurray, it didn't complain. Thanks for your help.

I see different error this time, I will review it but if you have any suggestions please do reply.

[root@centos9 /]# python3.9 volume_operations.py Password:

THE FOLLOWING SCRIPT SHOWS VOLUME OPERATIONS USING REST API PYTHON CLIENT LIBRARY:-

What Volume Operation would you like to do? [list/create/update/delete/clone] create

Getting SVM Details

[2021-12-21 13:40:03,819] [WARNING] [connectionpool:780] Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe30eee5880>: Failed to establish a new connection: [Errno -2] Name or service not known')': /api/svm/svms?fields=uuid

raise NetAppRestError(cause=erro) from None netapp_ontap.error.NetAppRestError: Caused by ConnectionError(MaxRetryError("HTTPSConnectionPool(host='none', port=443): Max retries exceeded with url: /api/svm/svms?fields=uuid (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f757439e3a0>: Failed to establish a new connection: [Errno -2] Name or service not known'))"))

Many thanks!

RobertBlackhart commented 2 years ago

The problem here is that the script wants you to pass the cluster management IP: https://github.com/NetApp/ontap-rest-python/blob/9632d237ab12b76fd3b032ce47fa6db0a8df2857/examples/python_client_library/volume_operations.py#L425-L426

So you would want to run it like this:

[root@centos9 /]# python3.9 volume_operations.py --cluster 1.2.3.4

Where you replace 1.2.3.4 with whatever your IP actually is.

ashwinwriter commented 2 years ago

Thanks, Rob. That was so dumb of me. I have been running scripts with cluster IP as it clearly states in the sample, but I was so excited that I left my common sense in the bin.

It works, I ran it again with cluster IP.

[root@centos9 /]# python3.9 volume_operations.py -c x.x.x.x -u admin -p xxxxxx

THE FOLLOWING SCRIPT SHOWS VOLUME OPERATIONS USING REST API PYTHON CLIENT LIBRARY:-

What Volume Operation would you like to do? [list/create/update/delete/clone] list

Getting SVM Details

SVM name:-svm_nfs ; SVM uuid:-b8850b5c-5919-11ec-b300-000c2951836a

Enter the SVM from which the Volumes need to be listed:-b8850b5c-5919-11ec-b300-000c2951836a

I really appreciate your patience and help. I am glad you are there to help. Hopefully, I can pick up basic stuff from here on.

RobertBlackhart commented 2 years ago

No problem. Since your current problem is solved so I'll close the issue. If you have more questions, the Slack community linked above would be a good place to ask and chat about them.