Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v0.4.1
Fetching contributors…

Cannot retrieve contributors at this time

331 lines (306 sloc) 9.511 kb
<?php
function jailadmin_schema() {
$schema['jailadmin_jails'] = array(
'description' => 'Configured jails',
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE
),
'dataset' => array(
'type' => 'varchar',
'length' => 500,
'not null' => TRUE,
),
'route' => array(
'type' => 'varchar',
'length' => 45,
),
),
'primary key' => array('name'),
);
$schema['jailadmin_host_cmds'] = array(
'description' => 'Commands to run in the host after the jail is online',
'fields' => array(
'jail' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'command' => array(
'type' => 'varchar',
'length' => 500,
'not null' => TRUE,
),
),
);
$schema['jailadmin_bridges'] = array(
'description' => 'Configured bridges',
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'device' => array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
),
'ip' => array(
'type' => 'varchar',
'length' => 45,
),
),
'primary key' => array('name'),
);
$schema['jailadmin_bridge_physicals'] = array(
'description' => 'Physical devices to include in the bridge',
'fields' => array(
'bridge' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'device' => array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE
),
),
'primary key' => array('bridge', 'device'),
);
$schema['jailadmin_services'] = array(
'description' => 'Services to start when starting the jail',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
),
'path' => array(
'type' => 'varchar',
'length' => 500,
'not null' => TRUE,
),
'jail' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
),
'primary key' => array('id'),
'indexes' => array(
'jail_index' => array('jail'),
),
);
$schema['jailadmin_epairs'] = array(
'description' => 'Virtual NICs assigned to configured jails',
'fields' => array(
'device' => array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
),
'jail' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'bridge' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'ip' => array(
'type' => 'varchar',
'length' => 45,
'not null' => TRUE,
),
'is_span' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('device'),
'indexes' => array(
'jail_index' => array('jail'),
'bridge_index' => array('bridge'),
),
);
$schema['jailadmin_epair_aliases'] = array(
'description' => 'IP aliases for an epair device',
'fields' => array(
'device' => array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
),
'ip' => array(
'type' => 'varchar',
'length' => 45,
'not null' => TRUE,
),
),
);
$schema['jailadmin_bridge_aliases'] = array(
'description' => 'IP aliases for an epair device',
'fields' => array(
'device' => array(
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
),
'ip' => array(
'type' => 'varchar',
'length' => 45,
'not null' => TRUE,
),
),
);
$schema['jailadmin_routes'] = array(
'description' => 'IPv4 and IPv6 routes to add upon jail bootup',
'fields' => array(
'jail' => array(
'type' => 'varchar',
'length' => '100',
'not null' => TRUE,
),
'source' => array(
'type' => 'varchar',
'length' => 45,
'not null' => TRUE,
),
'destination' => array(
'type' => 'varchar',
'length' => 45,
'not null' => TRUE,
),
),
);
$schema['jailadmin_templates'] = array(
'description' => 'ZFS Templates',
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'snapshot' => array(
'type' => 'varchar',
'length' => 500,
'not null' => TRUE,
),
),
'primary key' => array('name'),
);
$schema['jailadmin_mounts'] = array(
'description' => 'Custom mounts',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
),
'jail' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'target' => array(
'type' => 'varchar',
'length' => 500,
'not null' => TRUE,
),
'source' => array(
'type' => 'varchar',
'length' => 500,
'not null' => TRUE,
),
'driver' => array(
'type' => 'varchar',
'length' => 50,
),
'options' => array(
'type' => 'varchar',
'length' => 200,
),
),
'primary key' => array('id'),
);
return $schema;
}
function jailadmin_update_7001() {
$spec = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
);
db_add_field('jailadmin_epairs', 'is_span', $spec);
}
function jailadmin_update_7002() {
$schema['jailadmin_host_cmds'] = array(
'description' => 'Commands to run in the host after the jail is online',
'fields' => array(
'jail' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'command' => array(
'type' => 'varchar',
'length' => 500,
'not null' => TRUE,
),
),
);
db_create_table('jailadmin_host_cmds', $schema['jailadmin_host_cmds']);
}
/**
* Add support for IP aliases and custom routes
*/
function jailadmin_update_7003() {
db_create_table('jailadmin_routes', drupal_get_schema_unprocessed('jailadmin', 'jailadmin_routes'));
db_create_table('jailadmin_epair_aliases', drupal_get_schema_unprocessed('jailadmin', 'jailadmin_epair_aliases'));
db_create_table('jailadmin_bridge_aliases', drupal_get_schema_unprocessed('jailadmin', 'jailadmin_bridge_aliases'));
/* Port existing records over to new tables */
$result = db_select('jailadmin_epairs', 'je')
->fields('je', array('ip', 'device'))
->execute();
foreach ($result as $record) {
db_insert('jailadmin_epair_aliases')
->fields(array(
'device' => $record->device,
'ip' => $record->ip,
))->execute();
}
$result = db_select('jailadmin_bridges', 'je')
->fields('je', array('ip', 'device'))
->execute();
foreach ($result as $record) {
db_insert('jailadmin_bridge_aliases')
->fields(array(
'device' => $record->device,
'ip' => $record->ip,
))->execute();
}
$result = db_select('jailadmin_jails', 'j')
->fields('j', array('name', 'route'))
->execute();
foreach ($result as $record) {
db_insert('jailadmin_routes')
->fields(array(
'jail' => $record->name,
'source' => 'default',
'destination' => $record->route,
))->execute();
}
}
/**
* Drop unneeded fields
*/
function jailadmin_update_7004() {
db_drop_field('jailadmin_epairs', 'ip');
db_drop_field('jailadmin_bridges', 'ip');
db_drop_field('jailadmin_jails', 'route');
}
Jump to Line
Something went wrong with that request. Please try again.