def ui_command_create(self, target_iqn): """ Create an iSCSI target. This target is defined across all gateway nodes, providing the client with a single 'image' for iscsi discovery. Only ONE iSCSI target is supported, at this time. """ self.logger.debug("CMD: /iscsi create {}".format(target_iqn)) defined_targets = [tgt.name for tgt in self.children] if len(defined_targets) > 0: self.logger.error("Only ONE iscsi target image is supported") return # We need LIO to be empty, so check there aren't any targets defined local_lio = root.RTSRoot() current_target_names = [tgt.wwn for tgt in local_lio.targets] if current_target_names: self.logger.error("Local LIO instance already has LIO configured " "with a target - unable to continue") return # OK - this request is valid, but is the IQN usable? if not valid_iqn(target_iqn): self.logger.error("IQN name '{}' is not valid for " "iSCSI".format(target_iqn)) return # 'safe' to continue with the definition self.logger.debug("Create an iscsi target definition in the UI") local_api = ('{}://127.0.0.1:{}/api/' 'target/{}'.format(self.http_mode, settings.config.api_port, target_iqn)) api = APIRequest(local_api) api.put() if api.response.status_code == 200: self.logger.info('ok') # create the target entry in the UI tree Target(target_iqn, self) else: self.logger.error("Failed to create the target on the local node") raise GatewayAPIError("iSCSI target creation failed - " "{}".format(response_message(api.response, self.logger)))
def ui_command_delete(self, client_iqn): """ You may delete a client from the configuration, but you must ensure the client has logged out of the iscsi gateways. Attempting to delete a client that has an open session will fail the request e.g. delete <client_iqn> """ self.logger.debug("CMD: ../hosts/ delete {}".format(client_iqn)) self.logger.debug("Client DELETE for {}".format(client_iqn)) # is the IQN usable? if not valid_iqn(client_iqn): self.logger.error("IQN name '{}' is not valid for " "iSCSI".format(client_iqn)) return client_api = ('{}://{}:{}/api/' 'client/{}'.format(self.http_mode, "127.0.0.1", settings.config.api_port, client_iqn)) api = APIRequest(client_api) api.delete() if api.response.status_code == 200: # Delete successful across all gateways self.logger.debug("- '{}' removed and configuration " "updated".format(client_iqn)) client = [client for client in self.children if client.name == client_iqn][0] # remove any rbd maps from the lun_map for this client rbds_mapped = [lun.rbd_name for lun in client.children] for rbd in rbds_mapped: self.update_lun_map('remove', rbd, client_iqn) self.delete(client) self.logger.info('ok') else: # client delete request failed self.logger.error(response_message(api.response, self.logger))
def ui_command_create(self, client_iqn): """ Clients may be created using the 'create' sub-command. The initial definition will be added to each gateway without any authentication set. Once a client is created the admin is automatically placed in the context of the new client definition for auth and disk configuration operations. e.g. > create <client_iqn> """ self.logger.debug("CMD: ../hosts/ create {}".format(client_iqn)) cli_seed = {"luns": {}, "auth": {}} # is the IQN usable? if not valid_iqn(client_iqn): self.logger.error("IQN name '{}' is not valid for " "iSCSI".format(client_iqn)) return # Issue the API call to create the client client_api = ('{}://127.0.0.1:{}/api/' 'client/{}'.format(self.http_mode, settings.config.api_port, client_iqn)) self.logger.debug("Client CREATE for {}".format(client_iqn)) api = APIRequest(client_api) api.put() if api.response.status_code == 200: Client(self, client_iqn, cli_seed) self.logger.debug("- Client '{}' added".format(client_iqn)) self.logger.info('ok') else: self.logger.error("Failed: {}".format(response_message(api.response, self.logger))) return # switch the current directory to the new client for auth or disk # definitions as part of the users workflow return self.ui_command_cd(client_iqn)