1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 Red Hat, Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
from nova.openstack.common import log as logging
19
LOG = logging.getLogger(__name__)
25
The VFS class defines an interface for manipulating files within
26
a virtual disk image filesystem. This allows file injection code
27
to avoid the assumption that the virtual disk image can be mounted
28
in the host filesystem.
30
All paths provided to the APIs in this class should be relative
31
to the root of the virtual disk image filesystem. Subclasses
32
will translate paths as required by their implementation.
34
def __init__(self, imgfile, imgfmt, partition):
35
self.imgfile = imgfile
37
self.partition = partition
40
Perform any one-time setup tasks to make the virtual
41
filesystem available to future API calls
47
Release all resources initialized in the setup method
53
Create a directory @path, including all intermedia
54
path components if they do not already exist
56
def make_path(self, path):
60
Append @content to the end of the file identified
61
by @path, creating the file if it does not already
64
def append_file(self, path, content):
68
Replace the entire contents of the file identified
69
by @path, wth @content, creating the file if it does
72
def replace_file(self, path, content):
76
Return the entire contents of the file identified
79
def read_file(self, path):
83
Return a True if the file identified by @path
86
def has_file(self, path):
90
Set the permissions on the file identified by
91
@path to @mode. The file must exist prior to
94
def set_permissions(self, path, mode):
98
Set the ownership on the file identified by
99
@path to the username @user and groupname @group.
100
Either of @user or @group may be None, in which case
101
the current ownership will be left unchanged. The
102
ownership must be passed in string form, allowing
103
subclasses to translate to uid/gid form as required.
104
The file must exist prior to this call.
106
def set_ownership(self, path, user, group):