Exemple #1
0
    def setup(cls, t_obj, tpg, err_func):
        tpg_obj = cls(t_obj, tag=tpg.get("tag", None))
        set_attributes(tpg_obj, tpg.get("attributes", {}), err_func)
        set_parameters(tpg_obj, tpg.get("parameters", {}), err_func)

        for lun in tpg.get("luns", []):
            LUN.setup(tpg_obj, lun, err_func)

        for p in tpg.get("portals", []):
            NetworkPortal.setup(tpg_obj, p, err_func)

        for acl in tpg.get("node_acls", []):
            NodeACL.setup(tpg_obj, acl, err_func)

        tpg_obj.enable = tpg.get("enable", True)
        dict_remove(tpg, ("luns", "portals", "node_acls", "tag", "attributes", "parameters", "enable"))
        for name, value in tpg.iteritems():
            if value:
                try:
                    setattr(tpg_obj, name, value)
                except:
                    err_func("Could not set tpg %s attribute '%s'" % (tpg_obj.tag, name))
Exemple #2
0
    def setup(cls, tpg_obj, acl, err_func):
        if "node_wwn" not in acl:
            err_func("'node_wwn' missing in node_acl")
            return
        try:
            acl_obj = cls(tpg_obj, acl["node_wwn"])
        except RTSLibError as e:
            err_func("Error when creating NodeACL for %s: %s" % (acl["node_wwn"], e))
            return

        set_attributes(acl_obj, acl.get("attributes", {}), err_func)

        for mlun in acl.get("mapped_luns", []):
            MappedLUN.setup(tpg_obj, acl_obj, mlun, err_func)

        dict_remove(acl, ("attributes", "mapped_luns", "node_wwn"))
        for name, value in acl.iteritems():
            if value:
                try:
                    setattr(acl_obj, name, value)
                except:
                    err_func("Could not set nodeacl %s attribute '%s'" % (acl["node_wwn"], name))
Exemple #3
0
    def setup(cls, tpg_obj, acl, err_func):
        if 'node_wwn' not in acl:
            err_func("'node_wwn' missing in node_acl")
            return
        try:
            acl_obj = cls(tpg_obj, acl['node_wwn'])
        except RTSLibError:
            err_func("Error when creating NodeACL for %s" % acl['node_wwn'])
            return

        set_attributes(acl_obj, acl.get('attributes', {}))

        for mlun in acl.get('mapped_luns', []):
            MappedLUN.setup(tpg_obj, acl_obj, mlun, err_func)

        dict_remove(acl, ('attributes', 'mapped_luns', 'node_wwn'))
        for name, value in acl.iteritems():
            if value:
                try:
                    setattr(acl_obj, name, value)
                except:
                    err_func("Could not set nodeacl %s attribute '%s'" %
                             (acl['node_wwn'], name))
Exemple #4
0
    def setup(cls, tpg_obj, acl, err_func):
        if 'node_wwn' not in acl:
            err_func("'node_wwn' missing in node_acl")
            return
        try:
            acl_obj = cls(tpg_obj, acl['node_wwn'])
        except RTSLibError:
            err_func("Error when creating NodeACL for %s" % acl['node_wwn'])
            return

        set_attributes(acl_obj, acl.get('attributes', {}))

        for mlun in acl.get('mapped_luns', []):
            MappedLun.setup(tpg_obj, acl_obj, mlun, err_func)

        dict_remove(acl, ('attributes', 'mapped_luns', 'node_wwn'))
        for name, value in acl.iteritems():
            if value:
                try:
                    setattr(acl_obj, name, value)
                except:
                    err_func("Could not set nodeacl %s attribute '%s'" %
                             (acl['node_wwn'], name))
Exemple #5
0
    def setup(cls, t_obj, tpg, err_func):
        tpg_obj = cls(t_obj, tag=tpg.get("tag", None))
        set_attributes(tpg_obj, tpg.get('attributes', {}), err_func)
        set_parameters(tpg_obj, tpg.get('parameters', {}), err_func)

        for lun in tpg.get('luns', []):
            LUN.setup(tpg_obj, lun, err_func)

        for p in tpg.get('portals', []):
            NetworkPortal.setup(tpg_obj, p, err_func)

        for acl in tpg.get('node_acls', []):
            NodeACL.setup(tpg_obj, acl, err_func)

        tpg_obj.enable = tpg.get('enable', True)
        dict_remove(tpg, ('luns', 'portals', 'node_acls', 'tag', 'attributes',
                          'parameters', 'enable'))
        for name, value in tpg.iteritems():
            if value:
                try:
                    setattr(tpg_obj, name, value)
                except:
                    err_func("Could not set tpg %s attribute '%s'" %
                             (tpg_obj.tag, name))
Exemple #6
0
    def setup(cls, t_obj, tpg, err_func):
        tpg_obj = cls(t_obj, tag=tpg.get("tag", None))
        tpg_obj.enable = tpg.get('enable', True)
        set_attributes(tpg_obj, tpg.get('attributes', {}))
        set_parameters(tpg_obj, tpg.get('parameters', {}))

        for lun in tpg.get('luns', []):
            LUN.setup(tpg_obj, lun, err_func)

        for p in tpg.get('portals', []):
            NetworkPortal.setup(tpg_obj, p, err_func)

        for acl in tpg.get('node_acls', []):
            NodeACL.setup(tpg_obj, acl, err_func)

        dict_remove(tpg, ('luns', 'portals', 'node_acls', 'tag',
                          'attributes', 'parameters', 'enable'))
        for name, value in tpg.iteritems():
            if value:
                try:
                    setattr(tpg_obj, name, value)
                except:
                    err_func("Could not set tpg %s attribute '%s'" %
                             (tpg_obj.tag, name))
Exemple #7
0
    def restore(self, config, clear_existing=False, abort_on_error=False):
        '''
        Takes a dict generated by dump() and reconfigures the target to match.
        Returns list of non-fatal errors that were encountered.
        '''
        if clear_existing:
            self.clear_existing(confirm=True)
        elif list(self.storage_objects) or list(self.targets):
            raise RTSLibError(
                "storageobjects or targets present, not restoring." +
                " Set clear_existing=True?")

        errors = []

        if abort_on_error:

            def err_func(err_str):
                raise RTSLibError(err_str)
        else:

            def err_func(err_str):
                errors.append(err_str + ", skipped")

        for index, so in enumerate(config.get('storage_objects', [])):
            if 'name' not in so:
                err_func("'name' not defined in storage object %d" % index)
                continue
            try:
                so_cls = storageobjects[so['plugin']]
            except KeyError:
                err_func(
                    "'plugin' not defined or invalid in storageobject %s" %
                    so['name'])
                continue
            kwargs = so.copy()
            dict_remove(kwargs,
                        ('exists', 'attributes', 'plugin', 'buffered_mode'))
            try:
                so_obj = so_cls(**kwargs)
            except (TypeError, ValueError):
                err_func("Could not create StorageObject %s" % so['name'])
                continue
            try:
                set_attributes(so_obj, so.get('attributes', {}))
            except RTSLibError:
                err_func("Could not set an attribute for %s" % so['name'])

        # Don't need to create fabric modules
        for index, fm in enumerate(config.get('fabric_modules', [])):
            if 'name' not in fm:
                err_func("'name' not defined in fabricmodule %d" % index)
                continue
            for fm_obj in self.fabric_modules:
                if fm['name'] == fm_obj.name:
                    fm_obj.setup(fm, err_func)
                    break

        for index, t in enumerate(config.get('targets', [])):
            if 'wwn' not in t:
                err_func("'wwn' not defined in target %d" % index)
                continue
            if 'fabric' not in t:
                err_func("target %s missing 'fabric' field" % t['wwn'])
                continue
            if t['fabric'] not in (f.name for f in self.fabric_modules):
                err_func("Unknown fabric '%s'" % t['fabric'])
                continue

            fm_obj = FabricModule(t['fabric'])

            # Instantiate target
            Target.setup(fm_obj, t, err_func)

        return errors
Exemple #8
0
    def restore(self, config, clear_existing=False):
        '''
        Takes a dict generated by dump() and reconfigures the target to match.
        Returns list of non-fatal errors that were encountered.
        '''
        if clear_existing:
            self.clear_existing(confirm=True)
        elif list(self.storage_objects) or list(self.targets):
            raise RTSLibError("storageobjects or targets present, not restoring." +
                              " Set clear_existing=True?")

        errors = []

        def err_func(err_str):
            errors.append(err_str + ", skipped")

        for index, so in enumerate(config.get('storage_objects', [])):
            if 'name' not in so:
                err_func("'name' not defined in storage object %d" % index)
                continue
            try:
                so_cls = storageobjects[so['plugin']]
            except KeyError:
                err_func("'plugin' not defined or invalid in storageobject %s" % so['name'])
                continue
            kwargs = so.copy()
            dict_remove(kwargs, ('exists', 'attributes', 'plugin', 'buffered_mode'))
            try:
                so_obj = so_cls(**kwargs)
            except (TypeError, ValueError):
                err_func("Could not create StorageObject %s" % so['name'])
                continue
            try:
                set_attributes(so_obj, so.get('attributes', {}))
            except RTSLibError:
                err_func("Could not set an attribute for %s" % so['name'])

        # Don't need to create fabric modules
        for index, fm in enumerate(config.get('fabric_modules', [])):
            if 'name' not in fm:
                err_func("'name' not defined in fabricmodule %d" % index)
                continue
            for fm_obj in self.fabric_modules:
                if fm['name'] == fm_obj.name:
                    fm_obj.setup(fm, err_func)
                    break

        for index, t in enumerate(config.get('targets', [])):
            if 'wwn' not in t:
                err_func("'wwn' not defined in target %d" % index)
                continue
            if 'fabric' not in t:
                err_func("target %s missing 'fabric' field" % t['wwn'])
                continue
            if t['fabric'] not in (f.name for f in self.fabric_modules):
                err_func("Unknown fabric '%s'" % t['fabric'])
                continue

            fm_obj = FabricModule(t['fabric'])

            # Instantiate target
            Target.setup(fm_obj, t, err_func)

        return errors
Exemple #9
0
    def restore(self, config, clear_existing=False, abort_on_error=False):
        '''
        Takes a dict generated by dump() and reconfigures the target to match.
        Returns list of non-fatal errors that were encountered.
        Will refuse to restore over an existing configuration unless clear_existing
            is True.
        '''
        if clear_existing:
            self.clear_existing(confirm=True)
        elif any(self.storage_objects) or any(self.targets):
            raise RTSLibError("storageobjects or targets present, not restoring")

        errors = []

        if abort_on_error:
            def err_func(err_str):
                raise RTSLibError(err_str)
        else:
            def err_func(err_str):
                errors.append(err_str + ", skipped")

        for index, so in enumerate(config.get('storage_objects', [])):
            if 'name' not in so:
                err_func("'name' not defined in storage object %d" % index)
                continue
            try:
                so_cls = so_mapping[so['plugin']]
            except KeyError:
                err_func("'plugin' not defined or invalid in storageobject %s" % so['name'])
                continue
            kwargs = so.copy()
            dict_remove(kwargs, ('exists', 'attributes', 'plugin', 'buffered_mode'))
            try:
                so_obj = so_cls(**kwargs)
            except Exception as e:
                err_func("Could not create StorageObject %s: %s" % (so['name'], e))
                continue

            # Custom err func to include block name
            def so_err_func(x):
                return err_func("Storage Object %s/%s: %s" % (so['plugin'], so['name'], x))

            set_attributes(so_obj, so.get('attributes', {}), so_err_func)

        # Don't need to create fabric modules
        for index, fm in enumerate(config.get('fabric_modules', [])):
            if 'name' not in fm:
                err_func("'name' not defined in fabricmodule %d" % index)
                continue
            for fm_obj in self.fabric_modules:
                if fm['name'] == fm_obj.name:
                    fm_obj.setup(fm, err_func)
                    break

        for index, t in enumerate(config.get('targets', [])):
            if 'wwn' not in t:
                err_func("'wwn' not defined in target %d" % index)
                continue
            if 'fabric' not in t:
                err_func("target %s missing 'fabric' field" % t['wwn'])
                continue
            if t['fabric'] not in (f.name for f in self.fabric_modules):
                err_func("Unknown fabric '%s'" % t['fabric'])
                continue

            fm_obj = FabricModule(t['fabric'])

            # Instantiate target
            Target.setup(fm_obj, t, err_func)

        return errors