Commit 37bd7d70 authored by Jon Pugh's avatar Jon Pugh

Add "services" to non-servers as "service_subscriptions". Separate method...

Add "services" to non-servers as "service_subscriptions". Separate method options_documentation() to server_options, platform_options, and site_options.
parent 06280e10
......@@ -81,9 +81,9 @@ class ServicesCommand extends Command
$input,
$output
);
if (isset($this->context->type) && $this->context->type != 'server') {
throw new \Exception('Context must be a server.');
}
// if (isset($this->context->type) && $this->context->type != 'server') {
// throw new \Exception('Context must be a server.');
// }
$this->sub_command = $input->getArgument('sub_command');
}
......@@ -120,19 +120,42 @@ class ServicesCommand extends Command
$this->io->comment("Add Services");
$service = $this->io->choice('Which service?', $this->context->getServiceOptions());
// Then ask which service type
$service_type = $this->io->choice('Which service type?', $this->context->getServiceTypeOptions($service));
// Then ask for all options.
$properties = $this->askForServiceProperties($service);
// If server, ask which service type.
if ($this->context->type == 'server') {
$service_type = $this->io->choice('Which service type?', $this->context->getServiceTypeOptions($service));
$this->io->info("Adding $service service $service_type...");
// Then ask for all options.
$properties = $this->askForServiceProperties($service);
try {
$this->context->config['services'][$service] = [
$this->io->info("Adding $service service $service_type...");
$services_key = 'services';
$service_info = [
'type' => $service_type,
'properties' => $properties,
];
}
// All other context types are associating with servers that provide the service.
else {
$server = $this->io->choice('Which server?', $this->getApplication()->getServerOptions($service));
// Then ask for all options.
$server_context = $this->getApplication()->getContext($server);
$properties = $this->askForServiceProperties($service);
$this->io->info("Using $service service from server $server...");
$services_key = 'service_subscriptions';
$service_info = [
'server' => $server,
];
}
try {
$this->context->config[$services_key][$service] = $service_info;
if (!empty($properties)) {
$this->context->config[$services_key][$service]['properties'] = $properties;
}
$this->context->save();
$this->io->success('Service saved to Context!');
}
......@@ -149,8 +172,9 @@ class ServicesCommand extends Command
private function askForServiceProperties($service) {
$class = $this->context->getAvailableServices($service);
$method = "{$this->context->type}_options";
$options = $class::option_documentation();
$options = $class::{$method}();
$properties = [];
foreach ($options as $name => $description) {
// If option does not exist, ask for it.
......
......@@ -143,7 +143,7 @@ class Context
*
* @return array
*/
public function getAvailableServices($service = NULL) {
public function getAvailableServices($service = '') {
// Load all service classes
$classes = [];
......@@ -246,7 +246,7 @@ class Context
public function getConfigTreeBuilder()
{
$tree_builder = new TreeBuilder();
$root_node = $tree_builder->root('server');
$root_node = $tree_builder->root($this->type);
$root_node
->children()
->scalarNode('name')
......@@ -255,15 +255,24 @@ class Context
->end();
// Load Services
if ($this->type == 'server') {
$services_key = 'services';
$services_property = 'type';
}
else {
$services_key = 'service_subscriptions';
$services_property = 'server';
}
$root_node
->children()
->arrayNode('services')
->arrayNode($services_key)
->prototype('array')
->children()
->scalarNode('type')
->scalarNode($services_property)
->isRequired(true)
->end()
->append($this->addServiceProperties())
->append($this->addServiceProperties($services_key))
->end()
->end();
......@@ -287,18 +296,28 @@ class Context
/**
* Append Service class options_documentation to config tree.
*/
public function addServiceProperties()
public function addServiceProperties($property_name = 'services')
{
$builder = new TreeBuilder();
$node = $builder->root('properties');
// Load config tree from Service type classes
if (!empty($this->getProperty('services')) && !empty($this->getProperty('services'))) {
foreach ($this->getProperty('services') as $service => $info) {
if (!empty($this->getProperty($property_name)) && !empty($this->getProperty($property_name))) {
foreach ($this->getProperty($property_name) as $service => $info) {
// If type is empty, it's because it's in the ServerContext
if (empty($info['type'])) {
$server = $this->application->getContext($info['server']);
$service_type = ucfirst($server->getService($service)->type);
}
else {
$service_type = ucfirst($info['type']);
}
$service = ucfirst($service);
$service_type = ucfirst($info['type']);
$class = "\Aegir\Provision\Service\\{$service}\\{$service}{$service_type}Service";
foreach ($class::option_documentation() as $name => $description) {
$method = "{$this->type}_options";
foreach ($class::{$method}() as $name => $description) {
$node
->children()
->scalarNode($name)->end()
......
......@@ -69,28 +69,31 @@ class Service {
* Return a list of user configurable options that this service provides to Server Context objects.
*/
static function server_options() {
return [
'http_port' => 'The port which the web service is running on.',
'web_group' => 'server with http: OS group for permissions; working default will be attempted',
];
return [];
// return [
// 'http_port' => 'The port which the web service is running on.',
// 'web_group' => 'server with http: OS group for permissions; working default will be attempted',
// ];
}
/**
* Return a list of user configurable options that this service provides to Platform Context objects.
*/
static function platform_options() {
return [
'platform_extra_config' => 'Extra lines of configuration to add to this platform.',
];
return [];
// return [
// 'platform_extra_config' => 'Extra lines of configuration to add to this platform.',
// ];
}
/**
* Return a list of user configurable options that this service provides to Site Context objects.
*/
static function site_options() {
return [
'site_mail' => 'The email address to use for the ServerAdmin configuration.',
];
return [];
// return [
// 'site_mail' => 'The email address to use for the ServerAdmin configuration.',
// ];
}
/**
......@@ -429,16 +432,6 @@ class Service {
// return TRUE;
// }
/**
* Return service-specific configuration options for help.
*
* @return
* array('option' => 'description')
*/
static function option_documentation() {
return array();
}
/**
* Save symlink for this server from /var/aegir/config/APPLICATION_NAME.conf -> /var/aegir/config/SERVER/APPLICATION_NAME.conf
*
......
......@@ -24,7 +24,12 @@ class DbService extends Service
const SERVICE_NAME = 'Database Server';
static function option_documentation()
/**
* Implements Service::server_options()
*
* @return array
*/
static function server_options()
{
return [
'master_db' => 'server with db: Master database connection info, {type}://{user}:{password}@{host}',
......@@ -32,6 +37,20 @@ class DbService extends Service
];
}
/**
* Implements Service::server_options()
*
* @return array
*/
static function site_options()
{
return [
'db_name' => 'The name of the database. Default: Automatically generated.',
'db_user' => 'The username used to access the database. Default: Automatically generated.',
'db_password' => 'The password used to access the database. Default: Automatically generated.',
];
}
/**
* Register the db handler for sites, based on the db_server option.
*/
......
......@@ -24,16 +24,21 @@ class HttpService extends Service {
protected $ssl_enabled = FALSE;
static function option_documentation() {
return array(
/**
* Implements Service::server_options()
*
* @return array
*/
static function server_options()
{
return [
'http_port' => 'The port which the web service is running on.',
// 'http_platformd_path' => 'The path to store platforms.',
// 'http_postd_path' => 'The path to store post configuration.',
'web_group' => 'server with http: OS group for permissions; working default will be attempted',
'web_disable_url' => 'server with http: URL disabled sites are redirected to; default {master_url}/hosting/disabled',
'web_maintenance_url' => 'server with http: URL maintenance sites are redirected to; default {master_url}/hosting/maintenance',
'restart_command' => 'The command to reload the web server configuration;'
);
];
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment