def container(name, ostemplate, **kwargs): """ Require an OpenVZ container """ if not openvz.exists(name): ctid = openvz.get_available_ctid() openvz.create(ctid, ostemplate=ostemplate, **kwargs) openvz.set(ctid, name=name) return Container(name)
def create(self, **kwargs): """ Create the container. Extra args are passed to :py:func:`fabtools.openvz.create`. """ return vz.create(self.ctid, **kwargs)
def container(name, ostemplate, **kwargs): """ Require an OpenVZ container. If it does not exist, the container will be created using the specified OS template (see :py:func:`fabtools.require.openvz.template()`). Extra args will be passed to :py:func:`fabtools.openvz.create()`:: from fabtools import require require.openvz.container('foo', 'debian', ipadd='1.2.3.4') This function returns a :py:class:`fabtools.openvz.Container` object, that can be used to perform further operations:: from fabtools.require.openvz import container ct = container('foo', 'debian') ct.set('ipadd', '1.2.3.4') ct.start() ct.exec2('hostname') This function can also be used as a context manager:: from fabtools.require.openvz import container with container('foo', 'debian') as ct: ct.set('ipadd', '1.2.3.4') ct.start() ct.exec2('hostname') """ if not openvz.exists(name): ctid = openvz.get_available_ctid() openvz.create(ctid, ostemplate=ostemplate, **kwargs) openvz.set(ctid, name=name) return Container(name)
def create(self, **kwargs): return vz.create(self.ctid, **kwargs)