summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2012-11-13 10:56:12 +0000
committerDaniel P. Berrange <berrange@redhat.com>2012-11-15 12:31:50 +0000
commit053bca72255bde37a4f7384b35ecedb85cff35d7 (patch)
treeaf38212c1a1cb29d52ca1319cb101c528c45e8bc
parente85156e20b664ccf9e6d0ac7e1006a80555f8922 (diff)
downloadnova-053bca72255bde37a4f7384b35ecedb85cff35d7.tar.gz
nova-053bca72255bde37a4f7384b35ecedb85cff35d7.tar.xz
nova-053bca72255bde37a4f7384b35ecedb85cff35d7.zip
Introduce a VFS api abstraction for manipulating disk images
Currently the file injection code has the assumumption that the guest disk image can be mounted on the host filesystem, which limits the techniques which can be used. Introducing a VFS API abstraction allows the file injection code to be de-coupled from the host filesystem. blueprint: virt-disk-api-refactoring Change-Id: I107c018586fd9b6fc2c7d497b7a437ac24f11944 Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
-rw-r--r--nova/virt/disk/vfs/__init__.py19
-rw-r--r--nova/virt/disk/vfs/api.py107
2 files changed, 126 insertions, 0 deletions
diff --git a/nova/virt/disk/vfs/__init__.py b/nova/virt/disk/vfs/__init__.py
new file mode 100644
index 000000000..880979c48
--- /dev/null
+++ b/nova/virt/disk/vfs/__init__.py
@@ -0,0 +1,19 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+"""
+Operations on virtual filesystems
+
+"""
diff --git a/nova/virt/disk/vfs/api.py b/nova/virt/disk/vfs/api.py
new file mode 100644
index 000000000..7d7768bb2
--- /dev/null
+++ b/nova/virt/disk/vfs/api.py
@@ -0,0 +1,107 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from nova.openstack.common import log as logging
+
+LOG = logging.getLogger(__name__)
+
+
+class VFS(object):
+
+ """
+ The VFS class defines an interface for manipulating files within
+ a virtual disk image filesystem. This allows file injection code
+ to avoid the assumption that the virtual disk image can be mounted
+ in the host filesystem.
+
+ All paths provided to the APIs in this class should be relative
+ to the root of the virtual disk image filesystem. Subclasses
+ will translate paths as required by their implementation.
+ """
+ def __init__(self, imgfile, imgfmt, partition):
+ self.imgfile = imgfile
+ self.imgfmt = imgfmt
+ self.partition = partition
+
+ """
+ Perform any one-time setup tasks to make the virtual
+ filesystem available to future API calls
+ """
+ def setup(self):
+ pass
+
+ """
+ Release all resources initialized in the setup method
+ """
+ def teardown(self):
+ pass
+
+ """
+ Create a directory @path, including all intermedia
+ path components if they do not already exist
+ """
+ def make_path(self, path):
+ pass
+
+ """
+ Append @content to the end of the file identified
+ by @path, creating the file if it does not already
+ exist
+ """
+ def append_file(self, path, content):
+ pass
+
+ """
+ Replace the entire contents of the file identified
+ by @path, wth @content, creating the file if it does
+ not already exist
+ """
+ def replace_file(self, path, content):
+ pass
+
+ """
+ Return the entire contents of the file identified
+ by @path
+ """
+ def read_file(self, path):
+ pass
+
+ """
+ Return a True if the file identified by @path
+ exists
+ """
+ def has_file(self, path):
+ pass
+
+ """
+ Set the permissions on the file identified by
+ @path to @mode. The file must exist prior to
+ this call.
+ """
+ def set_permissions(self, path, mode):
+ pass
+
+ """
+ Set the ownership on the file identified by
+ @path to the username @user and groupname @group.
+ Either of @user or @group may be None, in which case
+ the current ownership will be left unchanged. The
+ ownership must be passed in string form, allowing
+ subclasses to translate to uid/gid form as required.
+ The file must exist prior to this call.
+ """
+ def set_ownership(self, path, user, group):
+ pass