コード例 #1
0
ファイル: __main__.py プロジェクト: onisimchukv/bridgy
def unmount_handler(args, config):
    Sshfs.ensure_sshfs_installed()

    question = "What instances would you like to have unmounted?"

    if args['-a']:
        instances = inventory.instances(config)
        sshfs_objs = [Sshfs(config, instance, dry_run=args['-d']) for instance in instances]
        mounted_targets = [obj.instance for obj in sshfs_objs if obj.is_mounted]
        target_instances = mounted_targets
    else:
        desired_targets = args['<host>']
        instances = inventory.search(config, desired_targets)
        sshfs_objs = [Sshfs(config, instance, dry_run=args['-d']) for instance in instances]
        mounted_targets = [obj.instance for obj in sshfs_objs if obj.is_mounted]
        target_instances = prompt_targets(question, instances=mounted_targets, multiple=False, config=config)

    if len(target_instances) == 0:
        logger.error("No matching mounts found")
        if args['-a']:
            logger.warn("Did you select targets with <space> and confirm with <enter>?")
        sys.exit(1)

    for sshfsObj in sshfs_objs:
        if sshfsObj.instance in target_instances:
            if sshfsObj.unmount():
                logger.info("Unmounted %s" % sshfsObj.instance.name)
            else:
                logger.error("Unable to unmount %s" % sshfsObj.instance.name)
コード例 #2
0
ファイル: __main__.py プロジェクト: onisimchukv/bridgy
def list_inventory_handler(args, config):
    instances = []
    for ip, name, aliases, source in inventory.instances(config):
        if aliases:
            instances.append( (ip, name, ', '.join(aliases), source) )
        else:
            instances.append( (ip, name, '--- None ---', source) )
    logger.info(tabulate(instances, headers=['Name', 'Address/Dns', 'Aliases', 'Source']))
コード例 #3
0
ファイル: __main__.py プロジェクト: vtejapy/bridgy
def list_inventory_handler(args, config):
    instances = []
    for instance in sorted(inventory.instances(config, filter_sources=args['--source'])):
        if instance.aliases:
            instances.append( (instance.name, instance.address, '\n'.join(instance.aliases), instance.source, instance.type) )
        else:
            instances.append( (instance.name, instance.address, '--- None ---', instance.source, instance.type) )
    logger.info(tabulate(instances, headers=['Name', 'Address/Dns', 'Aliases', 'Source', 'Type']))
コード例 #4
0
def test_inclusion_filtering(mocker):
    test_dir = os.path.dirname(os.path.abspath(__file__))
    cache_dir = os.path.join(test_dir, 'aws_stubs')

    config = Config({'inventory': {'include_pattern': 'test.*'}})

    aws_obj = AwsInventory(cache_dir=cache_dir,
                           access_key_id='access_key_id',
                           secret_access_key='secret_access_key',
                           session_token='session_token',
                           region='region')

    mock_inventory = mocker.patch.object(bridgy.inventory, 'inventory')
    mock_inventory.return_value = aws_obj

    all_instances = instances(config)

    expected_instances = [
        Instance(name='test-forms',
                 address='devbox',
                 aliases=('devbox',
                          'ip-172-31-8-185.us-west-2.compute.internal',
                          'i-e54cbaeb'),
                 source='aws'),
        Instance(name='test-account-svc',
                 address='devbox',
                 aliases=('devbox',
                          'ip-172-31-0-139.us-west-2.compute.internal',
                          'i-f4d726fa'),
                 source='aws'),
        Instance(name='test-game-svc',
                 address='devbox',
                 aliases=('devbox',
                          'ip-172-31-0-141.us-west-2.compute.internal',
                          'i-f3d726fd'),
                 source='aws'),
        Instance(name='test-pubsrv',
                 address='devbox',
                 aliases=('devbox',
                          'ip-172-31-2-38.us-west-2.compute.internal',
                          'i-0f500447384e95942'),
                 source='aws'),
        Instance(name='test-pubsrv',
                 address='devbox',
                 aliases=('devbox',
                          'ip-172-31-2-39.us-west-2.compute.internal',
                          'i-0f500447384e95943'),
                 source='aws')
    ]

    assert set(all_instances) == set(expected_instances)
コード例 #5
0
def list_inventory_handler(args, config):
    instances = []
    for address, name, aliases, source, user, key in inventory.instances(
            config):
        if aliases:
            instances.append(
                (address, name, '\n'.join(aliases), user, key, source))
        else:
            instances.append(
                (address, name, '--- None ---', user, key, source))
    logger.info(
        tabulate(instances,
                 headers=[
                     'Name', 'Address/Dns', 'Aliases', 'User', 'IdentityFile',
                     'Source'
                 ]))
コード例 #6
0
def test_exclusion_filtering(mocker):
    test_dir = os.path.dirname(os.path.abspath(__file__))
    cache_dir = os.path.join(test_dir, 'aws_stubs')

    config = Config({'inventory': {'exclude_pattern': 'test.*'}})

    aws_obj = AwsInventory(cache_dir=cache_dir,
                           access_key_id='access_key_id',
                           secret_access_key='secret_access_key',
                           session_token='session_token',
                           region='region')
    inventorySet = InventorySet()
    inventorySet.add(aws_obj)

    mock_inventory = mocker.patch.object(bridgy.inventory, 'inventory')
    mock_inventory.return_value = inventorySet

    all_instances = instances(config)

    expected_instances = [
        Instance(name='devlab-forms',
                 address='devbox',
                 aliases=('devbox',
                          'ip-172-31-0-138.us-west-2.compute.internal',
                          'i-f7d726f9'),
                 source='aws',
                 container_id=None,
                 type='VM'),
        Instance(name='devlab-pubsrv',
                 address='devbox',
                 aliases=('devbox',
                          'ip-172-31-0-142.us-west-2.compute.internal',
                          'i-f5d726fb'),
                 source='aws',
                 container_id=None,
                 type='VM'),
        Instance(name='devlab-game-svc',
                 address='devbox',
                 aliases=('devbox',
                          'ip-172-31-0-140.us-west-2.compute.internal',
                          'i-f2d726fc'),
                 source='aws',
                 container_id=None,
                 type='VM')
    ]

    assert set(all_instances) == set(expected_instances)