Commit cb248274 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3294201 by Xiaohua Guan, yas: Manage Cloud Orchestrator deployment ...

Issue #3294201 by Xiaohua Guan, yas: Manage Cloud Orchestrator deployment  (Add support to AWS CFn templates for manual configuration)
parent 041b2522
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -76,12 +76,12 @@ class CloudFormationBatchOperations {
    $entity->setParameters(array_map(fn($item) => [
      'item_key' => $item['ParameterKey'] ?? '',
      'item_value' => $item['ParameterValue'] ?? '',
    ], $stack['Parameters'] ?: []));
    ], $stack['Parameters'] ?? []));

    $entity->setOutputs(array_map(fn($item) => [
      'item_key' => $item['OutputKey'] ?? '',
      'item_value' => $item['OutputValue'] ?? '',
    ], $stack['Outputs'] ?: []));
    ], $stack['Outputs'] ?? []));

    $entity->save();
  }
+13 −9
Original line number Diff line number Diff line
@@ -636,8 +636,8 @@ function cloud_cluster_get_deployment_templates_by_type(?string $deployment_type
      continue;
    }

    $template_definitions = Yaml::decode(file_get_contents("$template_path/$folder/templates.yml"));
    foreach ($template_definitions ?: [] as $name => $template_definition) {
    $definition = Yaml::decode(file_get_contents("$template_path/$folder/deploy.yml"));
    foreach ($definition['templates'] ?: [] as $name => $template_definition) {
      $templates[$name] = $template_definition['label'];
    }
  }
@@ -743,18 +743,22 @@ function cloud_cluster_render_deployment_parameters(array &$form, CloudLaunchTem
    \Drupal::service('extension.path.resolver')->getPath('module', 'cloud_cluster')
    ) . '/templates/' . $cloud_launch_template->field_deployment_type->value;

  $config = Yaml::decode(file_get_contents("$template_path/parameters.yml"));
  foreach ($config['groups'] ?: [] as $group) {
    $detail[$group['name']] = [
  $deployment_template = $cloud_launch_template->field_deployment_template->value;

  $definition = Yaml::decode(file_get_contents("$template_path/deploy.yml"));
  $parameters = $definition['parameters'];

  foreach ($definition['templates'][$deployment_template]['parameter_groups'] ?: [] as $parameter_group) {
    $detail[$parameter_group['name']] = [
      '#type' => 'details',
      '#title' => $group['title'],
      '#title' => $parameter_group['title'],
      '#open' => TRUE,
    ];

    foreach ($group['parameters'] ?: [] as $parameter) {
    foreach ($parameter_group['parameter_refs'] ?: [] as $parameter_name) {
      $item = [];

      foreach ($parameter as $key => $value) {
      foreach ($parameters[$parameter_name] as $key => $value) {
        if ($key === 'name') {
          continue;
        }
@@ -766,7 +770,7 @@ function cloud_cluster_render_deployment_parameters(array &$form, CloudLaunchTem
        $item["#$key"] = $value;
      }

      $detail[$group['name']][$parameter['name']] = $item;
      $detail[$parameter_group['name']][$parameter_name] = $item;
    }
  }

+6 −33
Original line number Diff line number Diff line
@@ -199,9 +199,9 @@ class CloudClusterCloudLaunchTemplatePlugin extends CloudPluginBase implements C

    $deployment_type = $cloud_launch_template->field_deployment_type->value;

    $template_definitions_path = realpath(
    $deployment_definition_path = realpath(
      sprintf(
        '%s/templates/%s/templates.yml',
        '%s/templates/%s/deploy.yml',
        $this->extensionPathResolver->getPath('module', 'cloud_cluster'),
        $deployment_type
      )
@@ -209,14 +209,14 @@ class CloudClusterCloudLaunchTemplatePlugin extends CloudPluginBase implements C

    $deployment_template = $cloud_launch_template->field_deployment_template->value;

    $template_definitions = Yaml::decode(file_get_contents($template_definitions_path));
    $template_definition = $template_definitions[$deployment_template];
    $deployment_definition = Yaml::decode(file_get_contents($deployment_definition_path));
    $template_definition = $deployment_definition['templates'][$deployment_template];
    $template_location = $template_definition['location'];

    // If the location is a relative path, the definition folder path
    // should be added.
    $template_content = file_get_contents($template_location)
      ?: file_get_contents(dirname($template_definitions_path) . '/' . $template_location);
      ?: file_get_contents(dirname($deployment_definition_path) . '/' . $template_location);

    $parameters = [];
    foreach ($form_state->getValue('parameters') ?: [] as $group) {
@@ -242,13 +242,7 @@ class CloudClusterCloudLaunchTemplatePlugin extends CloudPluginBase implements C
      $cloud_launch_template->validate();
      $cloud_launch_template->save();

      $parameter_definitions = $this->loadParameterDefinitions(realpath(
        sprintf(
          '%s/templates/%s/parameters.yml',
          $this->extensionPathResolver->getPath('module', 'cloud_cluster'),
          $deployment_type
        )
      ));
      $parameter_definitions = $deployment_definition['parameters'];

      // Create cloud cluster site object.
      $timestamp = time();
@@ -374,25 +368,4 @@ class CloudClusterCloudLaunchTemplatePlugin extends CloudPluginBase implements C
    return $field;
  }

  /**
   * Load parameter definitions.
   *
   * @param string $parameter_definitions_path
   *   The path of parameter definition file.
   *
   * @return array
   *   Parameter definitions.
   */
  private function loadParameterDefinitions($parameter_definitions_path): array {
    $definitions = [];
    $yml = Yaml::decode(file_get_contents($parameter_definitions_path));
    foreach ($yml['groups'] ?: [] as $group) {
      foreach ($group['parameters'] ?: [] as $parameter) {
        $definitions[$parameter['name']] = $parameter;
      }
    }

    return $definitions;
  }

}
+222 −0
Original line number Diff line number Diff line
parameters:
  StackName:
    title: Stack name
    default_value: ''
    type: textfield
  StackPrefix:
    title: Stack prefix
    description: A prefix to append to resource names/IDs. For example, ${StackPrefix}-IAM-Role,
      ${StackPrefix}-Drupal-RDS for RDS DB Identifier. Must be between 1 and 20 characters
      and only contain alphanumeric characters and hyphens.
    default_value: ''
    pattern: ^[a-zA-Z0-9\\-]+$
    maxlength: 20
    type: textfield
  DrupalUserName:
    title: Drupal administrator username
    default_value: cloud_admin
    type: textfield
  DrupalPassword:
    title: Drupal administrator password
    description: >-
      The Drupal admin account password. Must be between 6 and 32 characters
      and only contain alphanumeric characters and these special characters ` ~ ! # $ % ^ & * ( ) _ + , . \ -
    default_value: cloud_admin
    pattern: ^[\w`~!#$%^&*()_+,.\\-]+$
    maxlength: 32
    type: password
  DrupalEmail:
    title: Drupal administrator email address
    default_value: cloud_admin@example.com
    type: email
  DrupalTimezone:
    title: Drupal default time zone
    default_value: America/Los_Angeles
    type: timezone
  MySQLUserName:
    title: MySQL administrator username
    default_value: mysql_admin
    type: textfield
  MySQLPassword:
    title: MySQL administrator password
    description: >-
      Password for the RDS Username.  Must be between 6 and 32 characters
      and only contain alphanumeric characters and these special characters ` ~ ! # $ % ^ & * ( ) _ + , . \ -
    default_value: mysql_admin_password
    maxlength: 32
    pattern: ^[\w`~!#$%^&*()_+,.\\-]+$
    type: password
  DatabaseName:
    title: MySQL database name
    description: The name of the database. Must be between 4 and 32 characters and
      only contain alphanumeric characters and underscores.
    pattern: ^[a-zA-Z0-9_]+$
    maxlength: 32
    minlength: 4
    default_value: cloud_orchestrator
    type: textfield
  KeyName:
    title: EC2 key name
    default_value: ''
    type: entity_select
    entity_type: aws_cloud_key_pair
    entity_key: key_pair_name
    cloud_context: ''
  VPC:
    title: VPC
    default_value: ''
    type: entity_select
    entity_type: aws_cloud_vpc
    entity_key: vpc_id
    cloud_context: ''
  PrivateSubnet1:
    title: Private subnet1
    default_value: ''
    type: entity_select
    entity_type: aws_cloud_subnet
    entity_key: subnet_id
    cloud_context: ''
  PrivateSubnet2:
    title: Private subnet2
    default_value: ''
    type: entity_select
    entity_type: aws_cloud_subnet
    entity_key: subnet_id
    cloud_context: ''
  PublicSubnet1:
    title: Public subnet1
    default_value: ''
    type: entity_select
    entity_type: aws_cloud_subnet
    entity_key: subnet_id
    cloud_context: ''
  Subnet:
    title: Subnet
    default_value: ''
    type: entity_select
    entity_type: aws_cloud_subnet
    entity_key: subnet_id
    cloud_context: ''

templates:
  cloud_orchestrator_full:
    label: Cloud Orchestrator Full
    location: https://cloud-orchestrator.s3.amazonaws.com/cfn/cloud_orchestrator_full.yaml
    parameter_groups:
      - name: stack
        title: Stack Configuration
        parameter_refs:
          - StackName
          - StackPrefix
      - name: drupal
        title: Drupal configuration
        parameter_refs:
          - DrupalUserName
          - DrupalPassword
          - DrupalEmail
          - DrupalTimezone

      - name: database
        title: Database configuration
        parameter_refs:
          - MySQLUserName
          - MySQLPassword
          - DatabaseName

      - name: aws_ec2
        title: Amazon EC2 Configuration
        parameter_refs:
          - KeyName

  cloud_orchestrator_full_manual_vpc:
    label: Cloud Orchestrator Full Manual VPC
    location: https://cloud-orchestrator.s3.amazonaws.com/cfn/cloud_orchestrator_full_manual_vpc.yaml
    parameter_groups:
      - name: stack
        title: Stack Configuration
        parameter_refs:
          - StackName
          - StackPrefix
      - name: drupal
        title: Drupal configuration
        parameter_refs:
          - DrupalUserName
          - DrupalPassword
          - DrupalEmail
          - DrupalTimezone

      - name: database
        title: Database configuration
        parameter_refs:
          - MySQLUserName
          - MySQLPassword
          - DatabaseName

      - name: aws_ec2
        title: Amazon EC2 Configuration
        parameter_refs:
          - KeyName
          - VPC
          - PrivateSubnet1
          - PrivateSubnet2
          - PublicSubnet1

  cloud_orchestrator_single:
    label: Cloud Orchestrator Single
    location: https://cloud-orchestrator.s3.amazonaws.com/cfn/cloud_orchestrator_single.yaml
    parameter_groups:
      - name: stack
        title: Stack Configuration
        parameter_refs:
          - StackName
          - StackPrefix
      - name: drupal
        title: Drupal configuration
        parameter_refs:
          - DrupalUserName
          - DrupalPassword
          - DrupalEmail
          - DrupalTimezone

      - name: database
        title: Database configuration
        parameter_refs:
          - MySQLUserName
          - MySQLPassword
          - DatabaseName

      - name: aws_ec2
        title: Amazon EC2 Configuration
        parameter_refs:
          - KeyName

  cloud_orchestrator_single_manual_vpc:
    label: Cloud Orchestrator Single Manual VPC
    location: https://cloud-orchestrator.s3.amazonaws.com/cfn/cloud_orchestrator_single_manual_vpc.yaml
    parameter_groups:
      - name: stack
        title: Stack Configuration
        parameter_refs:
          - StackName
          - StackPrefix
      - name: drupal
        title: Drupal configuration
        parameter_refs:
          - DrupalUserName
          - DrupalPassword
          - DrupalEmail
          - DrupalTimezone

      - name: database
        title: Database configuration
        parameter_refs:
          - MySQLUserName
          - MySQLPassword
          - DatabaseName

      - name: aws_ec2
        title: Amazon EC2 Configuration
        parameter_refs:
          - KeyName
          - VPC
          - Subnet
+0 −78
Original line number Diff line number Diff line
groups:
  - name: stack
    title: Stack Configuration
    parameters:
      - name: StackName
        title: Stack name
        default_value: ''
        type: textfield
      - name: StackPrefix
        title: Stack prefix
        description: A prefix to append to resource names/IDs. For example, ${StackPrefix}-IAM-Role,
          ${StackPrefix}-Drupal-RDS for RDS DB Identifier. Must be between 1 and 20 characters
          and only contain alphanumeric characters and hyphens.
        default_value: ''
        pattern: ^[a-zA-Z0-9\\-]+$
        maxlength: 20
        type: textfield
  - name: drupal
    title: Drupal configuration
    parameters:
      - name: DrupalUserName
        title: Drupal administrator username
        default_value: cloud_admin
        type: textfield
      - name: DrupalPassword
        title: Drupal administrator password
        description: >-
          The Drupal admin account password. Must be between 6 and 32 characters
          and only contain alphanumeric characters and these special characters ` ~ ! # $ % ^ & * ( ) _ + , . \ -
        default_value: cloud_admin
        pattern: ^[\w`~!#$%^&*()_+,.\\-]+$
        maxlength: 32
        type: password
      - name: DrupalEmail
        title: Drupal administrator email address
        default_value: cloud_admin@example.com
        type: email
      - name: DrupalTimezone
        title: Drupal default time zone
        default_value: America/Los_Angeles
        type: timezone

  - name: database
    title: Database configuration
    parameters:
      - name: MySQLUserName
        title: MySQL administrator username
        default_value: mysql_admin
        type: textfield
      - name: MySQLPassword
        title: MySQL administrator password
        description: >-
          Password for the RDS Username.  Must be between 6 and 32 characters
          and only contain alphanumeric characters and these special characters ` ~ ! # $ % ^ & * ( ) _ + , . \ -
        default_value: mysql_admin_password
        maxlength: 32
        pattern: ^[\w`~!#$%^&*()_+,.\\-]+$
        type: password
      - name: DatabaseName
        title: MySQL database name
        description: The name of the database. Must be between 4 and 32 characters and
          only contain alphanumeric characters and underscores.
        pattern: ^[a-zA-Z0-9_]+$
        maxlength: 32
        minlength: 4
        default_value: cloud_orchestrator
        type: textfield

  - name: aws_ec2
    title: Amazon EC2 Configuration
    parameters:
      - name: KeyName
        title: EC2 key name
        default_value: ''
        type: entity_select
        entity_type: aws_cloud_key_pair
        entity_key: key_pair_name
        cloud_context: ''
Loading