فهرست منبع

Merged in FD3-537 (pull request #14)

FD3-537 dhcp workflow

Approved-by: Maximiliano Schvindt <maximiliano@interlink.com.ar>
Guillermo Espinoza 7 سال پیش
والد
کامیت
6070afd9c3

+ 36 - 0
app/DoctrineMigrations/Version20180522132838.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace Application\Migrations;
+
+use MigrationsBundle\Migrations\MigrationsBase;
+use Doctrine\DBAL\Schema\Schema;
+
+/**
+ * Migration para cargar los archivos .yml del directorio app/DoctrineMigrations/src
+ */
+class Version20180522132838 extends MigrationsBase
+{
+    /**
+     * @param Schema $schema
+     */
+    public function up(Schema $schema)
+    {
+        // cargo todos los archivos que esten en src/
+        // deben tener extensión yml
+        $directory = __DIR__ . DIRECTORY_SEPARATOR . 'src';
+        $migrations = scandir($directory);
+        foreach ($migrations as $migration) {
+            $this->executeYaml($directory, $migration);
+            $this->showResult();
+        }
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function down(Schema $schema)
+    {
+        // this down() migration is auto-generated, please modify it to your needs
+
+    }
+}

+ 31 - 0
app/DoctrineMigrations/src/action.yml

@@ -0,0 +1,31 @@
+insertorupdate:
+    action:
+        -
+          id: 1
+          name: "Configuración KEA"
+          workflow_name: "dhcp_workflow"
+          event: "a:1:{i:0;s:5:\"enter\";}"
+          event_reference: "active"
+          template: "echo \"Config KEA\"\r\nphp /opt/dhcp/bin/console kea:config"
+          tenancy_id: 1
+        -
+          id: 2
+          name: "Config on Create/Update/Remove"
+          object_class: "IPv4Bundle\\Entity\\Host"
+          event: "a:3:{i:0;s:11:\"postPersist\";i:1;s:10:\"postUpdate\";i:2;s:9:\"preRemove\";}"
+          template: "echo \"{{object.mac}} Config on Create/Update/Remove (postPersist / PostUpdate / PreRemove)\"\r\nphp /opt/dhcp/bin/console workflow:apply --entity=IPv4Bundle\\\\Entity\\\\Host --id={{object.id}} --workflow=dhcp_workflow --transition=\"add_config\""
+          tenancy_id: 1
+        -
+          id: 3
+          name: "Config on Create/Update/Remove"
+          object_class: "IPv4Bundle\\Entity\\Pool"
+          event: "a:3:{i:0;s:11:\"postPersist\";i:1;s:10:\"postUpdate\";i:2;s:9:\"preRemove\";}"
+          template: "echo \"{{object.mac}} Config on Create/Update/Remove (postPersist / PostUpdate / PreRemove)\"\r\nphp /opt/dhcp/bin/console workflow:apply --entity=IPv4Bundle\\\\Entity\\\\Pool --id={{object.id}} --workflow=dhcp_workflow --transition=\"add_config\""
+          tenancy_id: 1
+        -
+          id: 4
+          name: "Config on Create/Update/Remove"
+          object_class: "IPv4Bundle\\Entity\\SubNet"
+          event: "a:3:{i:0;s:11:\"postPersist\";i:1;s:10:\"postUpdate\";i:2;s:9:\"preRemove\";}"
+          template: "echo \"{{object.mac}} Config on Create/Update/Remove (postPersist / PostUpdate / PreRemove)\"\r\nphp /opt/dhcp/bin/console workflow:apply --entity=IPv4Bundle\\\\Entity\\\\SubNet --id={{object.id}} --workflow=dhcp_workflow --transition=\"add_config\""
+          tenancy_id: 1

+ 16 - 0
app/DoctrineMigrations/src/workflow.yml

@@ -0,0 +1,16 @@
+insertorupdate:
+    workflow:
+        -
+          id: 1001
+          name: "dhcp_workflow"
+          type: "state_machine"
+          marking_type: "single_state"
+          marking_name: "currentState"
+          description: "dhcp_workflow"
+          template: "initial_place: active\r\nplaces:\r\n  - active\r\n  - disable\r\ntransitions:\r\n  add_config:\r\n    from: active\r\n    to: active\r\n  disable:\r\n    from: active\r\n    to: disable\r\n  active:\r\n    from: disable\r\n    to: active"
+          created: "2018-05-22 12:34:41"
+          updated: "2018-05-22 12:34:41"
+          tenancy_id: 1
+          enable: 1
+          support: "a:3:{i:0;s:22:\"IPv4Bundle\\Entity\\Host\";i:1;s:22:\"IPv4Bundle\\Entity\\Pool\";i:2;s:24:\"IPv4Bundle\\Entity\\SubNet\";}"
+          owner: "admin"

+ 26 - 0
app/Resources/workflows/workflow_list.yml.dist

@@ -0,0 +1,26 @@
+framework:
+  workflows:
+    dhcp_workflow:
+      type: state_machine
+      marking_store:
+        type: single_state
+        arguments:
+          - currentState
+      supports:
+        - IPv4Bundle\Entity\Host
+        - IPv4Bundle\Entity\Pool
+        - IPv4Bundle\Entity\SubNet
+      initial_place: active
+      places:
+        - active
+        - disable
+      transitions:
+        add_config:
+          from: active
+          to: active
+        disable:
+          from: active
+          to: disable
+        active:
+          from: disable
+          to: active

+ 2 - 0
app/config/config.yml

@@ -21,6 +21,8 @@ imports:
     - { resource: "bundles/ik/base-admin-bundle/parameters.yml" }
     - { resource: "bundles/ik/device-bundle/parameters.yml" }
     - { resource: "bundles/ik/webservice-bundle/parameters.yml" }
+    # - { resource: workflow.yml }
+    - { resource: "../Resources/workflows/workflow_list.yml", ignore_errors: true  }
 
     - { resource: "@DHCPBundle/Resources/config/services.yml" }
     - { resource: "@IPv4Bundle/Resources/config/services.yml" }

+ 11 - 1
composer.json

@@ -176,10 +176,17 @@
         "symfony/phpunit-bridge": "^3.3"
     },
     "scripts": {
+        "workflows-commands": [
+            "chown -Rf www-data:www-data app/Resources/workflows",
+            "cp -n app/Resources/workflows/workflow_list.yml.dist app/Resources/workflows/workflow_list.yml",
+            "chown -Rf www-data:www-data app/Resources/workflows/workflow_list.yml",
+            "chown -Rf www-data:www-data web/workflows_png"
+        ],
         "mkdir-dir-cache-sessions-logs": "mkdir -p var/cache var/logs var/sessions",
         "chmod-dir-cache-sessions-logs": "chmod 777 -R var/cache var/logs var/sessions",
         "doctrine-update": "php bin/console doctrine:schema:update --force",
-        "doctrine-migrations": "php bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration",
+        "doctrine-migrations-down": "php bin/console doctrine:migrations:migrate --no-interaction first -vvv",
+        "doctrine-migrations": "php bin/console doctrine:migrations:migrate --no-interaction -vvv",
         "auto-increment": "php bin/console baseadmin:autoincrement",
         "symfony-scripts": [
             "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
@@ -190,14 +197,17 @@
             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
         ],
         "post-install-cmd": [
+            "@workflows-commands",
             "@symfony-scripts",
             "@mkdir-dir-cache-sessions-logs",
             "@chmod-dir-cache-sessions-logs",
             "@doctrine-update",
             "@auto-increment",
+            "@doctrine-migrations-down",
             "@doctrine-migrations"
         ],
         "post-update-cmd": [
+            "@workflows-commands",
             "@symfony-scripts",
             "@mkdir-dir-cache-sessions-logs",
             "@chmod-dir-cache-sessions-logs",

+ 17 - 1
src/IPv4Bundle/Entity/Host.php

@@ -6,15 +6,19 @@ use Doctrine\ORM\Mapping as ORM;
 use JMS\Serializer\Annotation as JMS;
 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 use IPv4Bundle\Traits\DHCPOptionTrait;
+use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
+use WorkflowBundle\Entity\Traits\WorkflowTrait;
 
 /**
  * @ORM\Entity
  * @ORM\HasLifecycleCallbacks
  * @UniqueEntity("mac")
  */
-class Host
+class Host implements WorkflowInterface
 {
+
     use DHCPOptionTrait;
+    use WorkflowTrait;
 
     const STATE_ACTIVE = 'active';
     const STATE_SUSPENDED = 'suspended';
@@ -59,6 +63,18 @@ class Host
      */
     protected $state = self::STATE_ACTIVE;
 
+    /**
+     * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
+     * @ORM\JoinColumn(name="workflow_id", referencedColumnName="id", onDelete="SET NULL")
+     * @JMS\MaxDepth(1)
+     */
+    protected $workflow;
+
+    /**
+     * @ORM\Column(type="string", nullable=true)
+     */
+    protected $currentState = null;
+
 
     /**
      * @return string

+ 16 - 1
src/IPv4Bundle/Entity/Pool.php

@@ -5,10 +5,13 @@ namespace IPv4Bundle\Entity;
 use Base\AdminBundle\Traits\TenancyIdTrait;
 use Base\AdminBundle\Traits\TenancyIdTraitInterface;
 use Doctrine\ORM\Mapping as ORM;
+use JMS\Serializer\Annotation as JMS;
 use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 use Symfony\Component\Validator\Constraints as Assert;
 use Symfony\Component\Validator\Context\ExecutionContextInterface;
 use Symfony\Component\HttpFoundation\IpUtils;
+use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
+use WorkflowBundle\Entity\Traits\WorkflowTrait;
 
 /**
  * @ORM\Entity
@@ -17,10 +20,11 @@ use Symfony\Component\HttpFoundation\IpUtils;
  *
  * @Assert\Callback("validateIPs")
  */
-class Pool implements TenancyIdTraitInterface
+class Pool implements TenancyIdTraitInterface, WorkflowInterface
 {
 
     use TenancyIdTrait;
+    use WorkflowTrait;
 
     /**
      * @var bigint $id
@@ -79,6 +83,17 @@ class Pool implements TenancyIdTraitInterface
      */
     protected $isStatic;
 
+    /**
+     * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
+     * @ORM\JoinColumn(name="workflow_id", referencedColumnName="id", onDelete="SET NULL")
+     * @JMS\MaxDepth(1)
+     */
+    protected $workflow;
+
+    /**
+     * @ORM\Column(type="string", nullable=true)
+     */
+    protected $currentState = null;
 
     /**
     * @return string

+ 16 - 2
src/IPv4Bundle/Entity/SubNet.php

@@ -10,6 +10,9 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
 use Symfony\Component\Validator\Constraints as Assert;
 use Symfony\Component\Validator\Context\ExecutionContextInterface;
 use IPv4Bundle\Traits\DHCPOptionTrait;
+use JMS\Serializer\Annotation as JMS;
+use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
+use WorkflowBundle\Entity\Traits\WorkflowTrait;
 
 /**
  * @ORM\Entity
@@ -20,12 +23,12 @@ use IPv4Bundle\Traits\DHCPOptionTrait;
  *
  * @ORM\HasLifecycleCallbacks
  */
-class SubNet implements TenancyIdTraitInterface
+class SubNet implements TenancyIdTraitInterface, WorkflowInterface
 {
 
     use TenancyIdTrait;
-
     use DHCPOptionTrait;
+    use WorkflowTrait;
 
     /**
      * @ORM\Column(name="id", type="bigint", nullable=false)
@@ -73,6 +76,17 @@ class SubNet implements TenancyIdTraitInterface
      */
     protected $ipPool;
 
+    /**
+     * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
+     * @ORM\JoinColumn(name="workflow_id", referencedColumnName="id", onDelete="SET NULL")
+     * @JMS\MaxDepth(1)
+     */
+    protected $workflow;
+
+    /**
+     * @ORM\Column(type="string", nullable=true)
+     */
+    protected $currentState = null;
 
     public function __construct()
     {

+ 0 - 0
web/workflows_png/.gitkeep