def main():
    if mounted(device_name):
        print('Preparation.')
        print('device_dismount(', device_name, sep='', end=')\n')
        device_dismount(device_name)
        time.sleep(1)
        print()

    print('Verify absence of unreachable device.')
    in_inventory = device_name in inventory()
    in_mounted = device_name in inventory_mounted()
    print(device_name + ' in inventory', in_inventory, sep=': ')
    print(device_name + ' is mounted', in_mounted, sep=': ')
    assert not in_inventory
    assert not in_mounted
    del in_inventory, in_mounted

    print()

    print('Discover effect of mounting unreachable device.')
    print('device_mount(' + device_name,
          device_address,
          device_port,
          sep=', ',
          end=')\n')
    device_mount(device_name, device_address, device_port, device_username,
                 device_password)
    time.sleep(1)
    in_connected = device_name in inventory_connected()
    in_mounted = device_name in inventory_mounted()
    print(device_name + ' is connected', in_connected, sep=': ')
    print(device_name + ' is mounted', in_mounted, sep=': ')
    assert not in_connected
    assert in_mounted
def main():
    if mounted(device_name):
        print('Preparation.')     
        print('device_dismount(', device_name, sep='', end=')\n')
        device_dismount(device_name)
        time.sleep(1)
        print()
        
    print('Verify absence of unreachable device.')     
    in_inventory = device_name in inventory()
    in_mounted = device_name in inventory_mounted()
    print(device_name + ' in inventory', in_inventory, sep=': ')
    print(device_name + ' is mounted', in_mounted, sep=': ')
    assert not in_inventory
    assert not in_mounted
    del in_inventory, in_mounted

    print()
    
    print('Discover effect of mounting unreachable device.')     
    print('device_mount(' + device_name, device_address, device_port, sep=', ', end=')\n')
    device_mount(device_name, device_address, device_port, device_username, device_password)
    time.sleep(1)
    in_connected = device_name in inventory_connected()
    in_mounted = device_name in inventory_mounted()
    print(device_name + ' is connected', in_connected, sep=': ')
    print(device_name + ' is mounted', in_mounted, sep=': ')
    assert not in_connected
    assert in_mounted
 def setUp(self):
     mounted_list = inventory_mounted()
     for device_name in mounted_list:
         print('setup: device_dismount(' + device_name, end=')\n')
         device_dismount(device_name)
     
     if mounted_list:
         print('Sleep to allow Controller to update...')
         time.sleep(2)
         self.assertFalse(inventory_mounted(), 'Dismount required: ' + str(inventory_mounted()))
    def setUp(self):
        mounted_list = inventory_mounted()
        for device_name in mounted_list:
            print('setup: device_dismount(' + device_name, end=')\n')
            device_dismount(device_name)

        if mounted_list:
            print('Sleep to allow Controller to update...')
            time.sleep(2)
            self.assertFalse(inventory_mounted(),
                             'Dismount required: ' + str(inventory_mounted()))
 def setUp(self):
     mounted_list = inventory_mounted()
     if mounted_list:
         for device_name in mounted_list:
             device_dismount(device_name)
             self.assertFalse(mounted(device_name),
                              'Expected dismount: ' + device_name)
def main():
    print(plain(doc(device_dismount)))
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return os.EX_OK
    print('There are no mounted devices to dismount. Demonstration cancelled.')
    return os.EX_TEMPFAIL
Example #7
0
def inventory_purge():
    """
    Dismount any mounted network device that is unconnected.
    """
    device_names = set(inventory_mounted()) - set(inventory_connected())
    for device in device_names:
        device_dismount(device)
Example #8
0
def inventory_purge():
    """
    Dismount any mounted network device that is unconnected.
    """
    device_names = set(inventory_mounted()) - set(inventory_connected())
    for device in device_names:
        device_dismount(device)
def main():
    print(plain(doc(device_dismount)))
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return EX_OK
    print('There are no mounted devices to dismount. Demonstration cancelled.')
    return EX_TEMPFAIL
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(management_interface)))
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return os.EX_OK
    print("There are no suitable network devices. Demonstration cancelled.")
    return os.EX_TEMPFAIL
def main():
    print(plain(doc(connected)))
    device_names = inventory_mounted()
    if not device_names:
        print('There are no devices mounted on the Controller.')
    else:
        device_name = device_names[0]
        print('is connected(%s):' % device_name, connected(device_name))
Example #12
0
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(management_interface)))
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return EX_OK
    print("There are no suitable network devices. Demonstration cancelled.")
    return EX_TEMPFAIL
def main():
    print(plain(doc(connected)))
    device_names = inventory_mounted()
    if not device_names:
        print('There are no devices mounted on the Controller.')
    else:
        device_name = device_names[0]
        print('is connected(%s):' % device_name, connected(device_name))
def main():
    """ Select a device and demonstrate."""
    print(plain(doc(device_control)))
    print("DeviceControl fields:", *DeviceControl._fields, sep="\n\t", end="\n\n")
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return EX_OK
    print("There are no suitable network devices. Demonstration cancelled.")
    return EX_TEMPFAIL
def main():
    print(plain(doc(device_dismount)))
    mounted_list = inventory_mounted()
    if not mounted_list:
        print('There are no mounted devices to dismount.')
    else:
        for device_name in mounted_list:
            print('device_dismount(' + device_name, end=')\n')
            device_dismount(device_name)
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(device_control)))
    print('DeviceControl fields:', *DeviceControl._fields, sep='\n\t', end='\n\n')
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return os.EX_OK
    print("There are no suitable network devices. Demonstration cancelled.")
    return os.EX_TEMPFAIL
def main():
    print(cleandoc(__doc__))
    print()
    print('1. Determine the inventory of network devices and choose one.')
    print('inventory_mounted()')
    device_names = inventory_mounted()
    if not device_names:
        print("There are no mounted network devices. Demonstration cancelled.")
        return EX_TEMPFAIL
    else:
        print_table(device_names, headers='device-name')
    for device_name in inventory_mounted():
        capabilities = demonstrate(device_name)
        if capabilities:
            return EX_OK
    print()
    print("No capabilities were discovered. Demonstration incomplete.")
    return EX_TEMPFAIL
 def test_device_dismount(self):
     """
     Apply function device_dismount to every device that is mounted.
     """
     mounted_list = inventory_mounted()
     self.assertTrue(mounted_list, 'One or more devices must be mounted.')
     for device_name in mounted_list:
         device_dismount(device_name)
         self.assertFalse(mounted(device_name), 'Expected not mounted: ' + device_name)
def main():
    print(cleandoc(__doc__))
    print()
    print('1. Determine the inventory of network devices and choose one.')
    print('inventory_mounted()')
    device_names = inventory_mounted()
    if not device_names:
        print("There are no mounted network devices. Demonstration cancelled.")
        return EX_TEMPFAIL
    else:
        print_table(device_names, headers='device-name')
    for device_name in inventory_mounted():
        capabilities = demonstrate(device_name)
        if capabilities:
            return EX_OK
    print()
    print("No capabilities were discovered. Demonstration incomplete.")
    return EX_TEMPFAIL
def main():
    print(plain(doc(device_dismount)))
    mounted_list = inventory_mounted()
    if not mounted_list:
        print("There are no mounted devices to dismount.")
    else:
        for device_name in mounted_list:
            print("device_dismount(" + device_name, end=")\n")
            device_dismount(device_name)
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(interface_names)))
    mounted_list = inventory_mounted()
    connected_list = inventory_connected()
    device_list = list(set(connected_list) & set(mounted_list))
    for device_name in device_list:
        return demonstrate(device_name)
    print('There are no mounted, connected devices to examine. Demonstration cancelled.')
Example #22
0
 def test_device_dismount(self):
     """
     Apply function device_dismount to every device that is mounted.
     """
     mounted_list = inventory_mounted()
     self.assertTrue(mounted_list, 'One or more devices must be mounted.')
     for device_name in mounted_list:
         device_dismount(device_name)
         self.assertFalse(mounted(device_name),
                          'Expected not mounted: ' + device_name)
    def test_dismount_device(self):
        mounted_list = inventory_mounted()
        self.assertTrue(mounted_list, 'One or more devices must be mounted.')
        for device_name in mounted_list:
            print('test: device_dismount(' + device_name, end=')\n')
            device_dismount(device_name)

        print('Sleep to allow Controller to update...')
        time.sleep(2)
        for device_name in mounted_list:
            self.assertFalse(mounted(device_name), 'Mounted: ' + device_name)
    def test_dismount_device(self):
        mounted_list = inventory_mounted()
        self.assertTrue(mounted_list, 'One or more devices must be mounted.')
        for device_name in mounted_list:
            print('test: device_dismount(' + device_name, end=')\n')
            device_dismount(device_name)

        print('Sleep to allow Controller to update...')
        time.sleep(2)
        for device_name in mounted_list:
            self.assertFalse(mounted(device_name), 'Mounted: ' + device_name)
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(interface_names)))
    mounted_list = inventory_mounted()
    connected_list = inventory_connected()
    device_list = list(set(connected_list) & set(mounted_list))
    for device_name in device_list:
        return demonstrate(device_name)
    print(
        'There are no mounted, connected devices to examine. Demonstration cancelled.'
    )
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(device_control)))
    print('DeviceControl fields:',
          *DeviceControl._fields,
          sep='\n\t',
          end='\n\n')
    for device_name in inventory_mounted():
        demonstrate(device_name)
        return EX_OK
    print("There are no suitable network devices. Demonstration cancelled.")
    return EX_TEMPFAIL
def match(device_name, interface_network):
    """ Discover matching interface on a different device."""
    for other_device in inventory_mounted():
        if other_device == device_name:
            continue
        for interface_name in interface_names(other_device):
            interface_config = interface_configuration_tuple(other_device, interface_name)
            if interface_config.address is None:
                # Skip network interface with unassigned IP address.             
                continue
            other_network = to_ip_network(interface_config.address, interface_config.netmask)
            if other_network == interface_network:
                print('Match %s/%s/%s to %s/%s' % (device_name, interface_config.address, interface_config.netmask, \
                                                   other_device, interface_network))
                return interface_config.address
    return None
 def setUp(self):
     unmounted_list = inventory_unmounted()
     for device_name in unmounted_list:
         device_config = self.network_device_config[device_name]
         print('setup: device_mount(' + device_name, *device_config.values(), sep=', ', end=')\n')
         device_mount(
             device_name,
             device_config['address'],
             device_config['port'],
             device_config['username'],
             device_config['password'])
     
     if unmounted_list:
         print('Sleep to allow Controller to update...')
         time.sleep(2)
         self.assertTrue(inventory_mounted(), 'Not mounted: ' + str(inventory_unmounted()))
def match(device_name, interface_network):
    """ Discover matching interface on a different device."""
    for other_device in inventory_mounted():
        if other_device == device_name:
            continue
        for interface_name in interface_names(other_device):
            interface_config = interface_configuration_tuple(other_device, interface_name)
            if interface_config.address is None:
                # Skip network interface with unassigned IP address.             
                continue
            other_network = to_ip_network(interface_config.address, interface_config.netmask)
            if other_network == interface_network:
                print('Match %s/%s/%s to %s/%s' % (device_name, interface_config.address, interface_config.netmask, \
                                                   other_device, interface_network))
                return interface_config.address
    return None
def main():
    ''' Document and demonstrate the function until a capable device is found.'''
    print(plain(doc(capability_discovery)))
    for device_name in inventory_mounted():
        try:
            if demonstrate(device_name):
                return os.EX_OK
        except Exception as e:
            if connected(device_name):
                # Unexplained exception.                
                print(e)
                return os.EX_TEMPFAIL
            else:
                # Expect exception when device not connected.             
                print('connected(%s): False' % device_name)
    return os.EX_TEMPFAIL
Example #31
0
    def setUp(self):
        unmounted_list = inventory_unmounted()
        for device_name in unmounted_list:
            device_config = self.network_device_config[device_name]
            print('setup: device_mount(' + device_name,
                  *device_config.values(),
                  sep=', ',
                  end=')\n')
            device_mount(device_name, device_config['address'],
                         device_config['port'], device_config['username'],
                         device_config['password'])

        if unmounted_list:
            print('Sleep to allow Controller to update...')
            time.sleep(2)
            self.assertTrue(inventory_mounted(),
                            'Not mounted: ' + str(inventory_unmounted()))
Example #32
0
def main():
    inventory_set = set(inventory())
    inventory_connected_set = set(inventory_connected())
    inventory_not_connected_set = set(inventory_not_connected())
    inventory_mounted_set = set(inventory_mounted())
    inventory_unmounted_set = set(inventory_unmounted())
    empty_set = set()

    print("The set of 'connected' devices is a subset of the inventory:",
          inventory_connected_set <= inventory_set)
    assert inventory_connected_set <= inventory_set

    print(
        "The set of 'not connected' devices is also a subset of the inventory:",
        inventory_not_connected_set <= inventory_set)
    assert inventory_not_connected_set <= inventory_set

    print(
        "There are no network devices in both the 'connected' set and the 'not connected' set:",
        inventory_not_connected_set & inventory_connected_set == empty_set)
    assert inventory_not_connected_set & inventory_connected_set == empty_set

    print(
        "Every network device in the inventory is in either the 'connected' set or the 'not connected' set:",
        inventory_connected_set | inventory_not_connected_set == inventory_set)
    assert inventory_connected_set | inventory_not_connected_set == inventory_set

    print()

    print("The set of 'mounted' devices is a subset of the inventory:",
          inventory_mounted_set <= inventory_set)
    assert inventory_mounted_set <= inventory_set

    print(
        "The set of 'unmounted' devices has no intersection with the inventory:",
        inventory_unmounted_set & inventory_set == empty_set)
    assert inventory_unmounted_set & inventory_set == empty_set, 'Expect no intersection, got %s' % (
        inventory_unmounted_set & inventory_set)

    print(
        "There are no network devices in both the 'mounted' set and the 'unmounted' set:",
        inventory_unmounted_set & inventory_mounted_set == empty_set)
    assert inventory_unmounted_set & inventory_mounted_set == empty_set
def main():
    mounted_list = inventory_mounted()
    if not mounted_list:
        print('There are no mounted devices to dismount.')
    else:
        for device_name in mounted_list:
            print('device_dismount(' + device_name, end=')\n')
            device_dismount(device_name)
        mounted_list = set(mounted_list)
        sleep_total = 0
        remaining_connected = mounted_list & set(inventory_connected())
        while remaining_connected:
            if sleep_total > sleep_interval * 100:
                print('Time out after %s seconds', sleep_total)
                return 2
            print('Disconnecting', *remaining_connected)
            sleep(sleep_interval)
            sleep_total += sleep_interval
            remaining_connected = mounted_list & set(inventory_connected())
            continue
        print('Dismounted %s device(s), slept for %s seconds' % (len(mounted_list), sleep_total))
        return EX_OK
    return EX_TEMPFAIL
def main():
    inventory_set = set(inventory())
    inventory_connected_set = set(inventory_connected())
    inventory_not_connected_set = set(inventory_not_connected())
    inventory_mounted_set = set(inventory_mounted())
    inventory_unmounted_set = set(inventory_unmounted())
    empty_set = set()
    
    print("The set of 'connected' devices is a subset of the inventory:",
           inventory_connected_set <= inventory_set)
    assert inventory_connected_set <= inventory_set
    
    print("The set of 'not connected' devices is also a subset of the inventory:",
           inventory_not_connected_set <= inventory_set)
    assert inventory_not_connected_set <= inventory_set
    
    print("There are no network devices in both the 'connected' set and the 'not connected' set:",
           inventory_not_connected_set & inventory_connected_set == empty_set)
    assert inventory_not_connected_set & inventory_connected_set == empty_set
    
    print("Every network device in the inventory is in either the 'connected' set or the 'not connected' set:",
           inventory_connected_set | inventory_not_connected_set == inventory_set)
    assert inventory_connected_set | inventory_not_connected_set == inventory_set
    
    print()
    
    print("The set of 'mounted' devices is a subset of the inventory:",
           inventory_mounted_set <= inventory_set)
    assert inventory_mounted_set <= inventory_set
    
    print("The set of 'unmounted' devices has no intersection with the inventory:",
           inventory_unmounted_set & inventory_set == empty_set)
    assert inventory_unmounted_set & inventory_set == empty_set, 'Expect no intersection, got %s' % (inventory_unmounted_set & inventory_set)
    
    print("There are no network devices in both the 'mounted' set and the 'unmounted' set:",
           inventory_unmounted_set & inventory_mounted_set == empty_set)
    assert inventory_unmounted_set & inventory_mounted_set == empty_set
def main():
    mounted_list = inventory_mounted()
    if not mounted_list:
        print('There are no mounted devices to dismount.')
    else:
        for device_name in mounted_list:
            print('device_dismount(' + device_name, end=')\n')
            device_dismount(device_name)
        mounted_list = set(mounted_list)
        sleep_total = 0
        remaining_connected = mounted_list & set(inventory_connected())
        while remaining_connected:
            if sleep_total > sleep_interval * 100:
                print('Time out after %s seconds', sleep_total)
                return 2
            print('Disconnecting', *remaining_connected)
            sleep(sleep_interval)
            sleep_total += sleep_interval
            remaining_connected = mounted_list & set(inventory_connected())
            continue
        print('Dismounted %s device(s), slept for %s seconds' %
              (len(mounted_list), sleep_total))
        return EX_OK
    return EX_TEMPFAIL
def main():
    print(plain(doc(inventory_mounted)))
    print(inventory_mounted())
def main():
    print(plain(doc(inventory_mounted)))
    print(inventory_mounted())
 def setUp(self):
     mounted_list = inventory_mounted()
     if mounted_list:
         for device_name in mounted_list:
             device_dismount(device_name)
             self.assertFalse(mounted(device_name), "Expected dismount: " + device_name)