Refactoring of code:
1) new snapshot module with code vss, lvm and part of backup.py - create_snapshot and remove_snapshot This module should contain all code related shadow, vss and any new snapshots. 2) new openstack module with code from osclient, restore and backup (BackupOS) This module should contain code related to cinder/nova backups 3) new utils module with code from utils, win_utils, bandwidth, config, exec_cmd, validator, streaming This module should containd code related to anything that cannot be extracted to its own module 4) new test modules - snapshot, utils, openstack and apiclient. Test scheduler daemon is now located in scheduler module. 5) Backup.py is deleted and code placed to openstack.backup (BackupOS) and to job.BackupJob Change-Id: I46194b40b3a65c15b6095cfb7388dcfd30d95997changes/16/288416/9
parent
ee97dbf49a
commit
c01d7c0a72
@ -0,0 +1,81 @@
|
||||
"""
|
||||
(c) Copyright 2015,2016 Hewlett-Packard Development Company, L.P.
|
||||
|
||||
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.
|
||||
"""
|
||||
import os
|
||||
|
||||
|
||||
class OpenstackOptions:
|
||||
"""
|
||||
Stores credentials for OpenStack API.
|
||||
Can be created using
|
||||
>> create_from_env()
|
||||
or
|
||||
>> create_from_dict(dict)
|
||||
"""
|
||||
def __init__(self, user_name, tenant_name, project_name, auth_url,
|
||||
password, identity_api_version, tenant_id=None,
|
||||
region_name=None, endpoint_type=None, cert=None,
|
||||
insecure=False, verify=True):
|
||||
self.user_name = user_name
|
||||
self.tenant_name = tenant_name
|
||||
self.auth_url = auth_url
|
||||
self.password = password
|
||||
self.tenant_id = tenant_id
|
||||
self.project_name = project_name
|
||||
self.identity_api_version = identity_api_version
|
||||
self.region_name = region_name
|
||||
self.endpoint_type = endpoint_type
|
||||
self.cert = cert
|
||||
self.insecure = insecure
|
||||
self.verify = verify
|
||||
if not (self.password and self.user_name and self.auth_url and
|
||||
(self.tenant_name or self.project_name)):
|
||||
raise Exception("Please set up in your env:"
|
||||
"OS_USERNAME, OS_TENANT_NAME/OS_PROJECT_NAME,"
|
||||
" OS_AUTH_URL, OS_PASSWORD")
|
||||
|
||||
@property
|
||||
def os_options(self):
|
||||
"""
|
||||
:return: The OpenStack options which can have tenant_id,
|
||||
auth_token, service_type, endpoint_type, tenant_name,
|
||||
object_storage_url, region_name
|
||||
"""
|
||||
return {'tenant_id': self.tenant_id,
|
||||
'tenant_name': self.tenant_name,
|
||||
'project_name': self.project_name,
|
||||
'identity_api_version': self.identity_api_version,
|
||||
'region_name': self.region_name,
|
||||
'endpoint_type': self.endpoint_type}
|
||||
|
||||
@staticmethod
|
||||
def create_from_env():
|
||||
return OpenstackOptions.create_from_dict(os.environ)
|
||||
|
||||
@staticmethod
|
||||
def create_from_dict(src_dict):
|
||||
return OpenstackOptions(
|
||||
user_name=src_dict.get('OS_USERNAME', None),
|
||||
tenant_name=src_dict.get('OS_TENANT_NAME', None),
|
||||
project_name=src_dict.get('OS_PROJECT_NAME', None),
|
||||
auth_url=src_dict.get('OS_AUTH_URL', None),
|
||||
identity_api_version=src_dict.get('OS_IDENTITY_API_VERSION',
|
||||
'2.0'),
|
||||
password=src_dict.get('OS_PASSWORD', None),
|
||||
tenant_id=src_dict.get('OS_TENANT_ID', None),
|
||||
region_name=src_dict.get('OS_REGION_NAME', None),
|
||||
endpoint_type=src_dict.get('OS_ENDPOINT_TYPE', None),
|
||||
cert=src_dict.get('OS_CERT', None)
|
||||
)
|
@ -0,0 +1,62 @@
|
||||
"""
|
||||
(c) Copyright 2014,2015 Hewlett-Packard Development Company, L.P.
|
||||
|
||||
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.
|
||||
|
||||
Freezer Backup modes related functions
|
||||
"""
|
||||
import os
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from freezer.snapshot import lvm
|
||||
from freezer.snapshot import vss
|
||||
from freezer.utils import winutils
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
logging = log.getLogger(__name__)
|
||||
home = os.path.expanduser("~")
|
||||
|
||||
|
||||
def snapshot_create(backup_opt_dict):
|
||||
"""
|
||||
Calls the code to take fs snapshots, depending on the platform
|
||||
|
||||
:param backup_opt_dict:
|
||||
:return: boolean value, True if snapshot has been taken, false otherwise
|
||||
"""
|
||||
|
||||
if winutils.is_windows():
|
||||
if backup_opt_dict.snapshot:
|
||||
# Create a shadow copy.
|
||||
backup_opt_dict.shadow_path, backup_opt_dict.shadow = \
|
||||
vss.vss_create_shadow_copy(backup_opt_dict.windows_volume)
|
||||
|
||||
backup_opt_dict.path_to_backup = winutils.use_shadow(
|
||||
backup_opt_dict.path_to_backup,
|
||||
backup_opt_dict.windows_volume)
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
return lvm.lvm_snap(backup_opt_dict)
|
||||
|
||||
|
||||
def snapshot_remove(backup_opt_dict, shadow, windows_volume):
|
||||
if winutils.is_windows():
|
||||
# Delete the shadow copy after the backup
|
||||
vss.vss_delete_shadow_copy(shadow, windows_volume)
|
||||
else:
|
||||
# Unmount and remove lvm snapshot volume
|
||||
lvm.lvm_snap_remove(backup_opt_dict)
|