12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace KeaBundle\Command;
- use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Output\OutputInterface;
- class KeaConfigCommand extends ContainerAwareCommand
- {
- protected function configure()
- {
- $this
- ->setName('kea:config')
- ->setDescription('Kea DHCP Config')
- ->setHelp('Create Kea DHCP Config')
- ->addOption('class', null, InputOption::VALUE_OPTIONAL, 'Kea Class Config in KeaBundle\Services. e.g. BaseKea', 'BaseKea')
- ->addOption('id', null, InputOption::VALUE_OPTIONAL, 'DHCP Entity ID. e.g.: 1', 1)
- ->addOption('library', null, InputOption::VALUE_OPTIONAL, 'Hook library path', '/kea-cm-hook/kea-hook-flowdat.so')
- ->addOption('set', null, InputOption::VALUE_NONE, 'Send Config DHCP4 to KEA')
- ;
- }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- */
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $this->output = $output;
- $class = $input->getOption('class');
- $id = $input->getOption('id');
- $library = $input->getOption('library');
- $keaConfigService = $this->getContainer()->get('kea.config');
- $setConfig = (int) $input->getOption('set');
- if ($setConfig) {
- $dhcpRepository = $this->getContainer()->get("doctrine.orm.entity_manager")->getRepository("DHCPBundle\Entity\DHCP");
- $dhcp = $dhcpRepository->findOneById($id);
- // selecciono el primer KEA DHCP que se encuentre
- if (!$dhcp) {
- $dhcpAll = $dhcpRepository->findAll();
- $dhcp = count($dhcpAll) ? current($dhcpAll) : null;
- }
- if ($dhcp) {
- $config = $keaConfigService->getConfig($id, $class, $library);
- $output->writeln($keaConfigService->setConfig($dhcp, $config));
- } else {
- $output->writeln("KEA DHCP id:{$id} <error>not found!</error>");
- }
- } else {
- $output->writeln($keaConfigService->getConfig($id, $class, $library));
- }
- }
- }
|