Permalink
Browse files

Add support for DHCP

  • Loading branch information...
1 parent e7764ae commit df14a2407c787a012bb498631253fcd26fec6285 @lattera committed Dec 5, 2012
Showing with 30 additions and 4 deletions.
  1. +6 −0 classes/NetworkDevice.php
  2. +17 −4 jailadmin.install
  3. +7 −0 jailconfig.inc
@@ -5,6 +5,7 @@ class NetworkDevice {
public $ips;
public $bridge;
public $is_span;
+ public $dhcp;
public $jail;
public static function Load($jail) {
@@ -65,6 +66,9 @@ public function BringGuestOnline() {
exec("/usr/local/bin/sudo /usr/sbin/jexec \"{$this->jail->name}\" ifconfig {$this->device}b up");
+ if ($this->dhcp)
+ exec("/usr/local/bin/sudo /usr/sbin/jexec \"{$this->jail->name}\" /sbin/dhclient {$this->device}b > /dev/null 2>&1 &");
+
return TRUE;
}
@@ -84,6 +88,7 @@ protected static function LoadFromRecord($jail, $record=array()) {
$net_device = new NetworkDevice;
$net_device->device = $record['device'];
$net_device->is_span = ($record['is_span'] == 1) ? TRUE : FALSE;
+ $net_device->dhcp = ($record['dhcp'] == 1) ? TRUE : FALSE;
$net_device->bridge = Network::Load($record['bridge']);
$net_device->jail = $jail;
@@ -136,6 +141,7 @@ public function Create() {
'device' => $this->device,
'bridge' => $this->bridge->name,
'is_span' => ($this->is_span) ? 1 : 0,
+ 'dhcp' => ($this->dhcp) ? 1 : 0,
))->execute();
return TRUE;
View
@@ -118,12 +118,12 @@ function jailadmin_schema() {
'length' => 100,
'not null' => TRUE,
),
- 'ip' => array(
- 'type' => 'varchar',
- 'length' => 45,
+ 'is_span' => array(
+ 'type' => 'int',
'not null' => TRUE,
+ 'default' => 0,
),
- 'is_span' => array(
+ 'dhcp' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
@@ -328,3 +328,16 @@ function jailadmin_update_7004() {
db_drop_field('jailadmin_bridges', 'ip');
db_drop_field('jailadmin_jails', 'route');
}
+
+/**
+ * Add DHCP support
+ */
+function jailadmin_update_7005() {
+ $spec = array(
+ 'type' => 'int',
+ 'not null' => TRUE,
+ 'default' => 0,
+ );
+
+ db_add_field('jailadmin_epairs', 'dhcp', $spec);
+}
View
@@ -96,6 +96,12 @@ function jailadmin_config($form, &$form_state) {
'#default_value' => FALSE,
);
+ $form['network_devices']['new_network_dhcp'] = array(
+ '#type' => 'checkbox',
+ '#title' => 'Use DHCP',
+ '#default_value' => FALSE,
+ );
+
$form['routes'] = array(
'#type' => 'fieldset',
'#title' => t('Routes'),
@@ -371,6 +377,7 @@ function jailadmin_config_submit($form, &$form_state) {
$network_device->bridge = Network::Load($form_state['values']['new_network_network']);
$network_device->device = $form_state['values']['new_network_device'];
$network_device->is_span = $form_state['values']['new_network_span'];
+ $network_device->dhcp = $form_state['values']['new_network_dhcp'];
$network_device->Create();

0 comments on commit df14a24

Please sign in to comment.