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 _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))
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))