コード例 #1
0
 def add_disk(self, disk, success_msg='ok'):
     rc = 0
     api_vars = {"disk": disk}
     targetdisk_api = ('{}://localhost:{}/api/'
                       'targetlun/{}'.format(self.http_mode,
                                             settings.config.api_port,
                                             self.target_iqn))
     api = APIRequest(targetdisk_api, data=api_vars)
     api.put()
     if api.response.status_code == 200:
         config = get_config()
         owner = config['disks'][disk]['owner']
         ui_root = self.get_ui_root()
         disk = ui_root.disks.disk_lookup[disk]
         disk.owner = owner
         self.logger.debug("- Disk '{}' owner updated to {}".format(
             disk.image_id, owner))
         TargetDisk(self, disk.image_id)
         self.logger.debug("- TargetDisk '{}' added".format(disk.image_id))
         if success_msg:
             self.logger.info(success_msg)
     else:
         self.logger.error("Failed - {}".format(
             response_message(api.response, self.logger)))
         rc = 1
     return rc
コード例 #2
0
    def ui_command_auth(self, action=None):
        """
        Disable/enable ACL authentication or clear CHAP settings for all clients on the target.

        - disable_acl ... Disable initiator name based ACL authentication.

        - enable_acl .... Enable initiator name based ACL authentication.

        - nochap ........ Remove chap authentication for all clients across all gateways.
                          Initiator name based authentication will then be used.

        e.g.
        auth disable_acl

        """

        if not action:
            self.logger.error(
                "Missing auth argument. Use 'auth nochap|disable_acl|enable_acl'"
            )
            return

        if action not in ['nochap', 'enable_acl', 'disable_acl']:
            self.logger.error(
                "Invalid auth argument. Use 'auth nochap|disable_acl|enable_acl'"
            )
            return

        if action == 'nochap':
            for client in self.children:
                client.set_auth(action, None, None, None)
        else:
            target_iqn = self.parent.name
            api_vars = {'action': action}
            targetauth_api = ('{}://localhost:{}/api/'
                              'targetauth/{}'.format(self.http_mode,
                                                     settings.config.api_port,
                                                     target_iqn))
            api = APIRequest(targetauth_api, data=api_vars)
            api.put()
            if api.response.status_code == 200:
                self.config = get_config()
                self.logger.info('ok')
            else:
                self.logger.error("Failed to {}: "
                                  "{}".format(
                                      action,
                                      response_message(api.response,
                                                       self.logger)))
                return
コード例 #3
0
ファイル: client.py プロジェクト: wwdillingham/ceph-iscsi
    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?
        try:
            client_iqn, iqn_type = normalize_wwn(['iqn'], client_iqn)
        except RTSLibError:
            self.logger.error("IQN name '{}' is not valid for "
                              "iSCSI".format(client_iqn))
            return

        target_iqn = self.parent.name

        # Issue the API call to create the client
        client_api = ('{}://localhost:{}/api/'
                      'client/{}/{}'.format(self.http_mode,
                                            settings.config.api_port,
                                            target_iqn,
                                            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.config = get_config()
            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)
コード例 #4
0
    def __init__(self, parent):
        UIGroup.__init__(self, 'hosts', parent)

        # lun_map dict is indexed by the rbd name, pointing to a list
        # of clients that have that rbd allocated.
        self.lun_map = {}
        self.client_map = {}

        # record the shortcut
        shortcut = self.shell.prefs['bookmarks'].get('hosts', None)
        if not shortcut or shortcut is not self.path:
            self.shell.prefs['bookmarks']['hosts'] = self.path
            self.shell.prefs.save()
            self.shell.log.debug("Bookmarked %s as %s." % (self.path, 'hosts'))

        self.config = get_config()
コード例 #5
0
    def ui_command_clearconfig(self, confirm=None):
        """
        The 'clearconfig' command allows you to return the configuration to an
        unused state: LIO on each gateway will be cleared, and gateway
        definitions in the configuration object will be removed.

        > clearconfig confirm=true

        In order to run the clearconfig command, all clients and disks *must*
        have already have been removed.
        """

        self.logger.debug("CMD: clearconfig confirm={}".format(confirm))

        confirm = self.ui_eval_param(confirm, 'bool', False)
        if not confirm:
            self.logger.error("To clear the configuration you must specify "
                              "confirm=true")
            return

        # get a new copy of the config dict over the local API
        # check that there aren't any disks or client listed
        current_config = get_config()
        for target_iqn, target in current_config['targets'].items():
            num_clients = len(target['clients'].keys())
            if num_clients > 0:
                self.logger.error("{} - Clients({}) must be removed first"
                                  " before clearing the gateway "
                                  "configuration".format(target_iqn,
                                                         num_clients))
                return

        num_disks = len(current_config['disks'].keys())
        if num_disks > 0:
            self.logger.error("Disks({}) must be removed first"
                              " before clearing the gateway "
                              "configuration".format(num_disks))
            return

        for target_iqn, target in current_config['targets'].items():
            target_config = current_config['targets'][target_iqn]

            self.clear_config(target_config['portals'], target_iqn)
コード例 #6
0
 def _get_meta_data_config(self):
     config = get_config()
     if not config:
         return
     self._apply_config(config['disks'][self.image_id])