示例#1
0
    def aliases(self, ip_address):
        """
        Given an ip address, return a list of alternate ip addresses

        :param ip_address: The ip address to lookup.
        :return: list of ip addresses
        """
        aliases = []
        network_name = self.host_ip_map.get(ip_address)
        if not network_name:
            return []
        basename = Consumes.basename(network_name)
        for item in self.host_ip_map.keys():
            item_name = self.host_ip_map.get(item)
            if item_name:
                item_basename = Consumes.basename(item_name)
                if item_basename == basename:
                    aliases.append(item)
        return aliases
示例#2
0
 def _iter_volume_groups(self):
     for server in self.config.get('global').get('all_servers'):
         server_name = server.get('name')
         disk_model = server.get('disk_model')
         region_name = server.get('region')
         rack_id = server.get('rack')
         lv_index = 0
         for volume_group in disk_model.get('volume_groups', []):
             vg_name = volume_group.get('name')
             physical_volumes = volume_group.get('physical_volumes')
             for logical_volume in volume_group.get('logical_volumes', []):
                 lv_name = logical_volume.get('name')
                 percent = logical_volume.get('size')
                 consumer = logical_volume.get('consumer')
                 if consumer and consumer.get('name', 'other') == 'swift':
                     attrs = consumer.get('attrs')
                     if not attrs:
                         raise SwiftModelException('The attrs item is'
                                                   ' missing from '
                                                   ' logical volume'
                                                   ' %s in disk model %s' %
                                                   (logical_volume.get(
                                                       'name'),
                                                    disk_model.get('name')))
                     if attrs.get('rings', None) is None:
                         raise SwiftModelException('The rings item is'
                                                   ' missing from logical'
                                                   ' volume'
                                                   ' %s in disk model %s' %
                                                   (logical_volume.get(
                                                       'name'),
                                                    disk_model.get('name')))
                     for ring in attrs.get('rings'):
                         if isinstance(ring, str):
                             ring_name = ring
                         else:
                             ring_name = ring.get('name')
                         server_ip, bind_port = self._get_server_bind(
                             ring_name, server_name)
                         if not server_ip:
                             # TODO: this may be worth warning
                             break
                         swift_drive_name = LVM_MOUNT + str(lv_index)
                         device_name = '/dev/' + vg_name + '/' + lv_name
                         device_info = DeviceInfo({
                             'region_name': region_name,
                             'rack_id': rack_id,
                             'region_id': 1,    # later, the rack id may
                             'zone_id': 1,      # change these defaults
                             'server_name': Consumes.basename(
                                 server_name),
                             'server_ip': server_ip,
                             'server_bind_port': bind_port,
                             'replication_ip': server_ip,
                             'replication_bind_port': bind_port,
                             'swift_drive_name': swift_drive_name,
                             'device_name': device_name,
                             'ring_name': ring_name,
                             'group_type': 'lvm',
                             'block_devices': {'percent': percent,
                                               'physicals':
                                                   physical_volumes},
                             'presence': 'present'})
                         yield device_info
                     lv_index += 1
示例#3
0
    def _iter_device_groups(self):
        for server in self.config.get('global').get('all_servers'):
            server_name = server.get('name')
            disk_model = server.get('disk_model')
            region_name = server.get('region')
            rack_id = server.get('rack')
            device_index = 0
            for device_group in disk_model.get('device_groups', []):
                consumer = device_group.get('consumer')
                if consumer and consumer.get('name', 'other') == 'swift':
                    attrs = consumer.get('attrs')
                    if not attrs:
                        raise SwiftModelException('The attrs item is'
                                                  ' missing from device-groups'
                                                  ' %s in disk model %s' %
                                                  (device_group.get('name'),
                                                   disk_model.get('name')))
                    devices = device_group.get('devices')
                    if attrs.get('rings', None) is None:
                        raise SwiftModelException('The rings item is'
                                                  ' missing from device-groups'
                                                  ' %s in disk model %s' %
                                                  (device_group.get('name'),
                                                   disk_model.get('name')))
                    for device in devices:
                        for ring in attrs.get('rings'):
                            if isinstance(ring, str):
                                ring_name = ring
                            else:
                                ring_name = ring.get('name')
                            server_ip, bind_port = self._get_server_bind(
                                ring_name, server_name)
                            if not server_ip:
                                # When a swift service (example swift-account)
                                # is configured in the input model to run a
                                # node, we expect the node to be in the
                                # "consumes" variable. e.g., consumes_SWF_ACC
                                # should have this node in its list. Since we
                                # failed to get the network name/port, it means
                                # that it is not.
                                # In model terms, we have a disk model that
                                # calls out that a device hosts a ring (e.g.
                                # account), but the node is not configured
                                # to run SWF-ACC.
                                # TODO: this may be worth warning
                                break

                            swift_drive_name = DISK_MOUNT + str(device_index)
                            device_info = DeviceInfo({
                                'region_name': region_name,
                                'rack_id': rack_id,
                                'region_id': 1,      # later, the rack id may
                                'zone_id': 1,        # change these defaults
                                'server_name': Consumes.basename(server_name),
                                'server_ip': server_ip,
                                'server_bind_port': bind_port,
                                'replication_ip': server_ip,
                                'replication_bind_port': bind_port,
                                'swift_drive_name': swift_drive_name,
                                'device_name': device.get('name'),
                                'ring_name': ring_name,
                                'group_type': 'device',
                                'block_devices': {'percent': '100%',
                                                  'physicals':
                                                      [device.get('name')]},
                                'presence': 'present'})

                            yield device_info
                        device_index += 1