示例#1
0
def sys_info(query_type=None):
    """
    Provide system information based on the query_type
    Valid query types are: ipv4_addresses, checkconf and checkversions
    **RESTRICTED**
    """

    if query_type == 'ipv4_addresses':

        return jsonify(data=ipv4_addresses()), 200

    elif query_type == 'checkconf':

        local_hash = gen_file_hash('/etc/ceph/iscsi-gateway.cfg')
        return jsonify(data=local_hash), 200

    elif query_type == 'checkversions':

        config_errors = pre_reqs_errors()
        if config_errors:
            return jsonify(data=config_errors), 500
        else:
            return jsonify(data='checks passed'), 200

    else:
        # Request Unknown
        return jsonify(message="Unknown /sysinfo query"), 404
示例#2
0
    def __init__(self, logger, iqn, gateway_ip_list, enable_portal=True):
        """
        Instantiate the class
        :param iqn: iscsi iqn name for the gateway
        :param gateway_ip_list: list of IP addresses to be defined as portals
                to LIO
        :return: gateway object
        """

        self.error = False
        self.error_msg = ''

        self.enable_portal = enable_portal  # boolean to trigger portal
        # IP creation

        self.logger = logger  # logger object

        self.iqn = iqn

        # If the ip list received has data in it, this is a target we need to
        # act on the IP's provided, otherwise just set to null
        if gateway_ip_list:
            # if the ip list provided doesn't match any ip of this host, abort
            # the assumption here is that we'll only have one matching ip in
            # the list!
            matching_ip = set(gateway_ip_list).intersection(ipv4_addresses())
            if len(list(matching_ip)) == 0:
                self.error = True
                self.error_msg = ("gateway IP addresses provided do not match"
                                  " any ip on this host")
                return

            self.active_portal_ip = list(matching_ip)[0]
            self.logger.debug("active portal will use "
                              "{}".format(self.active_portal_ip))

            self.gateway_ip_list = gateway_ip_list
            self.logger.debug("tpg's will be defined in this order"
                              " - {}".format(self.gateway_ip_list))
        else:
            # without gateway_ip_list passed in this is a 'init' or
            # 'clearconfig' request
            self.gateway_ip_list = []
            self.active_portal_ip = []

        self.changes_made = False
        self.config_updated = False

        # self.portal = None
        self.target = None
        self.tpg = None
        self.tpg_list = []

        self.config = Config(self.logger)
        if self.config.error:
            self.error = self.config.error
            self.error_msg = self.config.error_msg

        self.controls = self.config.config.get('controls', {}).copy()
        self._add_properies()
示例#3
0
def is_cleanup_host(config):
    """
    decide which gateway host should be responsible for any non-specific
    updates to the config object
    :param config: configuration dict from the rados pool
    :return: boolean indicating whether the addition cleanup should be
    performed by the running host
    """
    cleanup = False

    if 'ip_list' in config.config["gateways"]:

        gw_1 = config.config["gateways"]["ip_list"][0]

        usable_ip = get_ip(gw_1)
        if usable_ip != '0.0.0.0':
            if usable_ip in ipv4_addresses():
                cleanup = True

    return cleanup
示例#4
0
def is_cleanup_host(config):
    """
    decide which gateway host should be responsible for any non-specific updates to the
    config object
    :param config: configuration dict from the rados pool
    :return: boolean indicating whether the addition cleanup should be performed
             by the running host
    """
    cleanup = False

    if 'ip_list' in config.config["gateways"]:

        gw_1 = config.config["gateways"]["ip_list"][0]

        usable_ip = get_ip(gw_1)
        if usable_ip != '0.0.0.0':
            if usable_ip in ipv4_addresses():
                cleanup = True

    return cleanup
示例#5
0
    def __init__(self, logger, iqn, gateway_ip_list, enable_portal=True):
        """
        Instantiate the class
        :param iqn: iscsi iqn name for the gateway
        :param gateway_ip_list: list of IP addresses to be defined as portals to LIO
        :return: gateway object
        """

        self.error = False
        self.error_msg = ''

        self.enable_portal = enable_portal  # boolean to trigger portal IP creation

        self.logger = logger  # logger object

        self.iqn = iqn

        # if the ip list provided doesn't match any ip of this host, abort
        # the assumption here is that we'll only have one matching ip in the list!
        matching_ip = set(gateway_ip_list).intersection(ipv4_addresses())
        if len(list(matching_ip)) == 0:
            self.error = True
            self.error_msg = "gateway IP addresses provided do not match any ip on this host"
            return

        self.active_portal_ip = list(matching_ip)[0]
        self.logger.debug("active portal will use {}".format(
            self.active_portal_ip))

        self.gateway_ip_list = gateway_ip_list
        self.logger.debug("tpg's will be defined in this order - {}".format(
            self.gateway_ip_list))

        self.changes_made = False
        self.config_updated = False

        # self.portal = None
        self.target = None
        self.tpg = None
        self.tpg_list = []
示例#6
0
    def define_luns(logger, config, gateway):
        """
        define the disks in the config to LIO
        :param logger: logger object to print to
        :param config: configuration dict from the rados pool
        :param gateway: (object) gateway object - used for mapping
        :raises CephiSCSIError.
        """

        local_gw = this_host()

        # sort the disks dict keys, so the disks are registered in a specific
        # sequence
        disks = config.config['disks']
        srtd_disks = sorted(disks)
        pools = {disks[disk_key]['pool'] for disk_key in srtd_disks}

        if pools is None:
            logger.info("No LUNs to export")
            return True

        ips = ipv4_addresses()

        with rados.Rados(conffile=settings.config.cephconf) as cluster:

            for pool in pools:

                logger.debug("Processing rbd's in '{}' pool".format(pool))

                with cluster.open_ioctx(pool) as ioctx:

                    pool_disks = [
                        disk_key for disk_key in srtd_disks
                        if disk_key.startswith(pool)
                    ]
                    for disk_key in pool_disks:

                        pool, image_name = disk_key.split('.')

                        try:
                            with rbd.Image(ioctx, image_name) as rbd_image:
                                RBDDev.rbd_lock_cleanup(logger, ips, rbd_image)

                                lun = LUN(logger, pool, image_name,
                                          rbd_image.size(), local_gw)
                                if lun.error:
                                    raise CephiSCSIError(
                                        "Error defining rbd "
                                        "image {}".format(disk_key))

                                lun.allocate()
                                if lun.error:
                                    raise CephiSCSIError("Error unable to "
                                                         "register  {} with "
                                                         "LIO - {}".format(
                                                             disk_key,
                                                             lun.error_msg))

                        except rbd.ImageNotFound:
                            raise CephiSCSIError("Disk '{}' defined to the "
                                                 "config, but image '{}' can "
                                                 "not be found in '{}' "
                                                 "pool".format(
                                                     disk_key, image_name,
                                                     pool))

        # Gateway Mapping : Map the LUN's registered to all tpg's within the
        # LIO target
        gateway.manage('map')
        if gateway.error:
            raise CephiSCSIError("Error mapping the LUNs to the tpg's within "
                                 "the iscsi Target")