瀏覽代碼

FD3-502 refactory dhcp option. Se agrego option 122

Guillermo Espinoza 7 年之前
父節點
當前提交
103901bc6e

+ 6 - 9
src/IPv4Bundle/Admin/SubNetAdmin.php

@@ -17,7 +17,6 @@ class SubNetAdmin extends BaseAdmin
     {
         $datagridMapper
             ->add('address')
-            ->add('options')
         ;
     }
 
@@ -51,12 +50,11 @@ class SubNetAdmin extends BaseAdmin
             ->tab('SubNet')
             ->with('')
                 ->add('address')
-                //->add('options')
                 ->add('allowedHostType')
                 ->add('netGroup')
             ->end()
             ->end()
-	;
+    ;
     }
 
     /**
@@ -66,7 +64,6 @@ class SubNetAdmin extends BaseAdmin
     {
         $showMapper
             ->add('address')
-            ->add('options')
             ->add('allowedHostType')
             ->add('netGroup')
             ->add('ipPool')
@@ -74,12 +71,12 @@ class SubNetAdmin extends BaseAdmin
     }
 
     function prePersist($object){
-	    $object->setOptions(json_encode($object->getDHCPOption()));
-	    return parent::preUpdate($object);
+        $object->setOptions(json_encode($object->getDHCPOption()));
+        return parent::preUpdate($object);
     }
-    
+
     function preUpdate($object){
-	    $object->setOptions(json_encode($object->getDHCPOption()));
-	    return parent::preUpdate($object);
+        $object->setOptions(json_encode($object->getDHCPOption()));
+        return parent::preUpdate($object);
     }
 }

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

@@ -8,30 +8,13 @@ use IPv4Bundle\Traits\DHCPOptionTrait;
 
 /**
  * @ORM\Entity
- * @ORM\HasLifecycleCallbacks 
+ * @ORM\HasLifecycleCallbacks
  * @UniqueEntity("mac")
  */
 class Host
 {
     use DHCPOptionTrait;
 
-    /** 
-     *  @ORM\PreUpdate 
-     *  @ORM\PrePersist
-     */
-    public function doDHCPOptionsPrePersist() 
-    {
-	    $this->setOptions(json_encode($this->getDHCPOption()));
-    }
-    
-    /** 
-     * @ORM\PostLoad 
-     */
-    public function doDHCPOptionOnPostLoad()
-    {
-	   $this->setDHCPOption((array)json_decode($this->getOptions()));
-    }
-
     const STATE_ACTIVE = 'active';
     const STATE_SUSPENDED = 'suspended';
 

+ 1 - 20
src/IPv4Bundle/Entity/SubNet.php

@@ -18,7 +18,7 @@ use IPv4Bundle\Traits\DHCPOptionTrait;
  *
  * @Assert\Callback("validateAddress")
  *
- * @ORM\HasLifecycleCallbacks 
+ * @ORM\HasLifecycleCallbacks
  */
 class SubNet implements TenancyIdTraitInterface
 {
@@ -27,25 +27,6 @@ class SubNet implements TenancyIdTraitInterface
 
     use DHCPOptionTrait;
 
-    /** 
-     *  @ORM\PreUpdate 
-     *  @ORM\PrePersist
-     */
-    public function doDHCPOptionsPrePersist() 
-    {
-	    $this->setOptions(json_encode($this->getDHCPOption()));
-    }
-    
-    /** 
-     * @ORM\PostLoad 
-     */
-    public function doDHCPOptionOnPostLoad()
-    {
-	   $this->setDHCPOption((array)json_decode($this->getOptions()));
-    }
-
-
-
     /**
      * @ORM\Column(name="id", type="bigint", nullable=false)
      * @ORM\Id

+ 50 - 61
src/IPv4Bundle/EventListener/AdminDHCPOption.php

@@ -5,43 +5,41 @@ namespace IPv4Bundle\EventListener;
 use Sonata\AdminBundle\Event\ConfigureEvent;
 use IPv4Bundle\Traits\DHCPOptionTrait;
 
-class AdminDHCPOption{ 
+class AdminDHCPOption
+{
+
+    private $dhcpOptions = [
+        'filename', 'subnet_mask', 'time_offset',
+        'routers', 'domain_name_servers', 'host_name',
+        'domain_name', 'broadcast_address', 'default_lease_time',
+        'max_lease_time', 'next_server', 'tftp_server_name',
+        'option122_dhcp_server', 'option122_dhcp_server_secondary',
+        'option122_provisioning_server', 'option122_provisioning_type',
+    ];
+
     /**
      * @param ConfigureEvent $event
      */
     public function configureFormFields(ConfigureEvent $event)
     {
-         $mapper = $event->getMapper();
-         $subject = $mapper->getAdmin()->getSubject();
-         if ($subject && in_array(DHCPOptionTrait::class, class_uses($subject))) {
-             if ($mapper->hasOpenTab()) {
-                 $mapper
-                     ->end()
-                     ->end();
-             }
-             $options = array(
-                 'translation_domain' => 'IPv4Bundle'
-             );
-             $mapper
-                 ->tab('DHCP Option', $options)
-                 ->with('DHCP Option', $options)
-               ->add('filename', 		'text', array('required'=> false, ))
-               ->add('subnet_mask',		'text', array('required'=> false, ))
-               ->add('time_offset',		'text', array('required'=> false, ))
-               ->add('routers',			'text', array('required'=> false, ))
-               ->add('domain_name_servers', 	'text', array('required'=> false, ))
-               ->add('host_name', 		'text', array('required'=> false, ))
-               ->add('domain_name', 		'text', array('required'=> false, ))
-               ->add('broadcast_address', 	'text', array('required'=> false, ))
-               ->add('default_lease_time', 	'text', array('required'=> false, ))
-               ->add('max_lease_time', 		'text', array('required'=> false, ))
-               ->add('next_server', 		'text', array('required'=> false, ))
-               ->add('tftp_server_name', 	'text', array('required'=> false, ))
-
-                 ->end()
-                 ->end();
-         }
-
+        $mapper = $event->getMapper();
+        $subject = $mapper->getAdmin()->getSubject();
+        if ($subject && in_array(DHCPOptionTrait::class, class_uses($subject))) {
+            if ($mapper->hasOpenTab()) {
+                $mapper->end()->end();
+            }
+            $options = array(
+                'translation_domain' => 'IPv4Bundle'
+            );
+            $mapper->tab('DHCP Option', $options)
+                ->with('DHCP Option', $options);
+            foreach ($this->dhcpOptions as $opt) {
+                $mapper->add($opt, 'text', array(
+                    'required'=> false,
+                ));
+            }
+            $mapper->end()->end();
+        }
     }
 
     /**
@@ -49,35 +47,26 @@ class AdminDHCPOption{
      */
     public function configureShowFields(ConfigureEvent $event)
     {
-    	$mapper = $event->getMapper();
-	$subject = $mapper->getAdmin()->getSubject();
+        $mapper = $event->getMapper();
+        $subject = $mapper->getAdmin()->getSubject();
         if ($subject && in_array(DHCPOptionTrait::class, class_uses($subject))) {
-	   if ($mapper->hasOpenTab()) {
-	       $mapper
-	         ->end()
-	         ->end();
-	   }
-	   $options = array(
-                 'translation_domain' => 'IPv4Bundle'
-	   );
-        
-           $mapper
-                 ->tab('DHCP Option', $options)
-                 ->with('DHCP Option', $options);
-	   if(!$mapper->has('filename')) $mapper->add('filename', 		'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('subnet_mask')) $mapper->add('subnet_mask',		'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('time_offset')) $mapper->add('time_offset',		'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('routers')) $mapper->add('routers',		'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('domain_name_servers')) $mapper->add('domain_name_servers', 	'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('host_name')) $mapper->add('host_name', 		'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('domain_name')) $mapper->add('domain_name', 		'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('broadcast_address')) $mapper->add('broadcast_address', 	'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('default_lease_time')) $mapper->add('default_lease_time', 	'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('max_lease_time')) $mapper->add('max_lease_time', 	'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('next_server')) $mapper->add('next_server', 		'text', array('required'=> false, 'mapped' => false));
-           if(!$mapper->has('tftp_server_name')) $mapper->add('tftp_server_name', 	'text', array('required'=> false, 'mapped' => false));
-
-           $mapper->end()->end();
- 	}
+            if ($mapper->hasOpenTab()) {
+                $mapper->end()->end();
+            }
+            $options = array(
+                'translation_domain' => 'IPv4Bundle'
+            );
+            $mapper->tab('DHCP Option', $options)
+                ->with('DHCP Option', $options);
+            foreach ($this->dhcpOptions as $opt) {
+                if (!$mapper->has($opt)) {
+                    $mapper->add($opt, 'text', array(
+                        'required'=> false,
+                        'mapped' => false,
+                    ));
+                }
+            }
+            $mapper->end()->end();
+        }
     }
 }

+ 21 - 1
src/IPv4Bundle/Resources/translations/IPv4Bundle.es.yml

@@ -34,7 +34,11 @@ form:
     label_max_lease_time: Max. Lease Time
     label_next_server: Next Server
     label_tftp_server_name: TFTP Server Name
-    
+    label_option122_dhcp_server: Option122 Dhcp Server
+    label_option122_dhcp_server_secondary: Option122 Dhcp Server Secondary
+    label_option122_provisioning_server: Option122 Provisioning Server
+    label_option122_provisioning_type: Option122 Provisioning Type
+
 list:
     label_mac: Mac
     label_options: Opciones
@@ -69,6 +73,22 @@ show:
     label_net_group: Grupo de red
     label_ip_pool: IP Pool
     label_state: Estado
+    label_filename: Filename
+    label_subnet_mask: Subnet Mask
+    label_time_offset: Time Offset
+    label_routers: Routers
+    label_domain_name_servers: Domain Name Servers
+    label_host_name: Host Name
+    label_domain_name: Domain Name
+    label_broadcast_address: Boradcast Address
+    label_default_lease_time: Default Lease Time
+    label_max_lease_time: Max. Lease Time
+    label_next_server: Next Server
+    label_tftp_server_name: TFTP Server Name
+    label_option122_dhcp_server: Option122 Dhcp Server
+    label_option122_dhcp_server_secondary: Option122 Dhcp Server Secondary
+    label_option122_provisioning_server: Option122 Provisioning Server
+    label_option122_provisioning_type: Option122 Provisioning Type
 
 filter:
     label_mac: Mac

+ 196 - 139
src/IPv4Bundle/Traits/DHCPOptionTrait.php

@@ -2,142 +2,199 @@
 
 namespace IPv4Bundle\Traits;
 
-
-trait DHCPOptionTrait{
-	protected $json_dhcp_option_config;
-	function getDHCPOption(){
-		return $this->json_dhcp_option_config;
-	}
-
-	function setDHCPOption($config){
-		$this->json_dhcp_option_config = $config;
-	}
-
-	function setFilename($value){
-		$this->json_dhcp_option_config['filename'] = $value;
-	}
-
-	function getFilename(){
-		return @$this->json_dhcp_option_config['filename'];
-	}
-
-        function setSubnetMask($value){
-        	$this->json_dhcp_option_config['subnet_mask'] = $value;
-	}
-
-	function getSubnetMask(){
-		return @$this->json_dhcp_option_config['subnet_mask'];
-	}
-
-        function setTimeOffset($value){
-		$this->json_dhcp_option_config['time_offset'] = $value;
-	}
-	
-	function getTimeOffset(){
-		return @$this->json_dhcp_option_config['time_offset'];
-	}
-
-	function setRouters($value){
-		$this->json_dhcp_option_config['routers'] = $value;
-	}
-
-	function getRouters(){
-		return @$this->json_dhcp_option_config['routers'];
-	}
-
-	function setDomainNameServers($value){
-		$this->json_dhcp_option_config['domain_name_servers'] = $value;
-	}
-
-	function getDomainNameServers(){
-        	return @$this->json_dhcp_option_config['domain_name_servers'];
-	}
-
-	function setHostName($value){
-		$this->json_dhcp_option_config['host_name'] = $value;
-	}
-
-	function getHostName(){
-		return @$this->json_dhcp_option_config['host_name'];
-	}
-
-        function setDomainName($value){
-		$this->json_dhcp_option_config['domain_name'] = $value;
-	}
-        function getDomainName(){
-		return @$this->json_dhcp_option_config['domain_name'];
-	}
-
-        function setBroadcastAddress($value){
-		$this->json_dhcp_option_config['broadcast_address'] = $value;
-	}
-
-	function getBroadcastAddress(){
-		return @$this->json_dhcp_option_config['broadcast_address'];
-	}
-
-	function setDefaultLeaseTime($value){
-		$this->json_dhcp_option_config['default_lease_time'] = $value;
-	}
-
-	function getDefaultLeaseTime(){
-		return @$this->json_dhcp_option_config['default_lease_time'];
-	}
-
-	function setMaxLeaseTime($value){
-		$this->json_dhcp_option_config['max_lease_time'] = $value;
-	}
-
-	function getMaxLeaseTime(){
-		return @$this->json_dhcp_option_config['max_lease_time'];
-	}
-
-	function setNextServer($value){
-		$this->json_dhcp_option_config['next_server'] = $value;
-	}
-
-	function getNextServer(){
-		return @$this->json_dhcp_option_config['next_server'];
-	}
-
-	function setTftpServerName($value){
-		$this->json_dhcp_option_config['tftp_server'] = $value;
-	}
-
-	function getTftpServerName(){
-		return @$this->json_dhcp_option_config['tftp_server'];
-	}
-
-	function setOption122DhcpServer($value){
-		$this->json_dhcp_option_config['option122.dhcp-server'] = $value;
-	}
-
-	function getOption122DhcpServer(){
-		return @$this->json_dhcp_option_config['option122.dhcp-server'];
-	}
-
-	function setOption122DhcpServerSeconday($value){
-		$this->json_dhcp_option_config['option122.dhcp-server-secundary'] = $value;
-	}
-
-	function getOption122DhcpServerSeconday(){
-		return @$this->json_dhcp_option_config['option122.dhcp-server-secundary'];
-	}
-
-	function getOption122ProvisioningServer($value){
-		$this->json_dhcp_option_config['option122.provisioning-server'] = $value;
-	}
-
-	function setOption122ProvisioningServer(){
-		return @$this->json_dhcp_option_config['option122.provisioning-server'];
-	}
-
-	function setOption122ProvisioningType($value){
-		$this->json_dhcp_option_config['option122.provisioning-type'] = $value;
-	}
-
-	function getOption122ProvisioningType(){
-		return @$this->json_dhcp_option_config['option122.provisioning-type'];
-	}
-
-} 
+use Doctrine\ORM\Mapping as ORM;
+
+trait DHCPOptionTrait
+{
+
+    protected $json_dhcp_option_config;
+
+
+    /**
+     *  @ORM\PreUpdate
+     *  @ORM\PrePersist
+     */
+    public function doDHCPOptionsPrePersist()
+    {
+        $this->setOptions(json_encode($this->getDHCPOption()));
+    }
+
+    /**
+     * @ORM\PostLoad
+     */
+    public function doDHCPOptionOnPostLoad()
+    {
+       $this->setDHCPOption((array)json_decode($this->getOptions()));
+    }
+
+    function getDHCPOption()
+    {
+        return $this->json_dhcp_option_config;
+    }
+
+    function setDHCPOption($config)
+    {
+        $this->json_dhcp_option_config = $config;
+    }
+
+    function setFilename($value)
+    {
+        $this->json_dhcp_option_config['filename'] = $value;
+    }
+
+    function getFilename()
+    {
+        return @$this->json_dhcp_option_config['filename'];
+    }
+
+    function setSubnetMask($value)
+    {
+        $this->json_dhcp_option_config['subnet_mask'] = $value;
+    }
+
+    function getSubnetMask()
+    {
+        return @$this->json_dhcp_option_config['subnet_mask'];
+    }
+
+    function setTimeOffset($value)
+    {
+        $this->json_dhcp_option_config['time_offset'] = $value;
+    }
+
+    function getTimeOffset()
+    {
+        return @$this->json_dhcp_option_config['time_offset'];
+    }
+
+    function setRouters($value)
+    {
+        $this->json_dhcp_option_config['routers'] = $value;
+    }
+
+    function getRouters()
+    {
+        return @$this->json_dhcp_option_config['routers'];
+    }
+
+    function setDomainNameServers($value)
+    {
+        $this->json_dhcp_option_config['domain_name_servers'] = $value;
+    }
+
+    function getDomainNameServers()
+    {
+            return @$this->json_dhcp_option_config['domain_name_servers'];
+    }
+
+    function setHostName($value)
+    {
+        $this->json_dhcp_option_config['host_name'] = $value;
+    }
+
+    function getHostName()
+    {
+        return @$this->json_dhcp_option_config['host_name'];
+    }
+
+    function setDomainName($value)
+    {
+        $this->json_dhcp_option_config['domain_name'] = $value;
+    }
+
+    function getDomainName()
+    {
+        return @$this->json_dhcp_option_config['domain_name'];
+    }
+
+    function setBroadcastAddress($value)
+    {
+        $this->json_dhcp_option_config['broadcast_address'] = $value;
+    }
+
+    function getBroadcastAddress()
+    {
+        return @$this->json_dhcp_option_config['broadcast_address'];
+    }
+
+    function setDefaultLeaseTime($value)
+    {
+        $this->json_dhcp_option_config['default_lease_time'] = $value;
+    }
+
+    function getDefaultLeaseTime()
+    {
+        return @$this->json_dhcp_option_config['default_lease_time'];
+    }
+
+    function setMaxLeaseTime($value)
+    {
+        $this->json_dhcp_option_config['max_lease_time'] = $value;
+    }
+
+    function getMaxLeaseTime()
+    {
+        return @$this->json_dhcp_option_config['max_lease_time'];
+    }
+
+    function setNextServer($value)
+    {
+        $this->json_dhcp_option_config['next_server'] = $value;
+    }
+
+    function getNextServer()
+    {
+        return @$this->json_dhcp_option_config['next_server'];
+    }
+
+    function setTftpServerName($value)
+    {
+        $this->json_dhcp_option_config['tftp_server'] = $value;
+    }
+
+    function getTftpServerName()
+    {
+        return @$this->json_dhcp_option_config['tftp_server'];
+    }
+
+    function setOption122DhcpServer($value)
+    {
+        $this->json_dhcp_option_config['option122.dhcp-server'] = $value;
+    }
+
+    function getOption122DhcpServer()
+    {
+        return @$this->json_dhcp_option_config['option122.dhcp-server'];
+    }
+
+    function setOption122DhcpServerSecondary($value)
+    {
+        $this->json_dhcp_option_config['option122.dhcp-server-secondary'] = $value;
+    }
+
+    function getOption122DhcpServerSecondary()
+    {
+        return @$this->json_dhcp_option_config['option122.dhcp-server-secondary'];
+    }
+
+    function setOption122ProvisioningServer($value)
+    {
+        $this->json_dhcp_option_config['option122.provisioning-server'] = $value;
+    }
+
+    function getOption122ProvisioningServer()
+    {
+        return @$this->json_dhcp_option_config['option122.provisioning-server'];
+    }
+
+    function setOption122ProvisioningType($value)
+    {
+        $this->json_dhcp_option_config['option122.provisioning-type'] = $value;
+    }
+
+    function getOption122ProvisioningType()
+    {
+        return @$this->json_dhcp_option_config['option122.provisioning-type'];
+    }
+
+}