public function getParentContainer(Container $container)
 {
     if (null !== $container->getParentId()) {
         return $this->parentContainer;
     }
     return $container;
 }
 public function __construct(Container $container, Container $parent = null)
 {
     $cmd = 'lxc-info -s -n ' . $container->getName();
     if (!empty($parent)) {
         $cmd = 'lxc-attach -n ' . $parent->getName() . ' -- ' . $cmd;
     }
     parent::__construct($cmd);
 }
Beispiel #3
0
    protected function createDummyProject()
    {
        $container = new Container();
        $container->setName('test')->setFriendlyName('Test')->setHostname('cluster.test.localdev')->setDomain('test.localdev')->setDnsZoneSerial('2015070501')->setLxcUtsName('test')->setLxcHwAddr('00:16:3e:e0:5c:c3')->setLxcRootFs('/var/lib/lxc/test/rootfs')->setNetworkAddress('10.100.1.0')->setIPAddress('10.100.1.1')->setDnsZoneTtl(604800)->setDnsZonePriMasterNs('ns.rainmaker.localdev')->setDnsZoneAdminEmail('hostmaster.rainmaker.localdev')->setDnsZoneRefresh(604800)->setDnsZoneRetry(86400)->setDnsZoneExpire(2419200)->setDnsZoneNegCacheTtl(604800)->setState(Container::STATE_RUNNING)->setProfileName('rainmaker/default-project');
        $json = '
{
  "mounts": [
    {
      "source": "/var/cache/lxc/rainmaker",
      "target": "{{container_rootfs}}/var/cache/lxc/rainmaker",
      "group": "bind"
    },
    {
      "source": "/srv/saltstack",
      "target": "{{container_rootfs}}/srv/saltstack",
      "group": "bind"
    }
  ],
  "exports": []
}
';
        $container->setProfileMetadata($json);
        return $container;
    }
 public function __construct(Container $project)
 {
     $cmd = 'lxc-destroy --name ' . escapeshellarg($project->getName());
     parent::__construct($cmd);
 }
    protected function createDummyProjectBranches()
    {
        $json = '
{
  "mounts": [
    {
      "source": "{{container_rootfs}}/var/www/html",
      "target": "/export/rainmaker/{{container_name}}",
      "group": "nfs"
    },
    {
      "source": "/srv/saltstack",
      "target": "{{container_rootfs}}/srv/saltstack",
      "group": "bind"
    }
  ],
  "exports": [
    {
      "source": "/export/rainmaker/{{container_name}}"
    }
  ]
}
';
        $containers = array();
        $container = new Container();
        $container->setName('test.prod')->setFriendlyName('Test [Prod]')->setHostname('test.localdev')->setDomain('test.localdev')->setDnsZoneSerial('2015070501')->setLxcUtsName('test.prod')->setLxcHwAddr('00:16:3e:e0:5c:c4')->setLxcRootFs('/var/lib/lxc/test.prod/rootfs')->setNetworkAddress('10.100.1.0')->setIPAddress('10.100.1.2')->setDnsZoneTtl(604800)->setDnsZonePriMasterNs('ns.rainmaker.localdev')->setDnsZoneAdminEmail('hostmaster.rainmaker.localdev')->setDnsZoneRefresh(604800)->setDnsZoneRetry(86400)->setDnsZoneExpire(2419200)->setDnsZoneNegCacheTtl(604800)->setState(Container::STATE_RUNNING)->setProfileName('rainmaker/default-branch')->setProfileMetadata($json)->setParentId(1);
        $containers[] = $container;
        $container = new Container();
        $container->setName('test.dev')->setFriendlyName('Test [Dev]')->setHostname('develop.test.localdev')->setDomain('test.localdev')->setDnsZoneSerial('2015070501')->setLxcUtsName('test.dev')->setLxcHwAddr('00:16:3e:e0:5c:c5')->setLxcRootFs('/var/lib/lxc/test.dev/rootfs')->setNetworkAddress('10.100.1.0')->setIPAddress('10.100.1.3')->setDnsZoneTtl(604800)->setDnsZonePriMasterNs('ns.rainmaker.localdev')->setDnsZoneAdminEmail('hostmaster.rainmaker.localdev')->setDnsZoneRefresh(604800)->setDnsZoneRetry(86400)->setDnsZoneExpire(2419200)->setDnsZoneNegCacheTtl(604800)->setState(Container::STATE_STOPPED)->setProfileName('rainmaker/default-branch')->setProfileMetadata($json)->setParentId(1);
        $containers[] = $container;
        return $containers;
    }
    protected function createDummyProjectBranchClone()
    {
        $container = new Container();
        $container->setName('test.dev')->setFriendlyName('Test [Dev]')->setHostname('develop.test.localdev')->setDomain('test.localdev')->setDnsZoneSerial('2015070501')->setParentId(1);
        $json = '
{
  "mounts": [
    {
      "source": "{{container_rootfs}}/var/www/html",
      "target": "/export/rainmaker/{{container_name}}",
      "group": "nfs"
    },
    {
      "source": "/srv/saltstack",
      "target": "{{container_rootfs}}/srv/saltstack",
      "group": "bind"
    }
  ],
  "exports": [
    {
      "source": "/export/rainmaker/{{container_name}}"
    }
  ]
}
';
        $container->setProfileMetadata($json);
        return $container;
    }
 public function __construct(Container $container)
 {
     $cmd = 'lxc-create --name ' . escapeshellarg($container->getName()) . ' --bdev btrfs --template rainmaker-project' . ' -- --profile ' . escapeshellarg($container->getProfileName()) . ' --version ' . escapeshellarg($container->getProfileVersion());
     parent::__construct($cmd);
 }
    protected function createDummyProjectBranch()
    {
        $container = new Container();
        $container->setName('test.prod')->setFriendlyName('Test [Prod]')->setHostname('test.localdev')->setDomain('test.localdev')->setDnsZoneSerial('2015070501')->setState(Container::STATE_PENDING_PROVISIONING)->setProfileName('rainmaker/default-branch')->setParentId(1);
        $json = '
{
  "mounts": [
    {
      "source": "{{container_rootfs}}/var/www/html",
      "target": "/export/rainmaker/{{container_name}}",
      "group": "nfs"
    },
    {
      "source": "/srv/saltstack",
      "target": "{{container_rootfs}}/srv/saltstack",
      "group": "bind"
    }
  ],
  "exports": [
    {
      "source": "/export/rainmaker/{{container_name}}"
    }
  ]
}
';
        $container->setProfileMetadata($json);
        return $container;
    }
 /**
  * Returns the (parent) project container for the given container. If the container is a project
  * branch container then its project container will be returned. If the container is a project
  * container then it will be returned.
  *
  * @param Container $container
  * @return Container
  */
 public function getParentContainer(Container $container)
 {
     if (null !== ($id = $container->getParentId())) {
         return $this->findOneById($id);
     }
     return $container;
 }
 /**
  * Stops a Rainmaker project Linux container.
  *
  * @param Container $container
  */
 public function stopProjectContainer(Container $container)
 {
     try {
         $process = new GetContainerStatusProcess($container);
         if (stristr($this->getProcessRunner()->run($process), 'running') === FALSE) {
             return;
         }
     } catch (ProcessFailedException $e) {
         echo $e->getMessage();
     }
     try {
         $process = new StopProjectContainerProcess($container);
         $this->getProcessRunner()->run($process);
         $container->setState(Container::STATE_STOPPED);
         $this->getEntityManager()->getRepository('Rainmaker:Container')->saveContainer($container);
     } catch (ProcessFailedException $e) {
         echo $e->getMessage();
     }
 }
 public function __construct(Container $branch, Container $project)
 {
     parent::__construct('lxc-attach -n ' . $project->getName() . ' -- lxc-start -d -n ' . $branch->getName());
 }
 public function __construct(Container $newBranchContainer, Container $sourceBranchContainer, Container $project)
 {
     parent::__construct('lxc-attach -n ' . $project->getName() . ' -- lxc-clone -s -B btrfs ' . escapeshellarg($sourceBranchContainer->getName()) . ' ' . escapeshellarg($newBranchContainer->getName()));
 }
 public function __construct(Container $container)
 {
     parent::__construct('lxc-stop -n ' . $container->getName());
 }
 public function __construct(Container $branch, Container $project)
 {
     $cmd = 'lxc-attach -n ' . $project->getName() . ' -- lxc-destroy --name ' . escapeshellarg($branch->getName());
     parent::__construct($cmd);
 }
 public function __construct(Container $branch, Container $project)
 {
     $cmd = 'lxc-attach -n ' . $project->getName() . ' -- lxc-create --name ' . escapeshellarg($branch->getName()) . ' --bdev btrfs --template rainmaker-project-branch' . ' -- --profile ' . escapeshellarg($branch->getProfileName()) . ' --version ' . escapeshellarg($branch->getProfileVersion());
     parent::__construct($cmd);
 }