Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Implement MountSnapshotJob / UnmountSnapshotJob (#2156)
Browse files Browse the repository at this point in the history
* First try on MountSnapshotJob

Signed-off-by: Michael Pankov <work@michaelpankov.com>

* Add a migration

Signed-off-by: Michael Pankov <work@michaelpankov.com>

* Renumber the migration

Signed-off-by: Michael Pankov <work@michaelpankov.com>

* Address CodeFactor

Signed-off-by: Michael Pankov <work@michaelpankov.com>

* Use host.fqdn

Signed-off-by: Michael Pankov <work@michaelpankov.com>

* Format the migration

Signed-off-by: Michael Pankov <work@michaelpankov.com>

* Take care of review

Signed-off-by: Michael Pankov <work@michaelpankov.com>

* Implement UnmountSnapshotJob

Signed-off-by: Michael Pankov <work@michaelpankov.com>

* Redo the migration

Signed-off-by: Michael Pankov <work@michaelpankov.com>

* Add dependencies

Signed-off-by: Michael Pankov <work@michaelpankov.com>

* Add snapshot Create/Destroy jobs (#2159)

Signed-off-by: Igor Pashev <pashev.igor@gmail.com>

Co-authored-by: Igor Pashev <pashev.igor@gmail.com>
  • Loading branch information
mkpankov and ip1981 authored Aug 18, 2020
1 parent ca5f9e1 commit 5b4c1d2
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 0 deletions.
58 changes: 58 additions & 0 deletions chroma_core/migrations/0024_mountsnapshotjob_unmountsnapshotjob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.23 on 2020-08-14 09:30
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("chroma_core", "0023_remove_stratagem_client_job"),
]

operations = [
migrations.CreateModel(
name="MountSnapshotJob",
fields=[
(
"job_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="chroma_core.Job",
),
),
("fqdn", models.CharField(max_length=256)),
("fsname", models.CharField(max_length=8)),
("name", models.CharField(max_length=512)),
],
options={"ordering": ["id"],},
bases=("chroma_core.job",),
),
migrations.CreateModel(
name="UnmountSnapshotJob",
fields=[
(
"job_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="chroma_core.Job",
),
),
("fqdn", models.CharField(max_length=256)),
("fsname", models.CharField(max_length=8)),
("name", models.CharField(max_length=512)),
],
options={"ordering": ["id"],},
bases=("chroma_core.job",),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.27 on 2020-08-13 18:55
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("chroma_core", "0024_mountsnapshotjob_unmountsnapshotjob"),
]

operations = [
migrations.CreateModel(
name="CreateSnapshotJob",
fields=[
(
"job_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="chroma_core.Job",
),
),
("fqdn", models.CharField(help_text=b"MGS host to create the snapshot on", max_length=256)),
("fsname", models.CharField(help_text=b"Lustre filesystem name", max_length=8)),
("name", models.CharField(help_text=b"Snapshot name", max_length=64)),
(
"comment",
models.CharField(help_text=b"Optional comment for the snapshot", max_length=1024, null=True),
),
],
options={"ordering": ["id"],},
bases=("chroma_core.job",),
),
migrations.CreateModel(
name="DestroySnapshotJob",
fields=[
(
"job_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="chroma_core.Job",
),
),
("fqdn", models.CharField(help_text=b"MGS host to destroy the snapshot on", max_length=256)),
("fsname", models.CharField(help_text=b"Lustre filesystem name", max_length=8)),
("name", models.CharField(help_text=b"Snapshot name", max_length=64)),
("force", models.BooleanField(default=False, help_text=b"Destroy the snapshot with force")),
],
options={"ordering": ["id"],},
bases=("chroma_core.job",),
),
]
115 changes: 115 additions & 0 deletions chroma_core/models/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,37 @@ class NoNidsPresent(Exception):
pass


class CreateSnapshotJob(Job):
fqdn = models.CharField(max_length=256, help_text="MGS host to create the snapshot on")
fsname = models.CharField(max_length=8, help_text="Lustre filesystem name")
name = models.CharField(max_length=64, help_text="Snapshot to create")
comment = models.CharField(max_length=1024, null=True, help_text="Optional comment for the snapshot")

@classmethod
def long_description(cls, stateful_object):
return help_text["create_snapshot"]

def description(self):
return "Create snapshot '{}' of '{}'".format(self.name, self.fsname)

def get_steps(self):
args = {"host": self.fqdn, "fsname": self.fsname, "name": self.name}
if self.comment:
args["comment"] = self.comment

return [(CreateSnapshotStep, args)]

def get_deps(self):
# To prevent circular imports
from chroma_core.models.filesystem import ManagedFilesystem

return DependOn(ManagedFilesystem.objects.get(name=self.fsname), "available")

class Meta:
app_label = "chroma_core"
ordering = ["id"]


class CreateSnapshotStep(Step):
def run(self, kwargs):
args = {"fsname": kwargs["fsname"], "name": kwargs["name"]}
Expand All @@ -1795,6 +1826,34 @@ def run(self, kwargs):
)


class DestroySnapshotJob(Job):
fqdn = models.CharField(max_length=256, help_text="MGS host to destroy the snapshot on")
fsname = models.CharField(max_length=8, help_text="Lustre filesystem name")
name = models.CharField(max_length=64, help_text="Snapshot to destroy")
force = models.BooleanField(default=False, help_text="Destroy the snapshot with force")

@classmethod
def long_description(cls, stateful_object):
return help_text["destroy_snapshot"]

def description(self):
return "Destroy snapshot '{}' of '{}'".format(self.name, self.fsname)

def get_steps(self):
args = {"host": self.fqdn, "fsname": self.fsname, "name": self.name, "force": self.force}
return [(DestroySnapshotStep, args)]

def get_deps(self):
# To prevent circular imports
from chroma_core.models.filesystem import ManagedFilesystem

return DependOn(ManagedFilesystem.objects.get(name=self.fsname), "available")

class Meta:
app_label = "chroma_core"
ordering = ["id"]


class DestroySnapshotStep(Step):
def run(self, kwargs):
self.invoke_rust_agent_expect_result(
Expand All @@ -1816,3 +1875,59 @@ def run(self, kwargs):
self.invoke_rust_agent_expect_result(
kwargs["host"], "snapshot_unmount", {"fsname": kwargs["fsname"], "name": kwargs["name"]}
)


class MountSnapshotJob(Job):
fqdn = models.CharField(max_length=256)
fsname = models.CharField(max_length=8)
name = models.CharField(max_length=512)

@classmethod
def long_description(cls, stateful_object):
return help_text["mount_snapshot"]

def description(self):
return "Mount snapshot on host %s" % self.fqdn

def get_deps(self):
# To prevent circular imports
from chroma_core.models.filesystem import ManagedFilesystem

return DependOn(ManagedFilesystem.objects.get(name=self.fsname), "available")

def get_steps(self):
steps = [(MountSnapshotStep, {"host": self.fqdn, "fsname": self.fsname, "name": self.name})]

return steps

class Meta:
app_label = "chroma_core"
ordering = ["id"]


class UnmountSnapshotJob(Job):
fqdn = models.CharField(max_length=256)
fsname = models.CharField(max_length=8)
name = models.CharField(max_length=512)

@classmethod
def long_description(cls, stateful_object):
return help_text["unmount_snapshot"]

def description(self):
return "Unmount snapshot on host %s" % self.fqdn

def get_deps(self):
# To prevent circular imports
from chroma_core.models.filesystem import ManagedFilesystem

return DependOn(ManagedFilesystem.objects.get(name=self.fsname), "available")

def get_steps(self):
steps = [(UnmountSnapshotStep, {"host": self.fqdn, "fsname": self.fsname, "name": self.name})]

return steps

class Meta:
app_label = "chroma_core"
ordering = ["id"]
4 changes: 4 additions & 0 deletions chroma_help/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,8 @@
"revoke_ticket": "Revoking Ticket",
"forget_ticket": "Forgetting Ticket",
"create_task": "Creating Task",
"mount_snapshot": "Mounting Snapshot",
"unmount_snapshot": "Unmounting Snapshot",
"create_snapshot": "Create snapshot with the given name",
"destroy_snapshot": "Destroy existing snapshot",
}

0 comments on commit 5b4c1d2

Please sign in to comment.