Commit 76fced91 authored by Yas Naoi's avatar Yas Naoi
Browse files

Issue #3320310 by yas, Xiaohua Guan: Add a feature to update OpenStack network...

Issue #3320310 by yas, Xiaohua Guan: Add a feature to update OpenStack network (neutron) resources by a cron job
parent 00d29c15
Loading
Loading
Loading
Loading
+18 −18
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ function openstack_update_resources(CloudConfig $cloud_config): void {

  /** @var \Drupal\openstack\Service\OpenStackServiceInterface $openstack_service */
  $openstack_service = \Drupal::service('openstack.factory')->get($cloud_config->getCloudContext());
  if (!empty($openstack_ec2_api)) {

  $openstack_service->updateInstances();
  $openstack_service->updateImages();
  $openstack_service->updateKeyPairs();
@@ -83,17 +83,17 @@ function openstack_update_resources(CloudConfig $cloud_config): void {
  $openstack_service->updateSnapshots();
  $openstack_service->updateNetworkInterfaces();
  $openstack_service->updateFloatingIps();

  if (!empty($openstack_ec2_api)) {

    return;
  }
  else {
    $openstack_service->updateInstances();
    $openstack_service->updateImages();
    $openstack_service->updateKeyPairs();
    $openstack_service->updateVolumes();
    $openstack_service->updateSnapshots();
    $openstack_service->updateSecurityGroups();
    $openstack_service->updateFloatingIps();
    $openstack_service->updateNetworkInterfaces();
  }

  $openstack_service->updateNetworks();
  $openstack_service->updateSubnets();
  $openstack_service->updatePorts();
  $openstack_service->updateRouters();
  $openstack_service->updateQuotas();
}

/**
+80 −0
Original line number Diff line number Diff line
@@ -1251,4 +1251,84 @@ class OpenStackService extends Ec2Service implements OpenStackServiceInterface,
    return $this->cloudService->getTagValueCreatedByUid($bundle, $cloud_context, $uid);
  }

  /**
   * {@inheritdoc}
   */
  public function updateNetworks(array $params = [], $clear = TRUE): bool {
    // @todo Implement updateNetworks() method.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function updateNetworkEntities(array $params = [], $clear = TRUE, $entity_type = '', $cloud_context = '', $update = TRUE): bool {
    // @todo Implement updateNetworkEntities() method.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function updateSubnets(array $params = [], $clear = TRUE): bool {
    // @todo Implement updateSubnets() method.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function updateSubnetEntities(array $params = [], $clear = TRUE, $entity_type = '', $cloud_context = '', $update = TRUE): bool {
    // @todo Implement updateSubnetEntities() method.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function updatePorts(array $params = [], $clear = TRUE): bool {
    // @todo Implement updatePorts() method.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function updatePortEntities(array $params = [], $clear = TRUE, $entity_type = '', $cloud_context = '', $update = TRUE): bool {
    // @todo Implement updatePortEntities() method.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function updateRouters(array $params = [], $clear = TRUE): bool {
    // @todo Implement updateRouters() method.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function updateRouterEntities(array $params = [], $clear = TRUE, $entity_type = '', $cloud_context = '', $update = TRUE): bool {
    // @todo Implement updateRouterEntities() method.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function updateQuotas(array $params = [], $clear = TRUE): bool {
    // @todo Implement updateQuotas() method.
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function updateQuotaEntities(array $params = [], $clear = TRUE, $entity_type = '', $cloud_context = '', $update = TRUE): bool {
    // @todo Implement updateQuotaEntities() method.
    return TRUE;
  }

}
+52 −0
Original line number Diff line number Diff line
@@ -615,6 +615,58 @@ class OpenStackRestServiceMock extends OpenStackService {
    return $this->getMockData(__FUNCTION__);
  }

  /**
   * Get quotas.
   *
   * @param array $params
   *   Parameters to pass to the API.
   *
   * @return array
   *   The quota API response.
   */
  public function describeQuotas(array $params = []): array {
    return $this->getMockData(__FUNCTION__);
  }

  /**
   * Get subnets.
   *
   * @param array $params
   *   Parameters to pass to the API.
   *
   * @return array
   *   The subnet API response.
   */
  public function describeSubnets(array $params = []): array {
    return $this->getMockData(__FUNCTION__);
  }

  /**
   * Get ports.
   *
   * @param array $params
   *   Parameters to pass to the API.
   *
   * @return array
   *   The port API response.
   */
  public function describePorts(array $params = []): array {
    return $this->getMockData(__FUNCTION__);
  }

  /**
   * Get routers.
   *
   * @param array $params
   *   Parameters to pass to the API.
   *
   * @return array
   *   The router API response.
   */
  public function describeRouters(array $params = []): array {
    return $this->getMockData(__FUNCTION__);
  }

  /**
   * Get Floating IP List.
   *
+160 −0
Original line number Diff line number Diff line
@@ -740,6 +740,166 @@ interface OpenStackServiceInterface {
   */
  public function updateFloatingIpEntities($entity_type = '', $cloud_context = ''): bool;

  /**
   * Update the OpenStackNetworks.
   *
   * @param array $params
   *   Optional parameters array.
   * @param bool $clear
   *   TRUE to clear stale networks.
   *
   * @return bool
   *   indicates success so failure.
   */
  public function updateNetworks(array $params = [], $clear = TRUE): bool;

  /**
   * Call API for updated entities and store them as Network entities.
   *
   * @param array $params
   *   Optional parameters array.
   * @param bool $clear
   *   TRUE to clear stale networks.
   * @param string $entity_type
   *   Entity type string.
   * @param string $cloud_context
   *   Cloud context string.
   * @param bool $update
   *   TRUE to update info.
   *
   * @return bool
   *   indicates success so failure.
   */
  public function updateNetworkEntities(array $params = [], $clear = TRUE, $entity_type = '', $cloud_context = '', $update = TRUE): bool;

  /**
   * Update the OpenStackSubnets.
   *
   * @param array $params
   *   Optional parameters array.
   * @param bool $clear
   *   TRUE to clear stale subnets.
   *
   * @return bool
   *   indicates success so failure.
   */
  public function updateSubnets(array $params = [], $clear = TRUE): bool;

  /**
   * Call API for updated entities and store them as Subnet entities.
   *
   * @param array $params
   *   Optional parameters array.
   * @param bool $clear
   *   TRUE to clear stale subnets.
   * @param string $entity_type
   *   Entity type string.
   * @param string $cloud_context
   *   Cloud context string.
   * @param bool $update
   *   TRUE to update info.
   *
   * @return bool
   *   indicates success so failure.
   */
  public function updateSubnetEntities(array $params = [], $clear = TRUE, $entity_type = '', $cloud_context = '', $update = TRUE): bool;

  /**
   * Update the OpenStackPorts.
   *
   * @param array $params
   *   Optional parameters array.
   * @param bool $clear
   *   TRUE to clear stale ports.
   *
   * @return bool
   *   indicates success so failure.
   */
  public function updatePorts(array $params = [], $clear = TRUE): bool;

  /**
   * Call API for updated entities and store them as Port entities.
   *
   * @param array $params
   *   Optional parameters array.
   * @param bool $clear
   *   TRUE to clear stale ports.
   * @param string $entity_type
   *   Entity type string.
   * @param string $cloud_context
   *   Cloud context string.
   * @param bool $update
   *   TRUE to update info.
   *
   * @return bool
   *   indicates success so failure.
   */
  public function updatePortEntities(array $params = [], $clear = TRUE, $entity_type = '', $cloud_context = '', $update = TRUE): bool;

  /**
   * Update the OpenStackRouters.
   *
   * @param array $params
   *   Optional parameters array.
   * @param bool $clear
   *   TRUE to clear stale routers.
   *
   * @return bool
   *   indicates success so failure.
   */
  public function updateRouters(array $params = [], $clear = TRUE): bool;

  /**
   * Call API for updated entities and store them as Router entities.
   *
   * @param array $params
   *   Optional parameters array.
   * @param bool $clear
   *   TRUE to clear stale routers.
   * @param string $entity_type
   *   Entity type string.
   * @param string $cloud_context
   *   Cloud context string.
   * @param bool $update
   *   TRUE to update info.
   *
   * @return bool
   *   indicates success so failure.
   */
  public function updateRouterEntities(array $params = [], $clear = TRUE, $entity_type = '', $cloud_context = '', $update = TRUE): bool;

  /**
   * Update the OpenStackQuotas.
   *
   * @param array $params
   *   Optional parameters array.
   * @param bool $clear
   *   TRUE to clear stale qoutas.
   *
   * @return bool
   *   indicates success so failure.
   */
  public function updateQuotas(array $params = [], $clear = TRUE): bool;

  /**
   * Call API for updated entities and store them as Quota entities.
   *
   * @param array $params
   *   Optional parameters array.
   * @param bool $clear
   *   TRUE to clear stale quotas.
   * @param string $entity_type
   *   Entity type string.
   * @param string $cloud_context
   *   Cloud context string.
   * @param bool $update
   *   TRUE to update info.
   *
   * @return bool
   *   indicates success so failure.
   */
  public function updateQuotaEntities(array $params = [], $clear = TRUE, $entity_type = '', $cloud_context = '', $update = TRUE): bool;

  /**
   * Setup IP Permissions.
   *
+5 −0
Original line number Diff line number Diff line
@@ -5688,6 +5688,11 @@ class OpenStackService extends CloudServiceBase implements OpenStackServiceInter
      'updateSecurityGroups',
      'updateFloatingIps',
      'updateNetworkInterfaces',
      'updateNetworks',
      'updateSubnets',
      'updatePorts',
      'updateRouters',
      'updateQuotas',
    ];
    self::updateResourceQueue($cloud_config, $method_names, $queue_limit);
  }