Пример #1
0
def clearconfig():
    """
    Clear the LIO configuration of the settings defined by the config object
    We could simply call the clear_existing method of rtsroot - but if the
    admin has defined additional non ceph iscsi exports they'd loose everything

    :param local_gw: (str) gateway name
    :return: (int) 0 = LIO configuration removed/not-required
                   4 = LUN removal problem encountered
                   8 = Gateway (target/tpgs) removal failed
    """

    local_gw = this_host()

    # clear the current config, based on the config objects settings
    lio = LIO()
    gw = Gateway(config)

    # This will fail incoming IO, but wait on outstanding IO to
    # complete normally. We rely on the initiator multipath layer
    # to handle retries like a normal path failure.
    logger.info("Removing iSCSI target from LIO")
    gw.drop_target(local_gw)
    if gw.error:
        logger.error("rbd-target-gw failed to remove target objects")
        return 8

    logger.info("Removing LUNs from LIO")
    lio.drop_lun_maps(config, False)
    if lio.error:
        logger.error("rbd-target-gw failed to remove LUN objects")
        return 4

    logger.info("Active Ceph iSCSI gateway configuration removed")
    return 0
Пример #2
0
    def clear_config(self):
        """
        Remove the target definition form LIO
        :return: None
        """
        # check that there aren't any disks or clients in the configuration
        lio = LIO()

        disk_count = len(
            [disk for disk in lio.ceph_storage_objects(self.config)])
        clients = []
        for tpg in self.tpg_list:
            tpg_clients = [node for node in tpg._list_node_acls()]
            clients += tpg_clients
        client_count = len(clients)

        if disk_count > 0 or client_count > 0:
            self.error = True
            self.error_msg = ("Clients({}) and disks({}) must be removed"
                              "before the gateways".format(
                                  client_count, disk_count))
            return

        self.logger.debug("Clients defined :{}".format(client_count))
        self.logger.debug("Disks defined :{}".format(disk_count))
        self.logger.info("Removing target configuration")

        try:
            self.delete()
        except RTSLibError as err:
            self.error = True
            self.error_msg = "Unable to delete target - {}".format(err)
Пример #3
0
    def delete(self):
        """
        Clear the LIO configuration of the settings defined by the config object
        We could simply call the clear_existing method of rtsroot - but if the
        admin has defined additional non ceph iscsi exports they'd loose
        everything

        :return: (int) 0 = LIO configuration removed/not-required
                       4 = LUN removal problem encountered
                       8 = Gateway (target/tpgs) removal failed
        """

        self.logger.debug("delete received, refreshing local state")
        self.config.refresh()
        if self.config.error:
            self.logger.critical("Problems accessing config object"
                                 " - {}".format(self.config.error_msg))
            return 8

        if "gateways" in self.config.config:
            if self.hostname not in self.config.config["gateways"]:
                self.logger.info("No gateway configuration to remove on this "
                                 "host ({})".format(self.hostname))
                return 0
        else:
            self.logger.info("Configuration object does not hold any gateway "
                             "metadata - nothing to do")
            return 0

        ret = 0

        try:
            self.delete_targets()
        except CephiSCSIError:
            ret = 8

        # unload disks not yet added to targets
        lio = LIO()
        lio.drop_lun_maps(self.config, False)
        if lio.error:
            self.logger.error("failed to remove LUN objects")
            if ret != 0:
                ret = 4

        if ret == 0:
            self.logger.info("Active Ceph iSCSI gateway configuration removed")
        return ret
Пример #4
0
    def map_luns(self, config):
        """
        LIO will have objects already defined by the lun module,
        so this method, brings those objects into the gateways TPG
        """

        lio = LIO()
        # process each storage object added to the gateway, and map to the tpg
        for stg_object in lio.ceph_storage_objects(config):
            for tpg in self.tpg_list:
                self.logger.debug("processing tpg{}".format(tpg.tag))

                if not self.lun_mapped(tpg, stg_object):
                    self.logger.debug("{} needed mapping to "
                                      "tpg{}".format(stg_object.name, tpg.tag))

                    lun_id = int(stg_object.path.split('/')[-2].split('_')[1])

                    try:
                        mapped_lun = LUN(tpg,
                                         lun=lun_id,
                                         storage_object=stg_object)
                        self.changes_made = True
                    except RTSLibError as err:
                        self.logger.error("LUN mapping failed: {}".format(err))
                        self.error = True
                        self.error_msg = err
                        return

                    try:
                        self.bind_alua_group_to_lun(config, mapped_lun)
                    except CephiSCSIInval as err:
                        self.logger.error("Could not bind LUN to ALUA group: "
                                          "{}".format(err))
                        self.error = True
                        self.error_msg = err
                        return
Пример #5
0
def ansible_main():

    fields = {"mode": {"required": True,
                       "type": "str",
                       "choices": ["gateway", "disks"]
                       }
              }

    module = AnsibleModule(argument_spec=fields,
                           supports_check_mode=False)

    run_mode = module.params['mode']
    changes_made = False

    logger.info("START - GATEWAY configuration PURGE started, run mode "
                "is {}".format(run_mode))
    cfg = Config(logger)
    this_host = socket.gethostname().split('.')[0]
    perform_cleanup_tasks = is_cleanup_host(cfg)

    #
    # Purge gateway configuration, if the config has gateways
    if run_mode == 'gateway' and len(cfg.config['gateways'].keys()) > 0:

        lio = LIO()
        gateway = Gateway(cfg)

        if gateway.session_count() > 0:
            module.fail_json(msg="Unable to purge - gateway still has active "
                                 "sessions")

        gateway.drop_target(this_host)
        if gateway.error:
            module.fail_json(msg=gateway.error_msg)

        lio.drop_lun_maps(cfg, perform_cleanup_tasks)
        if lio.error:
            module.fail_json(msg=lio.error_msg)

        if gateway.changed or lio.changed:

            # each gateway removes it's own entry from the config
            cfg.del_item("gateways", this_host)

            if perform_cleanup_tasks:
                cfg.reset = True

                # drop all client definitions from the configuration object
                client_names = cfg.config["clients"].keys()
                for client in client_names:
                    cfg.del_item("clients", client)

                cfg.del_item("gateways", "iqn")
                cfg.del_item("gateways", "created")
                cfg.del_item("gateways", "ip_list")

            cfg.commit()

            changes_made = True

    elif run_mode == 'disks' and len(cfg.config['disks'].keys()) > 0:
        #
        # Remove the disks on this host, that have been registered in the
        # config object
        #
        # if the owner field for a disk is set to this host, this host can
        # safely delete it
        # nb. owner gets set at rbd allocation and mapping time
        images_left = []

        # delete_list will contain a list of pool/image names where the owner
        # is this host
        delete_list = [key.replace('.', '/', 1) for key in cfg.config['disks']
                       if cfg.config['disks'][key]['owner'] == this_host]

        if delete_list:
            images_left = delete_group(module, delete_list, cfg)

        # if the delete list still has entries we had problems deleting the
        # images
        if images_left:
            module.fail_json(msg="Problems deleting the following rbd's : "
                                 "{}".format(','.join(images_left)))

        changes_made = cfg.changed

        logger.debug("ending lock state variable {}".format(cfg.config_locked))

    logger.info("END   - GATEWAY configuration PURGE complete")

    module.exit_json(changed=changes_made,
                     meta={"msg": "Purge of iSCSI settings ({}) "
                                  "complete".format(run_mode)})
Пример #6
0
def ansible_main():

    fields = {"mode": {"required": True,
                       "type": "str",
                       "choices": ["gateway", "disks"]
                       }
              }

    module = AnsibleModule(argument_spec=fields,
                           supports_check_mode=False)

    run_mode = module.params['mode']
    changes_made = False

    logger.info("START - GATEWAY configuration PURGE started, run mode "
                "is {}".format(run_mode))
    cfg = Config(logger)
    this_host = socket.gethostname().split('.')[0]
    perform_cleanup_tasks = is_cleanup_host(cfg)

    #
    # Purge gateway configuration, if the config has gateways
    if run_mode == 'gateway' and len(cfg.config['gateways'].keys()) > 0:

        lio = LIO()
        gateway = Gateway(cfg)

        if gateway.session_count() > 0:
            module.fail_json(msg="Unable to purge - gateway still has active "
                                 "sessions")

        gateway.drop_target(this_host)
        if gateway.error:
            module.fail_json(msg=gateway.error_msg)

        lio.drop_lun_maps(cfg, perform_cleanup_tasks)
        if lio.error:
            module.fail_json(msg=lio.error_msg)

        if gateway.changed or lio.changed:

            # each gateway removes it's own entry from the config
            cfg.del_item("gateways", this_host)

            if perform_cleanup_tasks:
                cfg.reset = True

                # drop all client definitions from the configuration object
                client_names = cfg.config["clients"].keys()
                for client in client_names:
                    cfg.del_item("clients", client)

                cfg.del_item("gateways", "iqn")
                cfg.del_item("gateways", "created")
                cfg.del_item("gateways", "ip_list")

            cfg.commit()

            changes_made = True

    elif run_mode == 'disks' and len(cfg.config['disks'].keys()) > 0:
        #
        # Remove the disks on this host, that have been registered in the
        # config object
        #
        # if the owner field for a disk is set to this host, this host can
        # safely delete it
        # nb. owner gets set at rbd allocation and mapping time
        images_left = []

        # delete_list will contain a list of pool/image names where the owner
        # is this host
        delete_list = [key.replace('.', '/', 1) for key in cfg.config['disks']
                       if cfg.config['disks'][key]['owner'] == this_host]

        if delete_list:
            images_left = delete_group(module, delete_list, cfg)

        # if the delete list still has entries we had problems deleting the
        # images
        if images_left:
            module.fail_json(msg="Problems deleting the following rbd's : "
                                 "{}".format(','.join(images_left)))

        changes_made = cfg.changed

        logger.debug("ending lock state variable {}".format(cfg.config_locked))

    logger.info("END   - GATEWAY configuration PURGE complete")

    module.exit_json(changed=changes_made,
                     meta={"msg": "Purge of iSCSI settings ({}) "
                                  "complete".format(run_mode)})