unable to stop an instance using python api

asked 2020-05-20 09:42:36 -0500

Prasanna Ram gravatar image

updated 2020-05-21 08:52:13 -0500

zaneb gravatar image

I am trying to stop an instance using openstack api with the help of python.

from openstack import connection
import os

def auth_args():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['password'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['project_name'] = os.environ['OS_TENANT_NAME']
    d['project_domain_id'] = os.environ['OS_PROJECT_DOMAIN_ID']
    d['user_domain_id'] = os.environ['OS_PROJECT_DOMAIN_ID']
    return d

for server in conn.compute.servers():
  if server.name == 'server_test':

i have set a source file then i am trying to run this code, but it gives the below error.

Traceback (most recent call last):

  File "stop_opsk_srv.py", line 20, in <module>
  File "/root/.local/lib/python2.7/site-packages/openstack/compute/v2/server.py", line 345, in stop
    self._action(session, body)
  File "/root/.local/lib/python2.7/site-packages/openstack/compute/v2/server.py", line 181, in _action
    return session.post(

I am able to retrieve instance details and meta data using the same conn.compute.servers() method. Please help.

edit retag flag offensive close merge delete



Can you publish the complete trace? The fragment you show contains no meaningful information.

Also, are you certain the user has the right to stop the instance?

Bernd Bausch gravatar imageBernd Bausch ( 2020-05-20 10:10:50 -0500 )edit