def __init__(self, context, db_driver=None): chunk_size_bytes = CONF.backup_swift_object_size sha_block_size_bytes = CONF.backup_swift_block_size backup_default_container = CONF.backup_swift_container enable_progress_timer = CONF.backup_swift_enable_progress_timer super(SwiftBackupDriver, self).__init__(context, chunk_size_bytes, sha_block_size_bytes, backup_default_container, enable_progress_timer, db_driver) if CONF.backup_swift_url is None: self.swift_url = None info = CONF.swift_catalog_info try: service_type, service_name, endpoint_type = info.split(':') except ValueError: raise exception.BackupDriverException(_( "Failed to parse the configuration option " "'swift_catalog_info', must be in the form " "<service_type>:<service_name>:<endpoint_type>")) for entry in context.service_catalog: if entry.get('type') == service_type: self.swift_url = entry.get( 'endpoints')[0].get(endpoint_type) else: self.swift_url = '%s%s' % (CONF.backup_swift_url, context.project_id) if self.swift_url is None: raise exception.BackupDriverException(_( "Could not determine which Swift endpoint to use. This can " " either be set in the service catalog or with the " " cinder.conf config option 'backup_swift_url'.")) LOG.debug("Using swift URL %s", self.swift_url) self.swift_attempts = CONF.backup_swift_retry_attempts self.swift_backoff = CONF.backup_swift_retry_backoff LOG.debug('Connect to %s in "%s" mode', CONF.backup_swift_url, CONF.backup_swift_auth) if CONF.backup_swift_auth == 'single_user': if CONF.backup_swift_user is None: LOG.error(_LE("single_user auth mode enabled, " "but %(param)s not set"), {'param': 'backup_swift_user'}) raise exception.ParameterNotFound(param='backup_swift_user') self.conn = swift.Connection( authurl=CONF.backup_swift_url, auth_version=CONF.backup_swift_auth_version, tenant_name=CONF.backup_swift_tenant, user=CONF.backup_swift_user, key=CONF.backup_swift_key, retries=self.swift_attempts, starting_backoff=self.swift_backoff, cacert=CONF.backup_swift_ca_cert_file) else: self.conn = swift.Connection(retries=self.swift_attempts, preauthurl=self.swift_url, preauthtoken=self.context.auth_token, starting_backoff=self.swift_backoff, cacert=CONF.backup_swift_ca_cert_file)
def __init__(self, context, db_driver=None): chunk_size_bytes = CONF.backup_oNest_object_size sha_block_size_bytes = CONF.backup_oNest_block_size backup_default_container = CONF.backup_oNest_container enable_progress_timer = CONF.backup_oNest_enable_progress_timer super(oNestBackupDriver, self).__init__(context, chunk_size_bytes, sha_block_size_bytes, backup_default_container, enable_progress_timer, db_driver) # Get oNest configuration info from cinder.conf auth_protocol_version = CONF.auth_protocol_version accesskey = CONF.accesskey secretkey = CONF.secretkey is_secure = CONF.is_secure is_random_access_addr = CONF.is_random_access_addr oNesthost = CONF.oNesthost access_net_mode = CONF.access_net_mode if not accesskey or not secretkey or not oNesthost: raise exception.BackupDriverException( _('Please check the cinder.conf to make sure ' 'configure accesskey, secretkey and oNesthost.')) authinfo = onest_common.AuthInfo(auth_protocol_version, accesskey, secretkey, is_secure, is_random_access_addr, oNesthost, access_net_mode) self.onest = onest_client.OnestClient(authinfo)
def _copy_snapshot(self, disk_name, source_id, azure_type, size=None): disk_dict = { 'location': CONF.azure.location, 'account_type': azure_type, 'creation_data': { 'create_option': DiskCreateOption.copy, 'source_uri': source_id } } if size: disk_dict['disk_size_gb'] = size try: async_action = self.snapshots.create_or_update( CONF.azure.resource_group, disk_name, disk_dict ) async_action.result() except Exception as e: try: self.snapshots.delete( CONF.azure.resource_group, disk_name ) except Exception: LOG.exception(_('Failed to elete snapshot %s after create' ' failed') % disk_name) message = (_("Copy disk %(blob_name)s from %(source_id)s in Azure" " failed. reason: %(reason)s") % dict(blob_name=disk_name, source_id=source_id, reason=six.text_type(e))) LOG.exception(message) raise exception.BackupDriverException(data=message)
def __init__(self, context, db_driver=None, execute=None): super(AzureBackupDriver, self).__init__(context, db_driver) try: self.azure = Azure() self.disks = self.azure.compute.disks self.snapshots = self.azure.compute.snapshots except Exception as e: message = (_("Initialize Azure Adapter failed. reason: %s") % six.text_type(e)) LOG.exception(message) raise exception.BackupDriverException(data=message)
def delete(self, backup): """Delete a saved backup in Azure.""" disk_name = self._get_name_from_id(BACKUP_PREFIX, backup['id']) LOG.debug("Calling Delete Backup '{}' in Azure ..." .format(disk_name)) try: async_action = self.snapshots.delete( CONF.azure.resource_group, disk_name ) async_action.result() except AzureMissingResourceHttpError: # refer lvm driver, if volume to delete doesn't exist, return True. message = (_("Backup: %s does not exist.") % disk_name) LOG.info(message) except Exception as e: message = (_("Delete Backup %(volume)s in Azure failed. reason: " "%(reason)s") % dict(volume=disk_name, reason=six.text_type(e))) LOG.exception(message) raise exception.BackupDriverException(data=message) else: LOG.info(_LI("Delete Backup %s in Azure finish."), disk_name) return True
def fake_backup_metadata(self, backup, object_meta): raise exception.BackupDriverException(message=_('fake'))
def initialize(self): self.swift_attempts = CONF.backup_swift_retry_attempts self.swift_backoff = CONF.backup_swift_retry_backoff self.backup_swift_auth_insecure = CONF.backup_swift_auth_insecure if CONF.backup_swift_auth == 'single_user': if CONF.backup_swift_user is None: LOG.error("single_user auth mode enabled, " "but %(param)s not set", {'param': 'backup_swift_user'}) raise exception.ParameterNotFound(param='backup_swift_user') if CONF.backup_swift_auth_url is None: self.auth_url = None info = CONF.keystone_catalog_info try: service_type, service_name, endpoint_type = info.split(':') except ValueError: raise exception.BackupDriverException(_( "Failed to parse the configuration option " "'keystone_catalog_info', must be in the form " "<service_type>:<service_name>:<endpoint_type>")) for entry in self.context.service_catalog: if entry.get('type') == service_type: # It is assumed that service_types are unique within # the service catalog, so once the correct one is found # it is safe to break out of the loop self.auth_url = entry.get( 'endpoints')[0].get(endpoint_type) break else: self.auth_url = CONF.backup_swift_auth_url if self.auth_url is None: raise exception.BackupDriverException(_( "Could not determine which Keystone endpoint to use. This " "can either be set in the service catalog or with the " "cinder.conf config option 'backup_swift_auth_url'.")) LOG.debug("Using auth URL %s", self.auth_url) LOG.debug('Connect to %s in "%s" mode', CONF.backup_swift_auth_url, CONF.backup_swift_auth) os_options = {} if CONF.backup_swift_user_domain is not None: os_options['user_domain_name'] = CONF.backup_swift_user_domain if CONF.backup_swift_project_domain is not None: os_options['project_domain_name'] = ( CONF.backup_swift_project_domain ) if CONF.backup_swift_project is not None: os_options['project_name'] = CONF.backup_swift_project self.conn = swift.Connection( authurl=self.auth_url, auth_version=CONF.backup_swift_auth_version, tenant_name=CONF.backup_swift_tenant, user=CONF.backup_swift_user, key=CONF.backup_swift_key, os_options=os_options, retries=self.swift_attempts, starting_backoff=self.swift_backoff, insecure=self.backup_swift_auth_insecure, cacert=CONF.backup_swift_ca_cert_file) else: if CONF.backup_swift_url is None: self.swift_url = None info = CONF.swift_catalog_info try: service_type, service_name, endpoint_type = info.split(':') except ValueError: raise exception.BackupDriverException(_( "Failed to parse the configuration option " "'swift_catalog_info', must be in the form " "<service_type>:<service_name>:<endpoint_type>")) for entry in self.context.service_catalog: if entry.get('type') == service_type: # It is assumed that service_types are unique within # the service catalog, so once the correct one is found # it is safe to break out of the loop self.swift_url = entry.get( 'endpoints')[0].get(endpoint_type) break else: self.swift_url = '%s%s' % (CONF.backup_swift_url, self.context.project_id) if self.swift_url is None: raise exception.BackupDriverException(_( "Could not determine which Swift endpoint to use. This " "can either be set in the service catalog or with the " "cinder.conf config option 'backup_swift_url'.")) LOG.debug("Using swift URL %s", self.swift_url) LOG.debug('Connect to %s in "%s" mode', CONF.backup_swift_url, CONF.backup_swift_auth) self.conn = swift.Connection(retries=self.swift_attempts, preauthurl=self.swift_url, preauthtoken=self.context.auth_token, starting_backoff=self.swift_backoff, insecure=( self.backup_swift_auth_insecure), cacert=CONF.backup_swift_ca_cert_file)
def restore(self, backup, volume_id, volume_file): """Restore volume from backup in azure. only support restore backup from and to azure. delete volume disk and then copy backup to volume disk, since managed disk have no restore operation. """ target_volume = self.db.volume_get(self.context, volume_id) azure_type = StorageAccountTypes.premium_lrs \ if 'azure_ssd' == target_volume['volume_type']['name'] \ else StorageAccountTypes.standard_lrs size = target_volume['size'] disk_name = self._get_name_from_id( VOLUME_PREFIX, target_volume['id']) backup_name = self._get_name_from_id( BACKUP_PREFIX, backup['id']) # tmp snapshot to store original disk tmp_disk_name = TMP_PREFIX + '-' + disk_name try: backup_obj = self.snapshots.get( CONF.azure.resource_group, backup_name ) disk_obj = self.disks.get( CONF.azure.resource_group, disk_name ) except Exception as e: message = (_("Restoring Backup of Volume: %(volume)s in Azure" " failed. reason: %(reason)s") % dict(volume=volume_id, reason=six.text_type(e))) LOG.exception(message) raise exception.BackupNotFound(backup_id=backup['id']) # 1 snapshot volume disk self._copy_snapshot(tmp_disk_name, disk_obj.id, azure_type) try: # 2 delete original disk async_action = self.disks.delete( CONF.azure.resource_group, disk_name ) async_action.result() except Exception as e: message = (_("Restoring Backup of Volume: %(volume)s in Azure" " failed. reason: %(reason)s") % dict(volume=volume_id, reason=six.text_type(e))) LOG.exception(message) raise exception.BackupDriverException(data=message) try: # restore from backup self._copy_disk(disk_name, backup_obj.id, azure_type, size) except Exception as e: # roll back try: tmp_obj = self.snapshots.get( CONF.azure.resource_group, tmp_disk_name ) self._copy_disk(disk_name, tmp_obj.id, azure_type, size) except Exception: message = (_("Restoring Backup of Volume: %(volume)s in Azure" " failed, and the original volume are damaged.") % dict(volume=volume_id)) LOG.exception(message) raise exception.BackupDriverException(backup_id=backup['id']) else: message = (_("Restoring Backup of Volume: %(volume)s in Azure" " failed, rolled back to the original volume.") % dict(volume=volume_id)) LOG.exception(message) message = (_("Restoring Backup of Volume: %(volume)s in Azure" " failed. reason: %(reason)s") % dict(volume=volume_id, reason=six.text_type(e))) LOG.exception(message) raise exception.BackupDriverException(data=message) finally: try: # delete tmp disk async_action = self.snapshots.delete( CONF.azure.resource_group, tmp_disk_name ) async_action.result() except Exception as e: message = (_("Delete Tmp disk during Restore Backup of Volume:" " %(volume)s in Azure failed. reason: %(reason)s") % dict(volume=volume_id, reason=six.text_type(e))) LOG.exception(message) raise exception.BackupDriverException(data=message)