Example #1
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))
Example #2
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))