Skip to content

Commit

Permalink
Rds v3 (#50)
Browse files Browse the repository at this point in the history
* Adding RDS v3 implementation
  • Loading branch information
vineet-pruthi authored and gtema committed Oct 11, 2019
1 parent 3b56141 commit 0b0939b
Show file tree
Hide file tree
Showing 48 changed files with 5,970 additions and 30 deletions.
1 change: 1 addition & 0 deletions doc/source/enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def get_proxy_methods():
"otcextensions.sdk.kms.v1._proxy",
"otcextensions.sdk.obs.v1._proxy",
"otcextensions.sdk.rds.v1._proxy",
"otcextensions.sdk.rds.v3._proxy",
"otcextensions.sdk.volume_backup.v2._proxy"
]

Expand Down
File renamed without changes.
55 changes: 55 additions & 0 deletions doc/source/user/proxies/rds_v3.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Database RDS API
================

For details on how to use database, see :doc:`/user/guides/rds`

.. automodule:: otcextensions.sdk.rds.v3._proxy

The Database Class
------------------

The database high-level interface is available through the ``rds`` member of a
:class:`~openstack.connection.Connection` object. The ``rds`` member will only
be added if the ``otcextensions.sdk.register_otc_extensions(conn)`` method is
called.

Datastore Operations
^^^^^^^^^^^^^^^^^^^^

.. autoclass:: otcextensions.sdk.rds.v3._proxy.Proxy

.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.datastore_versions
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.get_datastore_version
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.datastore_types

Flavor Operations
^^^^^^^^^^^^^^^^^

.. autoclass:: otcextensions.sdk.rds.v3._proxy.Proxy

.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.get_flavor
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.flavors

Instance Operations
^^^^^^^^^^^^^^^^^^^

.. autoclass:: otcextensions.sdk.rds.v3._proxy.Proxy

.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.create_instance
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.update_instance
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.delete_instance
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.get_instance
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.find_instance
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.instances


Backup Operations
^^^^^^^^^^^^^^^^^

.. autoclass:: otcextensions.sdk.rds.v3._proxy.Proxy

.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.backups
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.create_backup
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.delete_backup
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.get_backup_policy
.. automethod:: otcextensions.sdk.rds.v3._proxy.Proxy.set_backup_policy
3 changes: 3 additions & 0 deletions doc/source/user/resources/rds/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ RDS Resources
v1/configuration
v1/flavor
v1/instance
v3/configuration
v3/flavor
v3/instance
13 changes: 13 additions & 0 deletions doc/source/user/resources/rds/v3/configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
otcextensions.sdk.rds.v3.configuration
======================================

.. automodule:: otcextensions.sdk.rds.v3.configuration

The Configuration Class
-----------------------

The ``Configuration`` class inherits from
:class:`~otcextensions.sdk.sdk_resource.Resource`.

.. autoclass:: otcextensions.sdk.rds.v3.configuration.ConfigurationGroup
:members:
13 changes: 13 additions & 0 deletions doc/source/user/resources/rds/v3/flavor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
otcextensions.sdk.rds.v3.flavor
===============================

.. automodule:: otcextensions.sdk.rds.v3.flavor

The Flavor Class
----------------

The ``Flavor`` class inherits from
:class:`~otcextensions.sdk.sdk_resource.Resource`.

.. autoclass:: otcextensions.sdk.rds.v3.flavor.Flavor
:members:
13 changes: 13 additions & 0 deletions doc/source/user/resources/rds/v3/instance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
otcextensions.sdk.rds.v3.instance
=================================

.. automodule:: otcextensions.sdk.rds.v3.instance

The Instance Class
------------------

The ``Instance`` class inherits from
:class:`~otcextensions.sdk.sdk_resource.Resource`.

.. autoclass:: otcextensions.sdk.rds.v3.instance.Instance
:members:
14 changes: 12 additions & 2 deletions otcextensions/osclient/rds/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
#
import logging

from otcextensions import sdk
from osc_lib import utils

from otcextensions import sdk
from otcextensions.i18n import _

LOG = logging.getLogger(__name__)

DEFAULT_API_VERSION = '1.0'
DEFAULT_API_VERSION = '3'
API_VERSION_OPTION = 'os_rds_api_version'
API_NAME = "rds"
API_VERSIONS = {
"1.0": "openstack.connection.Connection",
"1": "openstack.connection.Connection",
"3": "openstack.connection.Connection"
}


Expand All @@ -42,4 +45,11 @@ def make_client(instance):

def build_option_parser(parser):
"""Hook to add global options"""
parser.add_argument(
'--os-rds-api-version',
metavar='<rds-api-version>',
default=utils.env('OS_RDS_API_VERSION'),
help=_("RDS API version, default=%s "
"(Env: OS_RDS_API_VERSION)") % DEFAULT_API_VERSION
)
return parser
Empty file.
211 changes: 211 additions & 0 deletions otcextensions/osclient/rds/v3/backup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""Backup v3 action implementations"""

from osc_lib import utils
from osc_lib.command import command

from otcextensions.common import sdk_utils
from otcextensions.i18n import _


BACKUP_TYPE_CHOICES = ['auto', 'manual', 'fragment', 'incremental']


_formatters = {
}


def _get_columns(item):
column_map = {}
hidden = ['location']
return sdk_utils.get_osc_show_columns_for_sdk_resource(
item, column_map, hidden)


class ListBackup(command.Lister):
_description = _("List database backups")
column_headers = (
'ID', 'Name', 'Type', 'Instance Id', 'Size (KB)'
)

columns = (
'id', 'name', 'type', 'instance_id', 'size'
)

def get_parser(self, prog_name):
parser = super(ListBackup, self).get_parser(prog_name)
parser.add_argument(
'instance',
metavar='<instance>',
help=_('Specify instance ID or Name to get backup list'),
)
parser.add_argument(
'--backup-id',
metavar='<backup_id>',
help=_('Specify the backup ID.'),
)
parser.add_argument(
'--backup-type',
metavar='{' + ','.join(BACKUP_TYPE_CHOICES) + '}',
choices=BACKUP_TYPE_CHOICES,
type=lambda s: s.lower(),
help=_('Specify the backup type.'),
)
parser.add_argument(
'--offset',
metavar='<offset>',
type=int,
help=_('Specify the index position.'),
)
parser.add_argument(
'--limit',
metavar='<limit>',
type=int,
help=_('Specify the limit of resources to be queried.'),
)
# parser.add_argument(
# '--begin-time',
# metavar='<begin_time>',
# help=_('Specify the start time for obtaining the backup list.'),
# )
# parser.add_argument(
# '--end-time',
# metavar='<end_time>',
# help=_('Specify the end time for obtaining the backup list.'),
# )

return parser

def take_action(self, parsed_args):
client = self.app.client_manager.rds
attrs = {}
args_list = [
'backup_id', 'backup_type', 'offset', 'limit'
# , 'begin_time', 'end_time'
]
for arg in args_list:
if getattr(parsed_args, arg):
attrs[arg] = getattr(parsed_args, arg)
if parsed_args.limit:
attrs['paginated'] = False

instance = client.find_instance(parsed_args.instance,
ignore_missing=False)

data = client.backups(instance=instance, **attrs)

return (self.column_headers, (utils.get_item_properties(
s,
self.columns,
) for s in data))


class CreateBackup(command.ShowOne):
_description = _('Create Database backup')

def get_parser(self, prog_name):
parser = super(CreateBackup, self).get_parser(prog_name)
parser.add_argument(
'name',
metavar='<name>',
help=_('Name for the backup'))
parser.add_argument(
'instance',
metavar='<instance>',
help=_('ID or Name of the instance to create backup from'))
parser.add_argument(
'--description',
metavar='<description>',
help=_('Description for the backup'))
parser.add_argument(
'--databases',
metavar='<databases>',
help=_(
'Specifies a CSV list of self-built SQL Server'
'databases that are partially backed up'
'(Only SQL Server support partial backups.)'))
return parser

def take_action(self, parsed_args):
client = self.app.client_manager.rds

attrs = {'name': parsed_args.name}
if parsed_args.description:
attrs['description'] = parsed_args.description

instance = client.find_instance(parsed_args.instance,
ignore_missing=False)

if (parsed_args.databases
and instance.datastore['type'].lower() == 'sqlserver'):
attrs['databases'] = []
databases = parsed_args.databases
databases = databases.split(",")
for db_name in databases:
attrs['databases'].append({'name': db_name})
else:
# Do we want to raise error otherwise?
pass

obj = client.create_backup(instance=instance,
**attrs)

display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns,
formatters=_formatters)

return (display_columns, data)


class DeleteBackup(command.Command):
_description = _('Delete Backup')

def get_parser(self, prog_name):
parser = super(DeleteBackup, self).get_parser(prog_name)
parser.add_argument('backup',
metavar='<backup_id>',
nargs='+',
help=_('ID of the backup'))
return parser

def take_action(self, parsed_args):

if parsed_args.backup:
client = self.app.client_manager.rds
for bck in parsed_args.backup:
client.delete_backup(backup=bck, ignore_missing=False)


class ListBackupDownloadLinks(command.Lister):
_description = _('List Backup Download Links')

column_headers = ('Size (KB)', 'URL', 'Expires at')
columns = ('size', 'download_link', 'expires_at')

def get_parser(self, prog_name):
parser = super(ListBackupDownloadLinks, self).get_parser(prog_name)
parser.add_argument('backup_id',
metavar='<backup_id>',
help=_('ID of the backup'))
return parser

def take_action(self, parsed_args):

client = self.app.client_manager.rds
data = client.backup_download_links(backup_id=parsed_args.backup_id)
return (self.column_headers, (utils.get_item_properties(
s,
self.columns,
formatters={}
) for s in data))
Loading

0 comments on commit 0b0939b

Please sign in to comment.