add instance filter
diff --git a/.gitignore b/.gitignore
index 73d1eaf..32e35b0 100755
--- a/.gitignore
+++ b/.gitignore
@@ -59,4 +59,13 @@
# Files created by releasenotes build
releasenotes/build
-.idea/
\ No newline at end of file
+.idea/
+
+# sqlite file
+*.sqlite
+
+# log
+*.log
+
+# envvar openrc file
+*openrc.sh
\ No newline at end of file
diff --git a/etc/staffeln/staffeln.conf b/etc/staffeln/staffeln.conf
index 5a735b2..5b8210c 100644
--- a/etc/staffeln/staffeln.conf
+++ b/etc/staffeln/staffeln.conf
@@ -4,7 +4,7 @@
[database]
backend = sqlalchemy
-connection = "mysql://root:password@localhost:3306/staffeln"
+connection = "mysql+pymysql://root:password@localhost:3306/staffeln"
mysql_engine = InnoDB
# mysql_sql_mode = TRADITIONAL
# idle_timeout = 3600
diff --git a/requirements.txt b/requirements.txt
index b8a1585..45ae2d5 100755
--- a/requirements.txt
+++ b/requirements.txt
@@ -13,5 +13,5 @@
openstacksdk>0.28.0
pymysql
-email
-smtplib
\ No newline at end of file
+# email
+# smtplib
\ No newline at end of file
diff --git a/staffeln/common/constants.py b/staffeln/common/constants.py
index 5818dcd..d537d48 100644
--- a/staffeln/common/constants.py
+++ b/staffeln/common/constants.py
@@ -1,3 +1,5 @@
BACKUP_COMPLETED=2
BACKUP_WIP=1
BACKUP_PLANNED=0
+
+BACKUP_ENABLED_KEY = 'true'
\ No newline at end of file
diff --git a/staffeln/conductor/backup.py b/staffeln/conductor/backup.py
index 53ca1e0..a37235b 100755
--- a/staffeln/conductor/backup.py
+++ b/staffeln/conductor/backup.py
@@ -60,6 +60,14 @@
for queue in queue_list:
self._volume_queue(queue)
+ # Backup the volumes attached to which has a specific metadata
+ def filter_server(self, metadata):
+
+ if not CONF.conductor.backup_metadata_key in metadata:
+ return False
+
+ return metadata[CONF.conductor.backup_metadata_key].lower() == constants.BACKUP_ENABLED_KEY
+
def check_instance_volumes(self):
"""Get the list of all the volumes from the project using openstacksdk
Function first list all the servers in the project and get the volumes
@@ -72,7 +80,8 @@
details=True, all_projects=True, project_id=project.id
)
for server in servers:
- server_id = server.host_id
+ if not self.filter_server(server.metadata): continue
+ server_id = server.id
volumes = server.attached_volumes
for volume in volumes:
queues_map.append(
@@ -112,16 +121,16 @@
volume_backup = conn.block_storage.create_backup(
volume_id=queue.volume_id, force=True
)
- update_queue = objects.Queue.get_by_id(self.ctx, queue.id)
- update_queue.backup_id = volume_backup.id
- update_queue.backup_status = constants.BACKUP_WIP
- update_queue.save()
+
+ queue.backup_id = volume_backup.id
+ queue.backup_status = constants.BACKUP_WIP
+ queue.save()
else:
pass
# TODO(Alex): remove this task from the task list
- # Backup planned task cannot have backup_id in the same cycle
- # Reserve for now because it is related to the WIP backup genenrators which
- # are not finished in the current cycle
+ # Backup planned task cannot have backup_id in the same cycle
+ # Reserve for now because it is related to the WIP backup genenrators which
+ # are not finished in the current cycle
def process_failed_task(self, task):
LOG.error("Backup of the volume %s failed." % task.id)
diff --git a/staffeln/conductor/manager.py b/staffeln/conductor/manager.py
index be3b433..fc00d6b 100755
--- a/staffeln/conductor/manager.py
+++ b/staffeln/conductor/manager.py
@@ -9,6 +9,7 @@
from staffeln.common import constants
from staffeln.conductor import backup
from staffeln.common import context
+from staffeln.i18n import _
LOG = log.getLogger(__name__)
CONF = staffeln.conf.CONF
@@ -62,15 +63,20 @@
LOG.info("backing... %s" % str(time.time()))
LOG.info("%s periodics" % self.name)
+ # TODO(Alex): need to escalate discussion
+ # how to manage last backups not finished yet
if len(self.get_all_tasks()) == 0:
backup.Backup().create_queue()
- # TODO(Alex): reschedule the backup engine immediately
+ else:
+ LOG.info(_("The last backup cycle is not finished yet."
+ "So the new backup cycle is skipped."))
queues_started = self.get_wip_tasks()
if len(queues_started) != 0:
for queue in queues_started: backup.Backup().check_volume_backup_status(queue)
queues_to_start = self.get_todo_tasks()
+ print(queues_to_start)
if len(queues_to_start) != 0:
for queue in queues_to_start:
backup.Backup().volume_backup_initiate(queue)
diff --git a/staffeln/conf/conductor.py b/staffeln/conf/conductor.py
index 9906004..a4ea907 100755
--- a/staffeln/conf/conductor.py
+++ b/staffeln/conf/conductor.py
@@ -23,7 +23,7 @@
),
cfg.StrOpt(
"backup_metadata_key",
- default="test",
+ default="__automated_backup",
help=_("The key string of metadata the VM, which requres back up, has"),
),
]
diff --git a/staffeln/conf/notify.py b/staffeln/conf/notify.py
index 20f1ede..42daefe 100644
--- a/staffeln/conf/notify.py
+++ b/staffeln/conf/notify.py
@@ -11,7 +11,7 @@
email_opts = [
cfg.StrOpt(
"template",
- default="<h3>${CONTENT}</h3>",
+ default="<h3>\${CONTENT}</h3>",
help=_("This html template is used to email the backup result."),
),
cfg.ListOpt(