예제 #1
0
class LustreClientMount(DeletableStatefulObject):
    host = models.ForeignKey('ManagedHost', help_text = "Mount host", related_name="client_mounts")
    filesystem = models.ForeignKey('ManagedFilesystem', help_text = "Mounted filesystem")
    mountpoint = models.CharField(max_length = CHARFIELD_MAX_LENGTH,
                                  help_text = "Filesystem mountpoint on host",
                                  null = True,
                                  blank = True)

    states = ['unmounted', 'mounted', 'removed']
    initial_state = 'unmounted'

    def __str__(self):
        return self.get_label()

    @property
    def active(self):
        return self.state == 'mounted'

    def get_label(self):
        return "%s:%s (%s)" % (self.host, self.mountpoint, self.state)

    def get_deps(self, state = None):
        if not state:
            state = self.state

        deps = []
        if state == 'mounted':
            # Depend on this mount's host having LNet up. If LNet is stopped
            # on the host, this filesystem will be unmounted first.
            deps.append(DependOn(self.host.lnet_configuration, 'lnet_up', fix_state='unmounted'))

        if state != 'removed':
            # Depend on the fs being available.
            deps.append(DependOn(self.filesystem, 'available',
                                 fix_state='unmounted'))

            # But if either the host or the filesystem are removed, the
            # mount should follow.
            deps.append(DependOn(self.host, 'lnet_up', acceptable_states = list(set(self.host.states) - set(['removed', 'forgotten'])), fix_state = 'removed'))
            deps.append(DependOn(self.filesystem, 'available', acceptable_states = list(set(self.filesystem.states) - set(['removed', 'forgotten'])), fix_state = 'removed'))

        return DependAll(deps)

    reverse_deps = {
        'ManagedHost': lambda mh: ObjectCache.host_client_mounts(mh.id),
        'LNetConfiguration': lambda lc: ObjectCache.host_client_mounts(lc.host.id),
        'ManagedFilesystem': lambda mf: ObjectCache.filesystem_client_mounts(mf.id)
    }

    class Meta:
        app_label = 'chroma_core'
        unique_together = ('host', 'filesystem')
예제 #2
0
class LustreClientMount(DeletableStatefulObject):
    host = models.ForeignKey("ManagedHost",
                             help_text="Mount host",
                             related_name="client_mounts",
                             on_delete=CASCADE)
    filesystem = models.CharField(
        max_length=8,
        help_text="Mounted filesystem",
        null=False,
        blank=False,
    )
    mountpoints = ArrayField(models.TextField(),
                             default=list,
                             help_text="Filesystem mountpoints on host")

    states = ["unmounted", "mounted", "removed"]
    initial_state = "unmounted"

    def __str__(self):
        return self.get_label()

    @property
    def active(self):
        return self.state == "mounted"

    def get_label(self):
        return "%s:%s (%s)" % (self.host, self.mountpoints, self.state)

    def get_deps(self, state=None):
        if not state:
            state = self.state

        deps = []
        if state == "mounted":
            # Depend on this mount's host having LNet up. If LNet is stopped
            # on the host, this filesystem will be unmounted first.
            deps.append(
                DependOn(self.host.lnet_configuration,
                         "lnet_up",
                         fix_state="unmounted"))

        if state != "removed":
            try:
                fs = ObjectCache.get_one(ManagedFilesystem,
                                         lambda mf: mf.name == self.filesystem)

                # Depend on the fs being available.
                deps.append(DependOn(fs, "available", fix_state="unmounted"))

                # If the filesystem is removed, the
                # mount should follow.
                deps.append(
                    DependOn(
                        fs,
                        "available",
                        acceptable_states=list(
                            set(fs.states) - set(["removed", "forgotten"])),
                        fix_state="removed",
                    ))
            except ManagedFilesystem.DoesNotExist:
                pass

            # If the host is removed, the
            # mount should follow.
            deps.append(
                DependOn(
                    self.host,
                    "lnet_up",
                    acceptable_states=list(
                        set(self.host.states) - set(["removed", "forgotten"])),
                    fix_state="removed",
                ))

        return DependAll(deps)

    reverse_deps = {
        "ManagedHost":
        lambda mh: ObjectCache.host_client_mounts(mh.id),
        "LNetConfiguration":
        lambda lc: ObjectCache.host_client_mounts(lc.host.id),
        "ManagedFilesystem":
        lambda mf: ObjectCache.filesystem_client_mounts(mf.name),
    }

    class Meta:
        app_label = "chroma_core"
        unique_together = ("host", "filesystem")