Exemple #1
0
 def mkvm_oneiric(self, conn):
     hw = '4A:59:43:49:79:BF'
     ip = '192.168.122.10'
 
     vm = LXCDomain.construct(conn,
                              True,
                              'oneiric',
                              1024 * 1024,
                              2,
                              FileSystemDevice(
                                 '/mnt/lxc/ubuntu_oneiric/rootfs'),
                              ETHNetworkDevice(hw, "vnet7", ip=ip))
     yield vm
Exemple #2
0
 def mkvm_oneiric_br(self, conn):
     hw = '4A:59:43:49:79:C0'
     ip = '192.168.123.2'
 
     vm = LXCDomain.construct(conn,
                              True,
                              'oneiric-br',
                              1024 * 1024,
                              2,
                              FileSystemDevice(
                                 '/mnt/lxc/ubuntu_oneiric_br/rootfs'),
                              ETHBridgedDevice(hw, "vnet7", 'br0', ip=ip))
     yield vm
Exemple #3
0
    def start(self, fs_mpoint_folder="/tmp/vms"):
        """
        starts lxc based vm
        fs_mpoint_folder is a folder where your vms file system
        will be mounted in some folder. It should exist
        """
        self.started = False
        
        if  not os.path.exists(fs_mpoint_folder):
            shell_exec('mkdir -p "{0}"'.format(fs_mpoint_folder))
        
        mpoint = os.path.join(fs_mpoint_folder, str(uuid.uuid1()))

        shell_exec('mkdir -p "{0}"'.format(mpoint))
        self.fs.mount(mpoint)
        
        try:
            if self.use_libvirt:
                self.vm = LXCDomain.construct(self.conn,
                                          True,
                                          self.name,
                                          1024 * 1024,
                                          2,
                                          FileSystemDevice(mpoint),
                                          ETHNetworkDevice(self.hwaddr,
                                                           "vnet7",
                                                           ip=self.ip))
            else:
                shell_exec('lxc-start -d -n "{0}"'.format(self.lxc_name))
        
        except:
            self.stop()
            raise
     
        logger.info("Domain started ok with ip {0!r} wait ssh ready".format(self.ip))
        
        for i in range(100):
            if is_ssh_ready(self.ip):
                self.started = True
                return self
        
        logger.critical("ssh failed to start on ip {0!r}".format(self.ip))
        self.stop()
        raise Exception("VM refuses to start")