~ubuntu-branches/ubuntu/vivid/openstack-trove/vivid

« back to all changes in this revision

Viewing changes to trove/guestagent/datastore/redis/manager.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, James Page
  • Date: 2015-03-30 11:22:26 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20150330112226-op8vdoaqypjn9ghs
Tags: 2015.1~b3-0ubuntu1
[ Chuck Short ]
* New upstream release.
  - d/control: Align with upstream dependencies.
  - d/p/fix-requirements.patch: Rebased
  - d/p/patch-default-config-file.patch: Rebased

[ James Page ]
* d/rules,control: Tweak unit test execution, add subunit to BD's.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2013 Rackspace
2
 
# All Rights Reserved.
3
 
#
4
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
 
#    not use this file except in compliance with the License. You may obtain
6
 
#    a copy of the License at
7
 
#
8
 
#         http://www.apache.org/licenses/LICENSE-2.0
9
 
#
10
 
#    Unless required by applicable law or agreed to in writing, software
11
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 
#    License for the specific language governing permissions and limitations
14
 
#    under the License.
15
 
 
16
 
from trove.common import cfg
17
 
from trove.common import exception
18
 
from trove.guestagent import dbaas
19
 
from trove.guestagent import volume
20
 
from trove.common import instance as rd_instance
21
 
from trove.guestagent.common import operating_system
22
 
from trove.guestagent.datastore.redis.service import RedisAppStatus
23
 
from trove.guestagent.datastore.redis.service import RedisApp
24
 
from trove.openstack.common import log as logging
25
 
from trove.common.i18n import _
26
 
from trove.openstack.common import periodic_task
27
 
 
28
 
 
29
 
LOG = logging.getLogger(__name__)
30
 
CONF = cfg.CONF
31
 
MANAGER = CONF.datastore_manager
32
 
 
33
 
 
34
 
class Manager(periodic_task.PeriodicTasks):
35
 
    """
36
 
    This is the Redis manager class. It is dynamically loaded
37
 
    based off of the service_type of the trove instance
38
 
    """
39
 
 
40
 
    @periodic_task.periodic_task(ticks_between_runs=3)
41
 
    def update_status(self, context):
42
 
        """
43
 
        Updates the redis trove instance. It is decorated with
44
 
        perodic task so it is automatically called every 3 ticks.
45
 
        """
46
 
        LOG.debug("Update status called.")
47
 
        RedisAppStatus.get().update()
48
 
 
49
 
    def change_passwords(self, context, users):
50
 
        """
51
 
        Changes the redis instance password,
52
 
        it is currently not not implemented.
53
 
        """
54
 
        LOG.debug("Change passwords called.")
55
 
        raise exception.DatastoreOperationNotSupported(
56
 
            operation='change_passwords', datastore=MANAGER)
57
 
 
58
 
    def reset_configuration(self, context, configuration):
59
 
        """
60
 
        Resets to the default configuration,
61
 
        currently this does nothing.
62
 
        """
63
 
        LOG.debug("Reset configuration called.")
64
 
        app = RedisApp(RedisAppStatus.get())
65
 
        app.reset_configuration(configuration)
66
 
 
67
 
    def _perform_restore(self, backup_info, context, restore_location, app):
68
 
        """
69
 
        Perform a restore on this instance,
70
 
        currently it is not implemented.
71
 
        """
72
 
        LOG.debug("Perform restore called.")
73
 
        raise exception.DatastoreOperationNotSupported(
74
 
            operation='_perform_restore', datastore=MANAGER)
75
 
 
76
 
    def prepare(self, context, packages, databases, memory_mb, users,
77
 
                device_path=None, mount_point=None, backup_info=None,
78
 
                config_contents=None, root_password=None, overrides=None,
79
 
                cluster_config=None):
80
 
        """
81
 
        This is called when the trove instance first comes online.
82
 
        It is the first rpc message passed from the task manager.
83
 
        prepare handles all the base configuration of the redis instance.
84
 
        """
85
 
        try:
86
 
            app = RedisApp(RedisAppStatus.get())
87
 
            RedisAppStatus.get().begin_install()
88
 
            if device_path:
89
 
                device = volume.VolumeDevice(device_path)
90
 
                # unmount if device is already mounted
91
 
                device.unmount_device(device_path)
92
 
                device.format()
93
 
                device.mount(mount_point)
94
 
                operating_system.update_owner('redis', 'redis', mount_point)
95
 
                LOG.debug('Mounted the volume.')
96
 
            app.install_if_needed(packages)
97
 
            LOG.info(_('Writing redis configuration.'))
98
 
            app.write_config(config_contents)
99
 
            app.restart()
100
 
            LOG.info(_('Redis instance has been setup and configured.'))
101
 
        except Exception:
102
 
            LOG.exception(_("Error setting up Redis instance."))
103
 
            app.status.set_status(rd_instance.ServiceStatuses.FAILED)
104
 
            raise RuntimeError("prepare call has failed.")
105
 
 
106
 
    def restart(self, context):
107
 
        """
108
 
        Restart this redis instance.
109
 
        This method is called when the guest agent
110
 
        gets a restart message from the taskmanager.
111
 
        """
112
 
        LOG.debug("Restart called.")
113
 
        app = RedisApp(RedisAppStatus.get())
114
 
        app.restart()
115
 
 
116
 
    def start_db_with_conf_changes(self, context, config_contents):
117
 
        """
118
 
        Start this redis instance with new conf changes.
119
 
        """
120
 
        LOG.debug("Start DB with conf changes called.")
121
 
        app = RedisApp(RedisAppStatus.get())
122
 
        app.start_db_with_conf_changes(config_contents)
123
 
 
124
 
    def stop_db(self, context, do_not_start_on_reboot=False):
125
 
        """
126
 
        Stop this redis instance.
127
 
        This method is called when the guest agent
128
 
        gets a stop message from the taskmanager.
129
 
        """
130
 
        LOG.debug("Stop DB called.")
131
 
        app = RedisApp(RedisAppStatus.get())
132
 
        app.stop_db(do_not_start_on_reboot=do_not_start_on_reboot)
133
 
 
134
 
    def get_filesystem_stats(self, context, fs_path):
135
 
        """Gets the filesystem stats for the path given."""
136
 
        LOG.debug("Get Filesystem Stats.")
137
 
        mount_point = CONF.get(
138
 
            'mysql' if not MANAGER else MANAGER).mount_point
139
 
        return dbaas.get_filesystem_volume_stats(mount_point)
140
 
 
141
 
    def create_backup(self, context, backup_info):
142
 
        """
143
 
        This will eventually create a backup. Right now
144
 
        it does nothing.
145
 
        """
146
 
        LOG.debug("Create Backup called.")
147
 
        raise exception.DatastoreOperationNotSupported(
148
 
            operation='create_backup', datastore=MANAGER)
149
 
 
150
 
    def mount_volume(self, context, device_path=None, mount_point=None):
151
 
        device = volume.VolumeDevice(device_path)
152
 
        device.mount(mount_point, write_to_fstab=False)
153
 
        LOG.debug("Mounted the device %s at the mount point %s." %
154
 
                  (device_path, mount_point))
155
 
 
156
 
    def unmount_volume(self, context, device_path=None, mount_point=None):
157
 
        device = volume.VolumeDevice(device_path)
158
 
        device.unmount(mount_point)
159
 
        LOG.debug("Unmounted the device %s from the mount point %s." %
160
 
                  (device_path, mount_point))
161
 
 
162
 
    def resize_fs(self, context, device_path=None, mount_point=None):
163
 
        device = volume.VolumeDevice(device_path)
164
 
        device.resize_fs(mount_point)
165
 
        LOG.debug("Resized the filesystem at %s." % mount_point)
166
 
 
167
 
    def update_overrides(self, context, overrides, remove=False):
168
 
        LOG.debug("Updating overrides.")
169
 
        raise exception.DatastoreOperationNotSupported(
170
 
            operation='update_overrides', datastore=MANAGER)
171
 
 
172
 
    def apply_overrides(self, context, overrides):
173
 
        LOG.debug("Applying overrides.")
174
 
        raise exception.DatastoreOperationNotSupported(
175
 
            operation='apply_overrides', datastore=MANAGER)
176
 
 
177
 
    def update_attributes(self, context, username, hostname, user_attrs):
178
 
        LOG.debug("Updating attributes.")
179
 
        raise exception.DatastoreOperationNotSupported(
180
 
            operation='update_attributes', datastore=MANAGER)
181
 
 
182
 
    def create_database(self, context, databases):
183
 
        LOG.debug("Creating database.")
184
 
        raise exception.DatastoreOperationNotSupported(
185
 
            operation='create_database', datastore=MANAGER)
186
 
 
187
 
    def create_user(self, context, users):
188
 
        LOG.debug("Creating user.")
189
 
        raise exception.DatastoreOperationNotSupported(
190
 
            operation='create_user', datastore=MANAGER)
191
 
 
192
 
    def delete_database(self, context, database):
193
 
        LOG.debug("Deleting database.")
194
 
        raise exception.DatastoreOperationNotSupported(
195
 
            operation='delete_database', datastore=MANAGER)
196
 
 
197
 
    def delete_user(self, context, user):
198
 
        LOG.debug("Deleting user.")
199
 
        raise exception.DatastoreOperationNotSupported(
200
 
            operation='delete_user', datastore=MANAGER)
201
 
 
202
 
    def get_user(self, context, username, hostname):
203
 
        LOG.debug("Getting user.")
204
 
        raise exception.DatastoreOperationNotSupported(
205
 
            operation='get_user', datastore=MANAGER)
206
 
 
207
 
    def grant_access(self, context, username, hostname, databases):
208
 
        LOG.debug("Granting access.")
209
 
        raise exception.DatastoreOperationNotSupported(
210
 
            operation='grant_access', datastore=MANAGER)
211
 
 
212
 
    def revoke_access(self, context, username, hostname, database):
213
 
        LOG.debug("Revoking access.")
214
 
        raise exception.DatastoreOperationNotSupported(
215
 
            operation='revoke_access', datastore=MANAGER)
216
 
 
217
 
    def list_access(self, context, username, hostname):
218
 
        LOG.debug("Listing access.")
219
 
        raise exception.DatastoreOperationNotSupported(
220
 
            operation='list_access', datastore=MANAGER)
221
 
 
222
 
    def list_databases(self, context, limit=None, marker=None,
223
 
                       include_marker=False):
224
 
        LOG.debug("Listing databases.")
225
 
        raise exception.DatastoreOperationNotSupported(
226
 
            operation='list_databases', datastore=MANAGER)
227
 
 
228
 
    def list_users(self, context, limit=None, marker=None,
229
 
                   include_marker=False):
230
 
        LOG.debug("Listing users.")
231
 
        raise exception.DatastoreOperationNotSupported(
232
 
            operation='list_users', datastore=MANAGER)
233
 
 
234
 
    def enable_root(self, context):
235
 
        LOG.debug("Enabling root.")
236
 
        raise exception.DatastoreOperationNotSupported(
237
 
            operation='enable_root', datastore=MANAGER)
238
 
 
239
 
    def is_root_enabled(self, context):
240
 
        LOG.debug("Checking if root is enabled.")
241
 
        raise exception.DatastoreOperationNotSupported(
242
 
            operation='is_root_enabled', datastore=MANAGER)
243
 
 
244
 
    def get_replication_snapshot(self, context, snapshot_info,
245
 
                                 replica_source_config=None):
246
 
        LOG.debug("Getting replication snapshot.")
247
 
        raise exception.DatastoreOperationNotSupported(
248
 
            operation='get_replication_snapshot', datastore=MANAGER)
249
 
 
250
 
    def attach_replication_slave(self, context, snapshot, slave_config):
251
 
        LOG.debug("Attaching replica.")
252
 
        raise exception.DatastoreOperationNotSupported(
253
 
            operation='attach_replication_slave', datastore=MANAGER)
254
 
 
255
 
    def detach_replica(self, context):
256
 
        LOG.debug("Detaching replica.")
257
 
        raise exception.DatastoreOperationNotSupported(
258
 
            operation='detach_replica', datastore=MANAGER)
259
 
 
260
 
    def demote_replication_master(self, context):
261
 
        LOG.debug("Demoting replica source.")
262
 
        raise exception.DatastoreOperationNotSupported(
263
 
            operation='demote_replication_master', datastore=MANAGER)