Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
 def exists(self):
     """
     Check if the container exists.
     """
     return vz.exists(self.ctid)
Example #5
0
 def exists(self):
     return vz.exists(self.ctid)
Example #6
0
 def exists(self):
     """
     Check if the container exists.
     """
     return vz.exists(self.ctid)