Exemplo n.º 1
0
  def Initialize(self, cluster_identifier, node_type, node_count, user,
                 password, cluster_parameter_group, cluster_subnet_group):
    """Method to initialize a Redshift cluster from an configuration parameters.

    The cluster is initialized in the EC2-VPC platform, that runs it in a
    virtual private cloud (VPC). This allows control access to the cluster by
    associating one or more VPC security groups with the cluster.

    To create a cluster in a VPC, first create an Amazon Redshift cluster subnet
    group by providing subnet information of the VPC, and then provide the
    subnet group when launching the cluster.


    Args:
      cluster_identifier: A unique identifier for the cluster.
      node_type: The node type to be provisioned for the cluster.
       Valid Values: ds2.xlarge | ds2.8xlarge | ds2.xlarge | ds2.8xlarge |
         dc1.large | dc1.8xlarge | dc2.large | dc2.8xlarge
      node_count: The number of compute nodes in the cluster.
      user: The user name associated with the master user account for the
        cluster that is being created.
      password: The password associated with the master user account for the
        cluster that is being created.
      cluster_parameter_group: Cluster Parameter Group associated with the
        cluster.
      cluster_subnet_group: Cluster Subnet Group associated with the cluster.

    Returns:
      None


    Raises:
      MissingOption: If any of the required parameters is missing.
    """
    if not (cluster_identifier and node_type and user and password):
      raise errors.MissingOption('Need cluster_identifier, user and password '
                                 'set for creating a cluster.')

    prefix = [
        'redshift', 'create-cluster', '--cluster-identifier', cluster_identifier
    ]

    if node_count == 1:
      worker_count_cmd = ['--cluster-type', 'single-node']
    else:
      worker_count_cmd = ['--number-of-nodes', str(node_count)]

    postfix = [
        '--node-type', node_type, '--master-username', user,
        '--master-user-password', password, '--cluster-parameter-group-name',
        cluster_parameter_group.name, '--cluster-subnet-group-name',
        cluster_subnet_group.name, '--publicly-accessible',
        ELIMINATE_AUTOMATED_SNAPSHOT_RETENTION
    ]

    cmd = self.cmd_prefix + prefix + worker_count_cmd + postfix
    stdout, stderr, _ = vm_util.IssueCommand(cmd, raise_on_failure=False)
    if not stdout:
      raise errors.Resource.CreationError('Cluster creation failure: '
                                          '{}'.format(stderr))
Exemplo n.º 2
0
    def Restore(self, snapshot_identifier, cluster_identifier):
        """Method to restore a Redshift cluster from an existing snapshot.

    A snapshot of cluster in VPC can be restored only in VPC. Therefore, subnet
    group name where the cluster is to be restored must be provided.

    vpc-security-group-ids are not specified at the time of restoration, and it
    is expected that the default VPC security group which gets associated with
    the cluster has appropriate ingress and egress rules.

    Ref: http://docs.aws.amazon.com/cli/latest/reference/
    redshift/restore-from-cluster-snapshot.html

    Args:
      snapshot_identifier: Identifier of the snapshot to restore
      cluster_identifier:  Identifier of the restored cluster
    Returns:
      None
    """
        if not (FLAGS.edw_service_cluster_user
                and FLAGS.edw_service_cluster_password
                and FLAGS.edw_service_cluster_db):
            raise errors.MissingOption(
                'Need the db, user and password set for '
                'restoring a cluster')
        else:
            self.db = FLAGS.edw_service_cluster_db
            self.user = FLAGS.edw_service_cluster_user
            self.password = FLAGS.edw_service_cluster_password

        if self._ValidateSnapshot(snapshot_identifier):
            node_type, node_count = self._SnapshotDetails(snapshot_identifier)
            self.spec.node_type = node_type
            self.spec.node_count = node_count
            cmd = self.cmd_prefix + [
                'redshift', 'restore-from-cluster-snapshot',
                '--cluster-identifier', cluster_identifier,
                '--snapshot-identifier', snapshot_identifier,
                '--cluster-subnet-group-name', self.cluster_subnet_group.name,
                '--cluster-parameter-group-name',
                self.cluster_subnet_group.name, '--publicly-accessible',
                '--automated-snapshot-retention-period=0'
            ]
            stdout, stderr, _ = vm_util.IssueCommand(cmd)
            if not stdout:
                raise errors.Resource.CreationError(
                    'Cluster creation failure: '
                    '{}'.format(stderr))