Exemple #1
0
def connect(config):
    # this shouldn't raise any exception as no connection is done when
    # creating the object.  But It may change, so I catch everything.
    try:
        cinder_client = Client('1',
                               username=config['username'],
                               project_id=config['tenant'],
                               api_key=config['password'],
                               auth_url=config['auth_url'],
                               endpoint_type=config['endpoint_type'])
        cinder_client.authenticate()
    except Exception as e:
        log_error("Connection failed: %s" % e)
    return cinder_client
Exemple #2
0
    def probe(self):

        try:
            cinder = Client(
                '2',
                session=self.get_session(),
                insecure=self.openstack['insecure'],
                cacert=self.openstack['cacert'],
            )
        except Exception as e:
            self.exit_error(str(e))

        try:
            result = cinder.services.list()
        except Exception as e:
            self.exit_error(str(e))

        stati = dict(up=0, disabled=0, down=0, total=0)

        for agent in result:
            if (self.host == None or self.host == agent.host) and (
                    self.binary == None or self.binary == agent.binary):
                stati['total'] += 1
                if agent.status == 'enabled' and agent.state == 'up':
                    stati['up'] += 1
                elif agent.status == 'disabled':
                    stati['disabled'] += 1
                else:
                    stati['down'] += 1

        for r in stati.keys():
            yield osnag.Metric(r, stati[r], min=0)
def connect(config):
    # this shouldn't raise any exception as no connection is done when
    # creating the object.  But It may change, so I catch everything.
    try:
        cinder_client = Client(
            "1",
            username=config["username"],
            project_id=config["tenant"],
            api_key=config["password"],
            auth_url=config["auth_url"],
            endpoint_type=config["endpoint_type"],
        )
        cinder_client.authenticate()
    except Exception as e:
        log_error("Connection failed: %s" % e)
    return cinder_client
Exemple #4
0
def cinder_client(os_creds, session=None):
    """
    Creates and returns a cinder client object
    :param os_creds: the credentials for connecting to the OpenStack remote API
    :param session: the keystone session object (optional)
    :return: the cinder client
    """
    if not session:
        session = keystone_utils.keystone_session(os_creds)

    return Client(version=os_creds.volume_api_version,
                  session=session,
                  region_name=os_creds.region_name)
def create_conn(cred=None):
    """
    create connection
    """
    nt = Client('2',
                username=cred['username'],
                api_key=cred['password'],
                project_id=cred['project_id'],
                auth_url=cred['auth_url'],
                endpoint_type=cred['endpoint_type'],
                cacert=cred['certificate'],
                region_name=cred['region_name'],
                retries=cred['retries'])
    return nt
Exemple #6
0
    def probe(self):
        try:
            auth = identity.Password(
                username=self.openstack['username'],
                password=self.openstack['password'],
                project_name=self.openstack['project_name'],
                user_domain_name=self.openstack['user_domain_name'],
                project_domain_name=self.openstack['project_domain_name'],
                auth_url=self.openstack['auth_url'])
            sess = session.Session(auth=auth)
        except Exception as e:
            self.exit_error('cannot get token ' + str(e))

        try:
            cinder = Client('2', session=sess)
        except Exception as e:
            self.exit_error(str(e))

        try:
            result = cinder.services.list()
        except Exception as e:
            self.exit_error(str(e))

        stati = dict(up=0, disabled=0, down=0, total=0)

        for agent in result:
            if (self.host == None or self.host == agent.host) and (
                    self.binary == None or self.binary == agent.binary):
                stati['total'] += 1
                if agent.status == 'enabled' and agent.state == 'up':
                    stati['up'] += 1
                elif agent.status == 'disabled':
                    stati['disabled'] += 1
                else:
                    stati['down'] += 1

        for r in stati.keys():
            yield osnag.Metric(r, stati[r], min=0)
Exemple #7
0
                    default=None,
                    help='Specify availability zone.')

parser.add_argument('--verbose',
                    action='count',
                    help='Print requests on stderr.')

args = parser.parse_args()

# this shouldn't raise any exception as no connection is done when
# creating the object.  But It may change, so I catch everything.
try:
    nova_client = Client(args.api_version,
                         username=args.username,
                         project_id=args.tenant,
                         api_key=args.password,
                         auth_url=args.auth_url,
                         endpoint_type=args.endpoint_type,
                         http_log_debug=args.verbose)
except Exception as e:
    script_critical("Error creating cinder communication object: %s" % e)

util = Novautils(nova_client)

if args.verbose:
    ch = logging.StreamHandler()
    nova_client.client._logger.setLevel(logging.DEBUG)
    nova_client.client._logger.addHandler(ch)

# Initiate the first connection and catch error.
util.check_connection()
Exemple #8
0
def _check_cinder_volume():
    parser = argparse.ArgumentParser(
        description='Check an OpenStack Keystone server.')
    parser.add_argument('--auth_url',
                        metavar='URL',
                        type=str,
                        default=os.getenv('OS_AUTH_URL'),
                        help='Keystone URL')

    parser.add_argument('--username',
                        metavar='username',
                        type=str,
                        default=os.getenv('OS_USERNAME'),
                        help='username to use for authentication')

    parser.add_argument('--password',
                        metavar='password',
                        type=str,
                        default=os.getenv('OS_PASSWORD'),
                        help='password to use for authentication')

    parser.add_argument('--tenant',
                        metavar='tenant',
                        type=str,
                        default=os.getenv('OS_TENANT_NAME'),
                        help='tenant name to use for authentication')

    parser.add_argument('--endpoint_url',
                        metavar='endpoint_url',
                        type=str,
                        help='Override the catalog endpoint.')

    parser.add_argument('--endpoint_type',
                        metavar='endpoint_type',
                        type=str,
                        default="publicURL",
                        help="""Endpoint type in the catalog request. """
                        """Public by default.""")

    parser.add_argument('--force_delete',
                        action='store_true',
                        help="""If matching volumes are found, delete """
                        """them and add a notification in the """
                        """message instead of getting out in """
                        """critical state.""")

    parser.add_argument('--api_version',
                        metavar='api_version',
                        type=str,
                        default='1',
                        help='Version of the API to use. 1 by default.')

    parser.add_argument('--timeout',
                        metavar='timeout',
                        type=int,
                        default=120,
                        help="""Max number of second to create/delete a """
                        """volume (120 by default).""")

    parser.add_argument('--volume_name',
                        metavar='volume_name',
                        type=str,
                        default="monitoring_test",
                        help="""Name of the volume to create """
                        """(monitoring_test by default)""")

    parser.add_argument('--volume_size',
                        metavar='volume_size',
                        type=int,
                        default=1,
                        help='Size of the volume to create (1 GB by default)')

    parser.add_argument('--volume_type',
                        metavar='volume_type',
                        type=str,
                        default=None,
                        help='With multiple backends, choose the volume type.')

    parser.add_argument('--availability_zone',
                        metavar='availability_zone',
                        type=str,
                        default=None,
                        help='Specify availability zone.')

    parser.add_argument('--verbose',
                        action='count',
                        help='Print requests on stderr.')

    args = parser.parse_args()

    # this shouldn't raise any exception as no connection is done when
    # creating the object.  But It may change, so I catch everything.
    try:
        nova_client = Client(args.api_version,
                             username=args.username,
                             project_id=args.tenant,
                             api_key=args.password,
                             auth_url=args.auth_url,
                             endpoint_type=args.endpoint_type,
                             http_log_debug=args.verbose)
    except Exception as e:
        utils.critical("Error creating cinder communication object: %s" % e)

    util = Novautils(nova_client)

    if args.verbose:
        ch = logging.StreamHandler()
        nova_client.client._logger.setLevel(logging.DEBUG)
        nova_client.client._logger.addHandler(ch)

    # Initiate the first connection and catch error.
    util.check_connection()

    if args.endpoint_url:
        util.mangle_url(args.endpoint_url)
        # after mangling the url, the endpoint has changed.  Check that
        # it's valid.
        util.check_connection(force=True)

    util.check_existing_volume(args.volume_name, args.force_delete)
    util.create_volume(args.volume_name, args.volume_size,
                       args.availability_zone, args.volume_type)
    util.volume_ready(args.timeout)
    util.delete_volume()
    util.volume_deleted(args.timeout)

    if util.msgs:
        utils.critical(", ".join(util.msgs))

    duration = util.get_duration()
    notification = ""

    if util.notifications:
        notification = "(" + ", ".join(util.notifications) + ")"

    utils.ok("Volume spawned and deleted in %d seconds %s| time=%d" %
             (duration, notification, duration))
Exemple #9
0
 def __init__(self, creds):
     self.cinderclient = Client(**creds)
Exemple #10
0
#!/usr/bin/python

import sys
from lib import openstack
from cinderclient.client import Client

ostack = openstack.OpenStack('config.yaml')
sess = ostack.getSession()

client = Client('1', session=sess)

action = ostack.run(client, sys.argv)

for i in action[sys.argv[0]]:
    print(i.id)
Exemple #11
0
 def __init__(self, creds):
     # TODO hardcoded version
     self.cinder_client = Client(version="2", **creds)