def main():
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(dest='mode', help='Add or delete a config')
    add_parser = subparsers.add_parser('add')
    add_parser.add_argument('appliance_uuid', type=str, help='Specify the appliance UUID to configure.')
    add_parser.add_argument('url_or_file', type=url_or_file, help='Specify file location of metadata or specify a url to automatically parse information.')
    add_parser.add_argument('display_name', nargs='?', default=None, help='Specify a namne that will be displayed in the UI.')
    add_parser.add_argument('-n', '--index', type=int, dest='config_index', default=0, choices=xrange(0, 4), help='Specify configuration index for single sign on.  This is used when configuring multiple SSO options, i.e., first config is 0, second is 1, and so on...')
    add_parser.add_argument('--skip-verify-ssl', default=False, action='store_true', help='Skips validation of SSL when retrieving metadata from a URL')
    add_parser.add_argument('-c', '--config', type=str, dest='config', default='papi_client.ini')
    delete_parser = subparsers.add_parser('delete')
    delete_parser.add_argument('appliance_uuid', type=str, help='Specify the appliance UUID to configure.')
    delete_parser.add_argument('config_index', type=int, choices=xrange(0, 4), help='Specify which configuration to remove.')
    delete_parser.add_argument('-c', '--config', type=str, dest='config', default='papi_client.ini')
    args = parser.parse_args()
    logger = get_logger()
    try:
        config_parser = get_config_parser(args.config)
        client = get_papi_client(config_parser, logger)
        if (args.mode == 'delete'):
            saml_configuration = SAMLApplianceConfiguration(args.appliance_uuid, args.config_index)
            saml_configuration.delete_sso(client)
            return 0
        if args.url_or_file.get('url', None):
            xml_content = xml_read_from_url(args.url_or_file['url'], args.skip_verify_ssl)
        else:
            xml_content = xml_read_from_file(args.url_or_file['file'])
        metadata = MetadataExtractor(xml_content)
        display_name = args.display_name
        if (not display_name):
            display_name = urlparse(metadata.entity_id).netloc
        logger.info(('Adding SSO configuration (index %d) for appliance %s' % (args.config_index, args.appliance_uuid)))
        saml_configuration = SAMLApplianceConfiguration(args.appliance_uuid, args.config_index, metadata=metadata, display_name=display_name)
        saml_configuration.add_sso(client)
    except (MissingValue, InvalidXML, InvalidFile, InvalidURL) as e:
        logger.error(e.message)
        return 1
    return 0
def main():
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(dest='mode', help='Add or delete a config')
    add_parser = subparsers.add_parser('add')
    add_parser.add_argument('appliance_uuid', type=str, help='Specify the appliance UUID to configure.')
    add_parser.add_argument('url_or_file', type=url_or_file, help='Specify file location of metadata or specify a url to automatically parse information.')
    add_parser.add_argument('display_name', nargs='?', default=None, help='Specify a namne that will be displayed in the UI.')
    add_parser.add_argument('-n', '--index', type=int, dest='config_index', default=0, choices=xrange(0, 4), help='Specify configuration index for single sign on.  This is used when configuring multiple SSO options, i.e., first config is 0, second is 1, and so on...')
    add_parser.add_argument('--skip-verify-ssl', default=False, action='store_true', help='Skips validation of SSL when retrieving metadata from a URL')
    add_parser.add_argument('-c', '--config', type=str, dest='config', default='papi_client.ini')
    delete_parser = subparsers.add_parser('delete')
    delete_parser.add_argument('appliance_uuid', type=str, help='Specify the appliance UUID to configure.')
    delete_parser.add_argument('config_index', type=int, choices=xrange(0, 4), help='Specify which configuration to remove.')
    delete_parser.add_argument('-c', '--config', type=str, dest='config', default='papi_client.ini')
    args = parser.parse_args()
    logger = get_logger()
    try:
        config_parser = get_config_parser(args.config)
        client = get_papi_client(config_parser, logger)
        if (args.mode == 'delete'):
            saml_configuration = SAMLApplianceConfiguration(args.appliance_uuid, args.config_index)
            saml_configuration.delete_sso(client)
            return 0
        if args.url_or_file.get('url', None):
            xml_content = xml_read_from_url(args.url_or_file['url'], args.skip_verify_ssl)
        else:
            xml_content = xml_read_from_file(args.url_or_file['file'])
        metadata = MetadataExtractor(xml_content)
        display_name = args.display_name
        if (not display_name):
            display_name = urlparse(metadata.entity_id).netloc
        logger.info(('Adding SSO configuration (index %d) for appliance %s' % (args.config_index, args.appliance_uuid)))
        saml_configuration = SAMLApplianceConfiguration(args.appliance_uuid, args.config_index, metadata=metadata, display_name=display_name)
        saml_configuration.add_sso(client)
    except (MissingValue, InvalidXML, InvalidFile, InvalidURL) as e:
        logger.error(e.message)
        return 1
    return 0