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_volume(): cinder = utils.Cinder() cinder.add_argument('--endpoint_url', metavar='endpoint_url', type=str, help='Override the catalog endpoint.') cinder.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.') cinder.add_argument('--volume_name', metavar='volume_name', type=str, default="monitoring_test", help='Name of the volume to create ' '(monitoring_test by default)') cinder.add_argument('--volume_size', metavar='volume_size', type=int, default=1, help='Size of the volume to create (1 GB by default)') cinder.add_argument('--volume_type', metavar='volume_type', type=str, default=None, help='With multiple backends, choose the volume type.') cinder.add_argument('--availability_zone', metavar='availability_zone', type=str, default=None, help='Specify availability zone.') options, args, client = cinder.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 = CinderUtils(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) util.check_existing_volume(options.volume_name, options.force_delete) util.create_volume(options.volume_name, options.volume_size, options.availability_zone, options.volume_type) util.volume_ready(options.timeout) util.delete_volume() util.volume_deleted(options.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))