~justin-fathomdb/nova/virtualbox-support

« back to all changes in this revision

Viewing changes to nova/compute/disk.py

  • Committer: Justin Santa Barbara
  • Date: 2010-08-21 14:03:21 UTC
  • mfrom: (158.1.4 raw-disk-images)
  • Revision ID: justin@fathomdb.com-20100821140321-5u10rh0y5ommfygv
Merged with latest lp:~justin-fathomdb/nova/raw-disk-images (though I'm fighting a mini merge-battle with myself because the code actually depends on the twisted removal)

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
    execute('dd if=%s of=%s bs=%d seek=%d conv=notrunc,fsync'
83
83
                  % (infile, outfile, sector_size, primary_first))
84
84
 
85
 
def inject_data(image, key=None, net=None, dns=None, remove_network_udev=False, partition=None, execute=None):
 
85
 
 
86
@defer.inlineCallbacks
 
87
def inject_data(    image, key=None, net=None, dns=None, 
 
88
                    remove_network_udev=False, 
 
89
                    partition=None, execute=None):
86
90
    """Injects a ssh key and optionally net data into a disk image.
87
91
 
88
92
    it will mount the image as a fully partitioned disk and attempt to inject
106
110
        else:
107
111
            mapped_device = device
108
112
 
 
113
        # We can only loopback mount raw images.  If the device isn't there,
 
114
        #  it's normally because it's a .vmdk or a .vdi etc
109
115
        if not os.path.exists(mapped_device):
110
 
            raise exception.Error('Mapped device was not found: %s' % mapped_device)
 
116
            raise exception.Error(
 
117
                'Mapped device was not found (we can only inject raw disk images): %s'
 
118
                % mapped_device)
111
119
 
112
120
        # Configure ext2fs so that it doesn't auto-check every N boots
113
121
        out, err = execute('sudo tune2fs -c 0 -i 0 %s' % mapped_device)
162
170
    execute('sudo tee %s' % dnsfile, dns)
163
171
 
164
172
def _remove_network_udev(fs, execute=None):
165
 
    # This is correct for Ubuntu, but might not be right for other distros
 
173
    # TODO(justinsb): This is correct for Ubuntu, but might not be right for
 
174
    #  other distros.  There is a much bigger discussion to be had about what
 
175
    #  we inject and how we inject it.
166
176
    rulesfile = os.path.join(fs, 'etc', 'udev', 'rules.d', '70-persistent-net.rules')
167
177
    execute('rm -f %s' % rulesfile)
168
178