def check_connection(self, force=False):
     if not self.connection_done or force:
         try:
             # force a connection to the server
             self.connection_done = self.nova_client.limits.get()
         except Exception as e:
             utils.critical("Cannot connect to nova: %s\n" % e)
def check_ceilometer_api():
    ceilometer = utils.Ceilometer()
    ceilometer.add_argument("-w", dest="warning", type=int, default=5, help="Warning timeout for Ceilometer APIs calls")
    ceilometer.add_argument(
        "-c", dest="critical", type=int, default=10, help="Critical timeout for Ceilometer APIs calls"
    )
    options, client = ceilometer.setup()

    elapsed, meters = utils.timeit(client.meters.list)
    if not meters:
        utils.critical("Unable to contact Ceilometer API.")

    if elapsed > options.critical:
        utils.critical(
            "Get meters took more than %d seconds, " "it's too long.|response_time=%d" % (options.critical, elapsed)
        )
    elif elapsed > options.warning:
        utils.warning(
            "Get meters took more than %d seconds, " "it's too long.|response_time=%d" % (options.warning, elapsed)
        )
    else:
        utils.ok(
            "Get meters, Ceilometer API is working: "
            "list %d meters in %d seconds.|response_time=%d" % (len(meters), elapsed, elapsed)
        )
Beispiel #3
0
 def check_connection(self, force=False):
     if not self.connection_done or force:
         try:
             # force a connection to the server
             self.connection_done = self.client.list_ports()
         except Exception as e:
             utils.critical("Cannot connect to neutron: %s\n" % e)
def _check_nova_api():
    nova = utils.Nova()
    nova.add_argument('-w', dest='warning', type=int, default=5,
                      help='Warning timeout for nova APIs calls')
    nova.add_argument('-c', dest='critical', type=int, default=10,
                      help='Critical timeout for nova APIs calls')
    options, args, client = nova.setup()

    def flavors_list():
        return list(client.flavors.list())

    elapsed, flavors = utils.timeit(flavors_list)
    if not flavors:
        utils.critical("Unable to contact nova API.")

    if elapsed > options.critical:
        utils.critical("Get flavors took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get flavors took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get flavors, nova API is working: "
                 "list %d flavors in %d seconds.|response_time=%d" %
                 (len(flavors), elapsed, elapsed))
Beispiel #5
0
def _check_nova_api():
    nova = utils.Nova()
    nova.add_argument('-w', dest='warning', type=int, default=5,
                      help='Warning timeout for nova APIs calls')
    nova.add_argument('-c', dest='critical', type=int, default=10,
                      help='Critical timeout for nova APIs calls')
    options, args, client = nova.setup()

    def flavors_list():
        try:
            return list(client.flavors.list())
        except Exception as ex:
            utils.critical(str(ex))

    elapsed, flavors = utils.timeit(flavors_list)
    if not flavors:
        utils.critical("Unable to contact nova API.")

    if elapsed > options.critical:
        utils.critical("Get flavors took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get flavors took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get flavors, nova API is working: "
                 "list %d flavors in %d seconds.|response_time=%d" %
                 (len(flavors), elapsed, elapsed))
def _check_ceilometer_api():
    ceilometer = utils.Ceilometer()
    ceilometer.add_argument('-w', dest='warning', type=int, default=5,
                            help='Warning timeout for Ceilometer APIs calls')
    ceilometer.add_argument('-c', dest='critical', type=int, default=10,
                            help='Critical timeout for Ceilometer APIs calls')
    options, client = ceilometer.setup()

    def meters_list():
        try:
            return client.meters.list()
        except exceptions.Gone as ex:
            msg = json.loads(ex.response.content)
            utils.warning(re.sub(r'\s\s*', ' ', msg['error_message']))
        except Exception as ex:
            utils.critical(str(ex))

    elapsed, meters = utils.timeit(meters_list)
    if not meters:
        utils.critical("Unable to contact Ceilometer API.")

    if elapsed > options.critical:
        utils.critical("Get meters took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get meters took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get meters, Ceilometer API is working: "
                 "list %d meters in %d seconds.|response_time=%d" %
                 (len(meters), elapsed, elapsed))
Beispiel #7
0
def _check_cinder_api():
    cinder = utils.Cinder()
    cinder.add_argument('-w', dest='warning', type=int, default=5,
                        help='Warning timeout for cinder APIs calls')
    cinder.add_argument('-c', dest='critical', type=int, default=10,
                        help='Critical timeout for cinder APIs calls')
    options, args, client = cinder.setup()

    def quotas_list():
        return client.quotas.get(options.os_tenant_name)

    elapsed, quotas = utils.timeit(quotas_list)
    if not quotas:
        utils.critical("Unable to contact cinder API.")

    if elapsed > options.critical:
        utils.critical("Get quotas took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get quotas took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get quotas, cinder API is working: "
                 "list quota in %d seconds.|response_time=%d" %
                 (elapsed, elapsed))
def _check_cinder_api():
    cinder = utils.Cinder()
    cinder.add_argument('-w', dest='warning', type=int, default=5,
                        help='Warning timeout for cinder APIs calls')
    cinder.add_argument('-c', dest='critical', type=int, default=10,
                        help='Critical timeout for cinder APIs calls')
    options, args, client = cinder.setup()

    def quotas_list():
        try:
            return client.quotas.get(options.os_tenant_name)
        except Exception as ex:
            utils.critical(str(ex))

    elapsed, quotas = utils.timeit(quotas_list)
    if not quotas:
        utils.critical("Unable to contact cinder API.")

    if elapsed > options.critical:
        utils.critical("Get quotas took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get quotas took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get quotas, cinder API is working: "
                 "list quota in %d seconds.|response_time=%d" %
                 (elapsed, elapsed))
def _check_cinder_api():
    cinder = utils.Cinder()
    cinder.add_argument('-w', dest='warning', type=int, default=5,
                        help='Warning timeout for cinder APIs calls')
    cinder.add_argument('-c', dest='critical', type=int, default=10,
                        help='Critical timeout for cinder APIs calls')
    options, args, client = cinder.setup()

    def limits_list():
        return client.limits.get()

    elapsed, limits = utils.timeit(limits_list)
    if not limits:
        utils.critical("Unable to contact cinder API.")

    if elapsed > options.critical:
        utils.critical("Get limits took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get limits took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get limits, cinder API is working: "
                 "list limits in %d seconds.|response_time=%d" %
                 (elapsed, elapsed))
def _check_neutron_api():
    neutron = utils.Neutron()
    neutron.add_argument('-w',
                         dest='warning',
                         type=int,
                         default=5,
                         help='Warning timeout for neutron APIs calls')
    neutron.add_argument('-c',
                         dest='critical',
                         type=int,
                         default=10,
                         help='Critical timeout for neutron APIs calls')
    options, args, client = neutron.setup()

    elapsed, networks = utils.timeit(client.list_networks)
    if not networks or len(networks.get('networks', [])) <= 0:
        utils.critical("Unable to contact neutron API.")

    if elapsed > options.critical:
        utils.critical("Get networks took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get networks took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get networks, neutron API is working: "
                 "list %d networks in %d seconds.|response_time=%d" %
                 (len(networks['networks']), elapsed, elapsed))
Beispiel #11
0
def _check_ceilometer_api():
    ceilometer = utils.Ceilometer()
    ceilometer.add_argument('-w',
                            dest='warning',
                            type=int,
                            default=5,
                            help='Warning timeout for Ceilometer APIs calls')
    ceilometer.add_argument('-c',
                            dest='critical',
                            type=int,
                            default=10,
                            help='Critical timeout for Ceilometer APIs calls')
    options, client = ceilometer.setup()

    elapsed, meters = utils.timeit(client.meters.list)
    if not meters:
        utils.critical("Unable to contact Ceilometer API.")

    if elapsed > options.critical:
        utils.critical("Get meters took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get meters took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get meters, Ceilometer API is working: "
                 "list %d meters in %d seconds.|response_time=%d" %
                 (len(meters), elapsed, elapsed))
 def check_connection(self, force=False):
     if not self.connection_done or force:
         try:
             # force a connection to the server
             self.connection_done = self.nova_client.limits.get()
         except Exception as e:
             utils.critical("Cannot connect to cinder: %s" % e)
Beispiel #13
0
 def quotas_list():
     try:
         return client.quotas.get(
             getattr(options, 'os_project_name',
                     getattr(options, 'os_tenant_name', None)))
     except Exception as ex:
         utils.critical(str(ex))
def _check_glance_api():
    glance = utils.Glance()
    glance.add_argument('-w', dest='warning', type=int, default=5,
                        help='Warning timeout for Glance APIs calls')
    glance.add_argument('-c', dest='critical', type=int, default=10,
                        help='Critical timeout for Glance APIs calls')
    options, args, client = glance.setup()

    def images_list():
        try:
            return list(client.images.list())
        except Exception as ex:
            utils.critical(str(ex))

    elapsed, images = utils.timeit(images_list)
    if not images:
        utils.critical("Unable to contact Glance API.")

    if elapsed > options.critical:
        utils.critical("Get images took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get images took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get images, Glance API is working: "
                 "list %d images in %d seconds.|response_time=%d" %
                 (len(images), elapsed, elapsed))
 def check_connection(self, force=False):
     if not self.connection_done or force:
         try:
             # force a connection to the server
             self.connection_done = self.nova_client.list_ports()
         except Exception as e:
             utils.critical("Cannot connect to neutron: %s\n" % e)
def _check_glance_api():
    glance = utils.Glance()
    glance.add_argument('-w', dest='warning', type=int, default=5,
                        help='Warning timeout for Glance APIs calls')
    glance.add_argument('-c', dest='critical', type=int, default=10,
                        help='Critical timeout for Glance APIs calls')
    options, args, client = glance.setup()

    def images_list():
        try:
            return list(client.images.list())
        except Exception as ex:
            utils.critical(str(ex))

    elapsed, images = utils.timeit(images_list)
    if not images:
        utils.critical("Unable to contact Glance API.")

    if elapsed > options.critical:
        utils.critical("Get images took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get images took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get images, Glance API is working: "
                 "list %d images in %d seconds.|response_time=%d" %
                 (len(images), elapsed, elapsed))
def _check_neutron_api():
    neutron = utils.Neutron()
    neutron.add_argument('-w', dest='warning', type=int, default=5,
                         help='Warning timeout for neutron APIs calls')
    neutron.add_argument('-c', dest='critical', type=int, default=10,
                         help='Critical timeout for neutron APIs calls')
    options, args, client = neutron.setup()

    def network_list():
        try:
            return client.list_networks()
        except Exception as ex:
            utils.critical(str(ex))

    elapsed, networks = utils.timeit(network_list)
    if not networks or len(networks.get('networks', [])) <= 0:
        utils.critical("Unable to contact neutron API.")

    if elapsed > options.critical:
        utils.critical("Get networks took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get networks took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get networks, neutron API is working: "
                 "list %d networks in %d seconds.|response_time=%d" %
                 (len(networks['networks']), elapsed, elapsed))
 def meters_list():
     try:
         return client.meters.list()
     except exceptions.Gone as ex:
         msg = json.loads(ex.response.content)
         utils.warning(re.sub(r'\s\s*', ' ', msg['error_message']))
     except Exception as ex:
         utils.critical(str(ex))
Beispiel #19
0
 def check_connection(self, force=False):
     if not self.connection_done or force:
         try:
             # force a connection to the server
             self.connection_done = self.client.limits.get(
                 tenant_id=self.project)
         except Exception as e:
             utils.critical("Cannot connect to cinder: %s" % e)
 def meters_list():
     try:
         return client.meters.list()
     except exceptions.Gone as ex:
         msg = json.loads(ex.response.content)
         utils.warning(re.sub(r'\s\s*', ' ', msg['error_message']))
     except Exception as ex:
         utils.critical(str(ex))
Beispiel #21
0
 def meters_list():
     try:
         return client.meters.list()
     except exc.HTTPNotFound as ex:
         utils.warning('Did not find Ceilometer API running '
                       'on given endpoint')
     except Exception as ex:
         utils.critical(str(ex))
Beispiel #22
0
def _check_neutron_floating_ip():
    neutron = utils.Neutron()
    neutron.add_argument('--endpoint_url', metavar='endpoint_url', type=str,
                            help='Override the catalog endpoint.')
    neutron.add_argument('--force_delete', action='store_true',
                            help=('If matching floating ip are found, delete '
                                'them and add a notification in the message '
                                'instead of getting out in critical state.'))
    neutron.add_argument('--floating_ip', metavar='floating_ip', type=fip_type,
                            default=None,
                            help=('Regex of IP(s) to check for existance. '
                                'This value can be "all" for conveniance '
                                '(match all ip). This permit to avoid certain '
                                'floating ip to be kept. Its default value '
                                'prevents the removal of any existing '
                                'floating ip'))
    neutron.add_argument('--ext_network_name', metavar='ext_network_name',
                            type=str, default='public',
                            help=('Name of the "public" external network '
                            '(public by default)'))
    options, args, client = neutron.setup()

    project = (options.os_project_id if options.os_project_id else
                options.os_project_name)
    tenant = (options.os_tenant_id if options.os_tenant_id else
                options.os_tenant_name)
    util = NeutronUtils(client, tenant or project)

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

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

    if options.floating_ip:
        util.check_existing_floatingip(options.floating_ip,
                                       options.force_delete)
    util.get_network_id(options.ext_network_name)
    util.create_floating_ip()
    util.delete_floating_ip()

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

    duration = util.get_duration()
    notification = ""

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

    utils.ok("Floating ip created and deleted %s| time=%d"
             % (notification, duration))
Beispiel #23
0
def _check_glance_image_exists():
    glance = utils.Glance()
    glance.add_argument('--req_count',
                        dest='req_count',
                        type=int,
                        required=False,
                        default=0,
                        help='minimum number of images in glance')
    glance.add_argument('--req_images',
                        metavar='req_images',
                        type=str,
                        nargs='+',
                        required=False,
                        help='name of images who must be available')
    options, args, client = glance.setup()

    # Flags resultat
    valid_image = 0
    count = len(list(client.images.list(**{"limit": options.req_count or 1})))

    if options.req_images:
        required_images = options.req_images
        for image in required_images:
            try:
                if len(list(client.images.list(**{"filters": {
                        "name": image
                }}))) == 1:
                    valid_image = valid_image + 1
            except Exception:
                pass

    if options.req_count and count < options.req_count:
        utils.critical("Failed - less than %d images found (%d)" %
                       (options.req_count, count))

    if options.req_images and valid_image < len(required_images):
        utils.critical(
            "Failed - '%s' %d/%d images found " %
            (", ".join(required_images), valid_image, len(required_images)))

    if options.req_images and options.req_count:
        utils.ok("image %s found and enough images >=%d" %
                 (", ".join(required_images), options.req_count))
    elif options.req_images:
        utils.ok("image %s found" % (", ".join(required_images)))
    elif options.req_count:
        utils.ok("more than %d images found" % (count))
    else:
        utils.ok("Connection glance established")
def _check_keystone_api():
    keystone = utils.Keystone()

    def check_token():
        return keystone.run().strip()

    elapsed, token = utils.timeit(check_token)
    if not token:
        utils.critical("Unable to get a token")

    if elapsed > 10:
        utils.warning("Got a token after 10 seconds, it's too long."
                      "|response_time=%s" % elapsed)
    else:
        utils.ok("Got a token, Keystone API is working."
                 "|response_time=%s" % elapsed)
Beispiel #25
0
def _check_keystone_api():
    keystone = utils.Keystone()

    def check_token():
        options, args, client = keystone.setup()
        return client.service_catalog.get_token()

    elapsed, token = utils.timeit(check_token)
    if not token:
        utils.critical("Unable to get a token")

    if elapsed > 10:
        utils.warning("Got a token after 10 seconds, it's too long."
                      "|response_time=%s" % elapsed)
    else:
        utils.ok("Got a token, Keystone API is working."
                 "|response_time=%s" % elapsed)
def _check_keystone_api():
    keystone = utils.Keystone()

    def check_token():
        return keystone.run()

    elapsed, result = utils.timeit(check_token)
    rc, out = result
    if rc:
        utils.critical("Unable to get a token:\n{0}".format(out))

    if elapsed > 10:
        utils.warning("Got a token after 10 seconds, it's too long."
                      "|response_time=%s" % elapsed)
    else:
        utils.ok("Got a token, Keystone API is working."
                 "|response_time=%s" % elapsed)
def _check_keystone_api():
    keystone = utils.Keystone()

    def check_token():
        return keystone.run()

    elapsed, result = utils.timeit(check_token)
    rc, out = result
    if rc:
        utils.critical("Unable to get a token:\n{0}".format(out))

    if elapsed > 10:
        utils.warning("Got a token after 10 seconds, it's too long."
                      "|response_time=%s" % elapsed)
    else:
        utils.ok("Got a token, Keystone API is working."
                 "|response_time=%s" % elapsed)
def check_keystone_api():
    keystone = utils.Keystone()

    def check_token():
        options, args, client = keystone.setup()
        return client.service_catalog.get_token()

    elapsed, token = utils.timeit(check_token)
    if not token:
        utils.critical("Unable to get a token")

    if elapsed > 10:
        utils.warning("Got a token after 10 seconds, it's too long."
                      "|response_time=%s" % elapsed)
    else:
        utils.ok("Got a token, Keystone API is working."
                 "|response_time=%s" % elapsed)
def check_glance():
    glance = utils.Glance()
    glance.add_argument('--req_count', dest='req_count', type=str,
                        required=False,
                        help='minimum number of images in glance')
    glance.add_argument('--req_images', metavar='req_images', type=str,
                        nargs='+', required=False,
                        help='name of images who must be available')
    options, args, client = glance.setup()

    #Flags resultat
    valid_image = 0
    count = 0
    if options.req_count:
        required_count = int(options.req_count)
        if (len(client.get_images(**{"limit": required_count}))
                >= required_count):
            count = 1

    if options.req_images:
        required_images = options.req_images
        for image in required_images:
            try:
                if len(client.get_images(**{"filters": {"name": image}})) == 1:
                    valid_image = valid_image + 1
            except:
                pass

    if options.req_count and count == 0:
        utils.critical("Failed - less than %d images found" % (required_count))

    if options.req_images and valid_image < len(required_images):
        utils.critical("Failed - '%s' %d/%d images found " %
                       (", ".join(required_images), valid_image,
                        len(required_images)))

    if options.req_images and options.req_count:
        utils.ok("image %s found and enough images >=%d" %
                 (", ".join(required_images), required_count))
    elif options.req_images:
        utils.ok("image %s found" % (", ".join(required_images)))
    elif options.req_count:
        utils.ok("more than %d images found" % (count))
    else:
        utils.ok("Connection glance established")
def _check_glance_upload():
    glance = utils.Glance()
    glance.add_argument('--monitoring-image', dest='image_name', type=str,
                        default="openstack-monitoring-test-image",
                        help='Name of the monitoring image')
    options, args, client = glance.setup()

    elapsed, iid = utils.timeit(_upload_image,
                                client=client,
                                name=options.image_name)
    try:
        res = client.images.get(iid)
        if res.status != 'active':
            utils.critical("Unable to upload image in Glance")
    finally:
        client.images.delete(res.id)

    if elapsed > 20:
        utils.warning("Upload image in 20 seconds, it's too long")
    else:
        utils.ok("Glance image uploaded in %s seconds" % elapsed)
def _check_ceilometer_api():
    ceilometer = utils.Ceilometer()
    ceilometer.add_argument('-w',
                            dest='warning',
                            type=int,
                            default=5,
                            help='Warning timeout for Ceilometer APIs calls')
    ceilometer.add_argument('-c',
                            dest='critical',
                            type=int,
                            default=10,
                            help='Critical timeout for Ceilometer APIs calls')
    options, client = ceilometer.setup()

    def meters_list():
        try:
            return client.meters.list()
        except exceptions.Gone as ex:
            msg = json.loads(ex.response.content)
            utils.warning(re.sub(r'\s\s*', ' ', msg['error_message']))
        except Exception as ex:
            utils.critical(str(ex))

    elapsed, meters = utils.timeit(meters_list)
    if not meters:
        utils.critical("Unable to contact Ceilometer API.")

    if elapsed > options.critical:
        utils.critical("Get meters took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get meters took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get meters, Ceilometer API is working: "
                 "list %d meters in %d seconds.|response_time=%d" %
                 (len(meters), elapsed, elapsed))
Beispiel #32
0
def _check_ceilometer_api():
    ceilometer = utils.Ceilometer()
    ceilometer.add_argument('-w',
                            dest='warning',
                            type=int,
                            default=5,
                            help='Warning timeout for Ceilometer APIs calls')
    ceilometer.add_argument('-c',
                            dest='critical',
                            type=int,
                            default=10,
                            help='Critical timeout for Ceilometer APIs calls')
    options, client = ceilometer.setup()

    def meters_list():
        try:
            return client.meters.list()
        except exc.HTTPNotFound as ex:
            utils.warning('Did not find Ceilometer API running '
                          'on given endpoint')
        except Exception as ex:
            utils.critical(str(ex))

    elapsed, meters = utils.timeit(meters_list)
    if not meters:
        utils.critical("Unable to contact Ceilometer API.")

    if elapsed > options.critical:
        utils.critical("Get meters took more than %d seconds, "
                       "it's too long.|response_time=%d" %
                       (options.critical, elapsed))
    elif elapsed > options.warning:
        utils.warning("Get meters took more than %d seconds, "
                      "it's too long.|response_time=%d" %
                      (options.warning, elapsed))
    else:
        utils.ok("Get meters, Ceilometer API is working: "
                 "list %d meters in %d seconds.|response_time=%d" %
                 (len(meters), elapsed, elapsed))
def _check_glance_upload():
    glance = utils.Glance()
    glance.add_argument('--monitoring-image', dest='image_name', type=str,
                        default="openstack-monitoring-test-image",
                        help='Name of the monitoring image')
    options, args, client = glance.setup()

    data_raw = "X" * 1024 * 1024
    elapsed, res = utils.timeit(client.images.create,
                                data=data_raw,
                                disk_format='raw',
                                container_format='bare',
                                name=options.image_name)
    if not res or not res.id or res.status != 'active':
        utils.critical("Unable to upload image in Glance")

    res.delete()

    if elapsed > 20:
        utils.warning("Upload image in 20 seconds, it's too long")
    else:
        utils.ok("Glance image uploaded in %s seconds" % elapsed)
 def network_list():
     try:
         return client.list_networks()
     except Exception as ex:
         utils.critical(str(ex))
def _check_neutron_floating_ip():
    parser = argparse.ArgumentParser(
        description='Check an Floating ip creation. Note that it is able '
                    + 'to delete *all* floating ips from a account, so '
                    + 'ensure that nothing important is running on the '
                    + 'specified account.')
    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 floating ip are found, delete them '
                        + 'and add a notification in the message instead of '
                        + 'getting out in critical state.')

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

    parser.add_argument('--floating_ip', metavar='floating_ip', type=fip_type,
                        default=None,
                        help='Regex of IP(s) to check for existance. '
                        + 'This value can be "all" for conveniance (match '
                        + 'all ip). This permit to avoid certain floating '
                        + 'ip to be kept. Its default value prevents the '
                        + 'removal of any existing floating ip')

    parser.add_argument('--ext_router_name', metavar='ext_router_name',
                        type=str, default='public',
                        help='Name of the "public" router (public by default)')

    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.Client(
            username=args.username,
            tenant_name=args.tenant,
            password=args.password,
            auth_url=args.auth_url,
        )
        nova_client.authenticate()
    except Exception as e:
        utils.critical("Authentication error: %s\n" % e)

    try:
        endpoint = nova_client.service_catalog.get_endpoints(
            'network')['network'][0][args.endpoint_type]
        if args.endpoint_url:
            endpoint = mangle_url(endpoint, args.endpoint_url)

        token = nova_client.service_catalog.get_token()['id']
        if args.verbose:
            logging.basicConfig(level=logging.DEBUG)
        neutron_client = neutron.Client('2.0', endpoint_url=endpoint,
                                        token=token)

    except Exception as e:
        utils.critical("Error creating neutron object: %s\n" % e)
    util = Novautils(neutron_client, nova_client.tenant_id)

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

    if args.floating_ip:
        util.check_existing_floatingip(args.floating_ip, args.force_delete)
    util.get_network_id(args.ext_router_name)
    util.create_floating_ip()
    util.delete_floating_ip()

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

    duration = util.get_duration()
    notification = ""

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

    utils.ok("Floating ip created and deleted %s| time=%d"
             % (notification, duration))
 def images_list():
     try:
         return list(client.images.list())
     except Exception as ex:
         utils.critical(str(ex))
 def quotas_list():
     try:
         return client.quotas.get(options.os_tenant_name)
     except Exception as ex:
         utils.critical(str(ex))
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))
Beispiel #39
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))
 def check_token():
     try:
         return keystone.run()
     except Exception as ex:
         utils.critical(str(ex))
 def flavors_list():
     try:
         return list(client.flavors.list())
     except Exception as ex:
         utils.critical(str(ex))
 def flavors_list():
     try:
         return list(client.flavors.list())
     except Exception as ex:
         utils.critical(str(ex))
 def network_list():
     try:
         return client.list_networks()
     except Exception as ex:
         utils.critical(str(ex))
def _check_neutron_floating_ip():
    parser = argparse.ArgumentParser(
        description='Check an Floating ip creation. Note that it is able ' +
        'to delete *all* floating ips from a account, so ' +
        'ensure that nothing important is running on the ' +
        'specified account.',
        conflict_handler='resolve')

    parser.add_argument('--auth_url',
                        '--os-auth-url',
                        metavar='URL',
                        type=str,
                        default=os.getenv('OS_AUTH_URL'),
                        help='url to use for authetication (Deprecated)')

    parser.add_argument('--os-auth-url',
                        dest='auth_url',
                        type=str,
                        default=os.getenv('OS_AUTH_URL'),
                        help='url to use for authetication')

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

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

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

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

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

    parser.add_argument('--os-tenant-name',
                        dest='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',
                        '--os-endpoint-type',
                        metavar='endpoint_type',
                        type=str,
                        default="publicURL",
                        help='Endpoint type in the catalog request. ' +
                        'Public by default. (Deprecated)')

    parser.add_argument('--os-enpdoint-type',
                        dest='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 floating ip are found, delete """
                        """them and add a notification in the message"""
                        """ instead of getting out in critical """
                        """state.""")

    parser.add_argument('--timeout',
                        '--http-timeout',
                        metavar='timeout',
                        type=int,
                        default=120,
                        help='Max number of second to create/delete a ' +
                        'floating ip (120 by default). (Deprecated)')

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

    parser.add_argument('--floating_ip',
                        metavar='floating_ip',
                        type=fip_type,
                        default=None,
                        help="""Regex of IP(s) to check for existance. """
                        """This value can be "all" for conveniance """
                        """(match all ip). This permit to avoid """
                        """certain floating ip to be kept. Its """
                        """default value prevents the removal of """
                        """any existing floating ip""")

    parser.add_argument(
        '--ext_network_name',
        metavar='ext_network_name',
        type=str,
        default='public',
        help='Name of the "public" external network (public by default)')

    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.Client(
            username=args.username,
            tenant_name=args.tenant,
            password=args.password,
            auth_url=args.auth_url,
        )
        nova_client.authenticate()
    except Exception as e:
        utils.critical("Authentication error: %s\n" % e)

    try:
        endpoint = nova_client.service_catalog.get_endpoints(
            'network')['network'][0][args.endpoint_type]
        if args.endpoint_url:
            endpoint = mangle_url(endpoint, args.endpoint_url)

        token = nova_client.service_catalog.get_token()['id']
        if args.verbose:
            logging.basicConfig(level=logging.DEBUG)
        neutron_client = neutron.Client('2.0',
                                        endpoint_url=endpoint,
                                        token=token)

    except Exception as e:
        utils.critical("Error creating neutron object: %s\n" % e)
    util = Novautils(neutron_client, nova_client.tenant_id)

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

    if args.floating_ip:
        util.check_existing_floatingip(args.floating_ip, args.force_delete)
    util.get_network_id(args.ext_network_name)
    util.create_floating_ip()
    util.delete_floating_ip()

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

    duration = util.get_duration()
    notification = ""

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

    utils.ok("Floating ip created and deleted %s| time=%d" %
             (notification, duration))
def _check_nova_instance():
    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('--image_name', metavar='image_name', type=str,
                        default=default_image_name,
                        help="Image name to use (%s by default)"
                        % default_image_name)

    parser.add_argument('--flavor_name', metavar='flavor_name', type=str,
                        default=default_flavor_name,
                        help="Flavor name to use (%s by default)"
                        % default_flavor_name)

    parser.add_argument('--instance_name', metavar='instance_name', type=str,
                        default=default_instance_name,
                        help="Instance name to use (%s by default)"
                        % default_instance_name)

    parser.add_argument('--force_delete', action='store_true',
                        help='If matching instances 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='2',
                        help='Version of the API to use. 2 by default.')

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

    parser.add_argument('--timeout_delete', metavar='timeout_delete', type=int,
                        default=45,
                        help='Max number of second to delete an existing '
                        + 'instance (45 by default).')

    parser.add_argument('--insecure', action='store_true',
                        help="The server's cert will not be verified")

    parser.add_argument('--network', metavar='network', type=str,
                        help="Override the network name or ID to use")

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

    parser.add_argument('--region_name', metavar='region_name',
                        type=str, help="Region name.")

    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,
                             insecure=args.insecure,
                             region_name=args.region_name)
    except Exception as e:
        utils.critical("Error creating nova communication object: %s\n" % 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_instance(args.instance_name,
                                 args.force_delete,
                                 args.timeout_delete)
    util.get_image(args.image_name)
    util.get_flavor(args.flavor_name)
    util.create_instance(args.instance_name, args.network)
    util.instance_ready(args.timeout)
    util.delete_instance()
    util.instance_deleted(args.timeout)

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

    duration = util.get_duration()
    notification = ""
    if util.notifications:
        notification = "(" + ", ".join(util.notifications) + ")"
    performance = ""
    if util.performances:
        performance = " ".join(util.performances)
    utils.ok("Nova instance spawned and deleted in %d seconds %s| time=%d %s"
             % (duration, notification, duration, performance))
 def images_list():
     try:
         return list(client.images.list())
     except Exception as ex:
         utils.critical(str(ex))
Beispiel #47
0
 def quotas_list():
     try:
         return client.quotas.get(options.os_tenant_name)
     except Exception as ex:
         utils.critical(str(ex))
 def floating_ips_list():
     try:
         return list(client.floating_ips.list())
     except Exception as ex:
         utils.critical(str(ex))
Beispiel #49
0
 def check_token():
     try:
         return keystone.run()
     except Exception as ex:
         utils.critical(str(ex))
def _check_nova_instance():
    parser = argparse.ArgumentParser(
        description='Check an OpenStack Keystone server.',
        conflict_handler='resolve')

    parser.add_argument('--auth_url',
                        '--os-auth-url',
                        metavar='URL',
                        type=str,
                        default=os.getenv('OS_AUTH_URL'),
                        help='url to use for authetication (Deprecated)')

    parser.add_argument('--os-auth-url',
                        dest='auth_url',
                        type=str,
                        default=os.getenv('OS_AUTH_URL'),
                        help='url to use for authetication')

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

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

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

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

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

    parser.add_argument('--os-tenant-name',
                        dest='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',
                        '--os-endpoint-type',
                        metavar='endpoint_type',
                        type=str,
                        default="publicURL",
                        help="""Endpoint type in the catalog request. """
                        """Public by default. (Deprecated)""")

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

    parser.add_argument('--image_name',
                        metavar='image_name',
                        type=str,
                        default=default_image_name,
                        help="Image name to use (%s by default)" %
                        default_image_name)

    parser.add_argument('--flavor_name',
                        metavar='flavor_name',
                        type=str,
                        default=default_flavor_name,
                        help="Flavor name to use (%s by default)" %
                        default_flavor_name)

    parser.add_argument('--instance_name',
                        metavar='instance_name',
                        type=str,
                        default=default_instance_name,
                        help="Instance name to use (%s by default)" %
                        default_instance_name)

    parser.add_argument('--force_delete',
                        action='store_true',
                        help="""If matching instances 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='2',
                        help='Version of the API to use. 2 by default.')

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

    parser.add_argument('--timeout_delete',
                        metavar='timeout_delete',
                        type=int,
                        default=45,
                        help="""Max number of second to delete an existing """
                        """instance (45 by default).""")

    parser.add_argument('--insecure',
                        action='store_true',
                        help="The server's cert will not be verified")

    parser.add_argument('--network',
                        metavar='network',
                        type=str,
                        help="Override the network name or ID to use")

    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,
                             insecure=args.insecure)
    except Exception as e:
        utils.critical("Error creating nova communication object: %s\n" % 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_instance(args.instance_name, args.force_delete,
                                 args.timeout_delete)
    util.get_image(args.image_name)
    util.get_flavor(args.flavor_name)
    util.create_instance(args.instance_name, args.network)
    util.instance_ready(args.timeout)
    util.delete_instance()
    util.instance_deleted(args.timeout)

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

    duration = util.get_duration()
    notification = ""
    if util.notifications:
        notification = "(" + ", ".join(util.notifications) + ")"
    performance = ""
    if util.performances:
        performance = " ".join(util.performances)
    utils.ok("Nova instance spawned and deleted in %d seconds %s| time=%d %s" %
             (duration, notification, duration, performance))
Beispiel #51
0
def _check_nova_instance():
    nova = utils.Nova()
    nova.add_argument('--endpoint_url', metavar='endpoint_url', type=str,
                        help='Override the catalog endpoint.')

    nova.add_argument('--image_name', metavar='image_name', type=str,
                        default=default_image_name,
                        help="Image name to use (%s by default)"
                        % default_image_name)

    nova.add_argument('--flavor_name', metavar='flavor_name', type=str,
                        default=default_flavor_name,
                        help="Flavor name to use (%s by default)"
                        % default_flavor_name)

    nova.add_argument('--instance_name', metavar='instance_name', type=str,
                        default=default_instance_name,
                        help="Instance name to use (%s by default)"
                        % default_instance_name)

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

    nova.add_argument('--timeout_delete', metavar='timeout_delete',
                        type=int, default=45,
                        help='Max number of second to delete an existing '
                             'instance (45 by default).')

    nova.add_argument('--network', metavar='network', type=str, default=None,
                        help="Override the network name to use")

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

    options, args, nova_client = nova.setup()

    util = Novautils(nova_client)

    if options.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 options.endpoint_url:
        util.mangle_url(options.endpoint_url)
        # after mangling the url, the endpoint has changed.  Check that
        # it's valid.
        util.check_connection(force=True)

    util.check_existing_instance(options.instance_name,
                                 options.force_delete,
                                 options.timeout_delete)
    util.get_image(options.image_name)
    util.get_flavor(options.flavor_name)
    util.get_network(options.network)
    util.create_instance(options.instance_name)
    util.instance_ready(options.timeout)
    util.delete_instance()
    util.instance_deleted(options.timeout)

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

    duration = util.get_duration()
    notification = ""
    if util.notifications:
        notification = "(" + ", ".join(util.notifications) + ")"
    performance = ""
    if util.performances:
        performance = " ".join(util.performances)
    utils.ok("Nova instance spawned and deleted in %d seconds %s| time=%d %s"
             % (duration, notification, duration, performance))
 def instances_list():
     try:
         return list(client.servers.list())
     except Exception as ex:
         utils.critical(str(ex))
def _check_nova_instance():
    parser = argparse.ArgumentParser(description="Check an OpenStack Keystone server.", conflict_handler="resolve")

    parser.add_argument(
        "--auth_url",
        "--os-auth-url",
        metavar="URL",
        type=str,
        default=os.getenv("OS_AUTH_URL"),
        help="url to use for authetication (Deprecated)",
    )

    parser.add_argument(
        "--os-auth-url",
        dest="auth_url",
        type=str,
        default=os.getenv("OS_AUTH_URL"),
        help="url to use for authetication",
    )

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

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

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

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

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

    parser.add_argument(
        "--os-tenant-name",
        dest="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",
        "--os-endpoint-type",
        metavar="endpoint_type",
        type=str,
        default="publicURL",
        help="""Endpoint type in the catalog request. """ """Public by default. (Deprecated)""",
    )

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

    parser.add_argument(
        "--image_name",
        metavar="image_name",
        type=str,
        default=default_image_name,
        help="Image name to use (%s by default)" % default_image_name,
    )

    parser.add_argument(
        "--flavor_name",
        metavar="flavor_name",
        type=str,
        default=default_flavor_name,
        help="Flavor name to use (%s by default)" % default_flavor_name,
    )

    parser.add_argument(
        "--instance_name",
        metavar="instance_name",
        type=str,
        default=default_instance_name,
        help="Instance name to use (%s by default)" % default_instance_name,
    )

    parser.add_argument(
        "--force_delete",
        action="store_true",
        help="""If matching instances 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="2", help="Version of the API to use. 2 by default."
    )

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

    parser.add_argument(
        "--timeout_delete",
        metavar="timeout_delete",
        type=int,
        default=45,
        help="""Max number of second to delete an existing """ """instance (45 by default).""",
    )

    parser.add_argument("--insecure", action="store_true", help="The server's cert will not be verified")

    parser.add_argument("--network", metavar="network", type=str, help="Override the network name or ID to use")

    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,
            insecure=args.insecure,
        )
    except Exception as e:
        utils.critical("Error creating nova communication object: %s\n" % 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_instance(args.instance_name, args.force_delete, args.timeout_delete)
    util.get_image(args.image_name)
    util.get_flavor(args.flavor_name)
    util.create_instance(args.instance_name, args.network)
    util.instance_ready(args.timeout)
    util.delete_instance()
    util.instance_deleted(args.timeout)

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

    duration = util.get_duration()
    notification = ""
    if util.notifications:
        notification = "(" + ", ".join(util.notifications) + ")"
    performance = ""
    if util.performances:
        performance = " ".join(util.performances)
    utils.ok(
        "Nova instance spawned and deleted in %d seconds %s| time=%d %s"
        % (duration, notification, duration, performance)
    )