def apply_config(): """ procesing logic that orchestrates the creation of the iSCSI gateway to LIO. """ # access config_loading from the outer scope, for r/w global config_loading config_loading = True local_gw = this_host() logger.info("Reading the configuration object to update local LIO " "configuration") # first check to see if we have any entries to handle - if not, there is # no work to do.. if "gateways" not in config.config: logger.info("Configuration is empty - nothing to define to LIO") config_loading = False return if local_gw not in config.config['gateways']: logger.info("Configuration does not have an entry for this host({}) - " "nothing to define to LIO".format(local_gw)) config_loading = False return # at this point we have a gateway entry that applies to the running host portals_already_active = portals_active() logger.info("Processing Gateway configuration") gateway = define_gateway() logger.info("Processing LUN configuration") try: LUN.define_luns(logger, config, gateway) except CephiSCSIError as err: halt("Could not define LUNs: {}".format(err)) logger.info("Processing client configuration") try: GWClient.define_clients(logger, config) except CephiSCSIError as err: halt("Could not define clients: {}".format(err)) if not portals_already_active: # The tpgs, luns and clients are all defined, but the active tpg # doesn't have an IP bound to it yet (due to the enable_portals=False # setting above) logger.info("Adding the IP to the enabled tpg, allowing iSCSI logins") gateway.enable_active_tpg(config) if gateway.error: halt("Error enabling the IP with the active TPG: {}".format( gateway.error_msg)) config_loading = False logger.info("iSCSI configuration load complete")
def define_target(self, target_iqn, gw_ip_list, target_only=False): """ define the iSCSI target and tpgs :param target_iqn: (str) target iqn :param gw_ip_list: (list) gateway ip list :param target_only: (bool) if True only setup target :return: (object) GWTarget object """ # GWTarget Definition : Handle the creation of the Target/TPG(s) and # Portals. Although we create the tpgs, we flick the enable_portal flag # off so the enabled tpg will not have an outside IP address. This # prevents clients from logging in too early, failing and giving up # because the nodeACL hasn't been defined yet (yes Windows I'm looking # at you!) # first check if there are tpgs already in LIO (True) - this would # indicate a restart or reload call has been made. If the tpg count is # 0, this is a boot time request self.logger.info("Setting up {}".format(target_iqn)) target = GWTarget(self.logger, target_iqn, gw_ip_list, enable_portal=self.portals_active(target_iqn)) if target.error: raise CephiSCSIError("Error initializing iSCSI target: " "{}".format(target.error_msg)) target.manage('target') if target.error: raise CephiSCSIError("Error creating the iSCSI target (target, " "TPGs, Portals): {}".format(target.error_msg)) if not target_only: self.logger.info("Processing LUN configuration") try: LUN.define_luns(self.logger, self.config, target) except CephiSCSIError as err: self.logger.error("{} - Could not define LUNs: " "{}".format(target.iqn, err)) raise self.logger.info("{} - Processing client configuration". format(target.iqn)) try: GWClient.define_clients(self.logger, self.config, target.iqn) except CephiSCSIError as err: self.logger.error("Could not define clients: {}".format(err)) raise if not target.enable_portal: # The tpgs, luns and clients are all defined, but the active tpg # doesn't have an IP bound to it yet (due to the # enable_portals=False setting above) self.logger.info("{} - Adding the IP to the enabled tpg, " "allowing iSCSI logins".format(target.iqn)) target.enable_active_tpg(self.config) if target.error: raise CephiSCSIError("{} - Error enabling the IP with the " "active TPG: {}".format(target.iqn, target.error_msg)) return target