oracle / oci-python-sdk

Oracle Cloud Infrastructure SDK for Python
https://cloud.oracle.com/cloud-infrastructure
Other
393 stars 281 forks source link

muscat region instance not reachable with the api_config parameters from python script. #683

Closed prmjh4 closed 4 months ago

prmjh4 commented 4 months ago

Python Script: import sys from oci.core import ComputeClient from oci.config import validate_config instance_id = str(sys.argv[1]) action = str(sys.argv[2]).upper() api_config = { 'user': 'ocid1.user.oc9..xxxx', 'key_file': '/opt/rackware/oci_api_key.pem', 'fingerprint': 'f3...', 'tenancy': 'ocid1.tenancy.oc9.xxx', 'region': 'me-dcc-muscat-1', 'api_url': 'oraclecloud9.com', } validate_config(api_config) compute_client = ComputeClient(api_config) compute_client.instance_action( instance_id=instance_id, action=action )

Error logs: Traceback (most recent call last): File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/urllib3/connection.py", line 163, in _new_conn conn = connection.create_connection( File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/urllib3/util/connection.py", line 62, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/socket.py", line 918, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/urllib3/connectionpool.py", line 602, in urlopen httplib_response = self._make_request(conn, method, url, File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/urllib3/connectionpool.py", line 348, in _make_request self._validate_conn(conn) File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/urllib3/connectionpool.py", line 844, in _validate_conn conn.connect() File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/urllib3/connection.py", line 306, in connect conn = self._new_conn() File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/urllib3/connection.py", line 172, in _new_conn raise NewConnectionError( oci._vendor.urllib3.exceptions.NewConnectionError: <oci._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fa94d1358e0>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/requests/adapters.py", line 446, in send resp = conn.urlopen( File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/urllib3/connectionpool.py", line 642, in urlopen retries = retries.increment(method, url, error=e, _pool=self, File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/urllib3/util/retry.py", line 403, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) oci._vendor.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='iaas.me-dcc-muscat-1.oraclecloud.com', port=443): Max retries exceeded with url: /20160918/instances/ocid1.instance.?action=START (Caused by NewConnectionError('<oci._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fa94d1358e0>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/base_client.py", line 361, in request response = self.session.request( File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/requests/sessions.py", line 538, in request resp = self.send(prep, send_kwargs) File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/requests/sessions.py", line 651, in send r = adapter.send(request, kwargs) File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/_vendor/requests/adapters.py", line 524, in send raise ConnectionError(e, request=request) oci._vendor.requests.exceptions.ConnectionError: HTTPSConnectionPool(host='iaas.me-dcc-muscat-1.oraclecloud.com', port=443): Max retries exceeded with url: /20160918/instances/ocid1.instance.?action=START (Caused by NewConnectionError('<oci._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fa94d1358e0>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/rackware/rmm01/PAM/power_cycle.py", line 33, in compute_client.instance_action( instance_id=instance_id, action=action ) File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/core/compute_client.py", line 3396, in instance_action return self.base_client.call_api( File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/base_client.py", line 272, in call_api response = self.request(request) File "/opt/rackware/vendor/python-3.8.1/lib/python3.8/site-packages/oci/base_client.py", line 378, in request raise exceptions.RequestException(e) oci.exceptions.RequestException: HTTPSConnectionPool(host='iaas.me-dcc-muscat-1.oraclecloud.com', port=443): Max retries exceeded with url: /20160918/instances/ocid1.instance.?action=START (Caused by NewConnectionError('<oci._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fa94d1358e0>: Failed to establish a new connection: [Errno -2] Name or service not known'))

Further debugging details: curl -v https://iaas.me-dcc-muscat-1.oci.oraclecloud9.com/20160918/instances/instance-id-value

For other regions where api_url is not involved is working fine but giving error in this case. What is the issue here please help me out with it. Parameters 'user','key_file','fingerprint','tenancy','region' are correctly passed.

This was working for me in the test env but as soon as I tried it on prod env then it started giving me the above error.

adizohar commented 4 months ago

config does not have api_url parameter, it ignored it, please use as below , update your OCI SDK version and run again

from oci.core import ComputeClient
from oci.config import validate_config

instance_id = "ocid1.instance.oc1.iad.xxxxxxx"
action = "START"

api_config = {
    'user': 'ocid1.user.oc1..xxxxx',
    'key_file': 'xxxxx',
    'fingerprint': '70:3d:ee:b7:df:99:93:cf:1xxxx',
    'tenancy': 'ocid1.tenancy.oc1..xxxxx',
    'region': 'me-dcc-muscat-1'
}
validate_config(api_config)
compute_client = ComputeClient(api_config)
response = compute_client.instance_action(instance_id=instance_id, action=action)
print(response.status)

When I tried it goes to

https://iaas.me-dcc-muscat-1.oraclecloud9.com/20160918/instances/ocid1.instance.ocx.iad.anuwcljsafha7wicnt56yzrqxr57ajjb3jjlkk3xv2grngj2fxxx
prmjh4 commented 4 months ago

Thanks @adizohar for the response! I started by not including api_url as I worked for me in all other cases but it gave me the same error so I tried with api_url but no progress and error still persists.

adizohar commented 4 months ago

looks like your compute does not know the URL - Name or service not known Can you run it from cloud shell ?

prmjh4 commented 4 months ago

Unfortunately, I do not have the cloud shell access! I tried the nc command to check the reachability to the iaas.me-dcc-muscat-1.oci.oraclecloud9.com on port 443 it got connected. Is there some other way by which we can debug this?

adizohar commented 4 months ago

Then why do you get error - Name or service not known How do you run the python ? from command line or tool ?

prmjh4 commented 4 months ago

I am running it from the command line. the script has the path mentioned for running python as well.

prmjh4 commented 4 months ago

The below code worked for me if anyone is facing the similar issue. you may try doing the below change by adding the url as the service_endpoint to the compute instance and then executing the script. api_config = { 'user': 'ocid1.user.oc1..xxxxx', 'key_file': 'xxxxx', 'fingerprint': '70:3d:ee:b7:df:99:93:cf:1xxxx', 'tenancy': 'ocid1.tenancy.oc1..xxxxx', 'region': 'me-dcc-muscat-1' } url='https://iaas.me-dcc-muscat-1.oci.oraclecloud9.com' validate_config(api_config) compute_client = ComputeClient(config=api_config, service_endpoint=url) response = compute_client.instance_action(instance_id=instance_id, action=action)