本文整理汇总了Python中cm.services.ServiceRole.legacy_convert方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceRole.legacy_convert方法的具体用法?Python ServiceRole.legacy_convert怎么用?Python ServiceRole.legacy_convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cm.services.ServiceRole
的用法示例。
在下文中一共展示了ServiceRole.legacy_convert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: normalize_user_data
# 需要导入模块: from cm.services import ServiceRole [as 别名]
# 或者: from cm.services.ServiceRole import legacy_convert [as 别名]
def normalize_user_data(app, ud):
"""
Normalize user data format to a consistent representation used within CloudMan.
This is useful as user data and also persistent data evolve over time and thus
calling this method at app start enables any necessary translation to happen.
"""
if ud.get('persistent_data_version', 1) < app.PERSISTENT_DATA_VERSION:
# First make a backup of the deprecated persistent data file
s3_conn = app.cloud_interface.get_s3_connection()
copy_file_in_bucket(
s3_conn, ud['bucket_cluster'], ud['bucket_cluster'],
'persistent_data.yaml', 'persistent_data-deprecated.yaml', preserve_acl=False,
validate=False)
# Convert (i.e., normalize) v2 ud
if 'filesystems' in ud:
log.debug("Normalizing v2 user data")
for fs in ud['filesystems']:
if 'roles' not in fs:
fs['roles'] = ServiceRole.legacy_convert(fs['name'])
if 'delete_on_termination' not in fs:
if fs['kind'] == 'snapshot':
fs['delete_on_termination'] = True
else:
fs['delete_on_termination'] = False
for svc in ud.get('services', []):
if 'roles' not in svc:
svc['roles'] = ServiceRole.legacy_convert(
svc.get('name', 'NoName'))
# Convert (i.e., normalize) v1 ud
if "static_filesystems" in ud or "data_filesystems" in ud:
log.debug("Normalizing v1 user data")
if 'filesystems' not in ud:
ud['filesystems'] = []
if 'static_filesystems' in ud:
for vol in ud['static_filesystems']:
# Create a mapping between the old and the new format styles
# Some assumptions are made here; namely, all static file systems
# in the original data are assumed delete_on_termination, their name
# defines their role and they are mounted under /mnt/<name>
roles = ServiceRole.legacy_convert(vol['filesystem'])
fs = {'kind': 'snapshot', 'name': vol['filesystem'],
'roles': roles, 'delete_on_termination': True,
'mount_point': os.path.join('/mnt', vol['filesystem']),
'ids': [vol['snap_id']]}
ud['filesystems'].append(fs)
ud.pop('static_filesystems')
ud['cluster_type'] = 'Galaxy'
if 'data_filesystems' in ud:
for fs_name, fs in ud['data_filesystems'].items():
fs = {'kind': 'volume', 'name': fs_name,
'roles': ServiceRole.legacy_convert(fs_name), 'delete_on_termination': False,
'mount_point': os.path.join('/mnt', fs_name),
'ids': [fs[0]['vol_id']]}
ud['filesystems'].append(fs)
ud.pop('data_filesystems')
if 'cluster_type' not in ud:
ud['cluster_type'] = 'Data'
if 'galaxy_home' in ud:
ud.pop('galaxy_home')
if 'services' in ud and 'service' in ud['services'][0]:
log.debug("Normalizing v1 service user data")
old_svc_list = ud['services']
ud['services'] = []
# clear 'services' and replace with the new format
for svc in old_svc_list:
if 'roles' not in svc:
normalized_svc = {'name': svc['service'], 'roles':
ServiceRole.legacy_convert(svc['service'])}
ud['services'].append(normalized_svc)
return ud
示例2: normalize_user_data
# 需要导入模块: from cm.services import ServiceRole [as 别名]
# 或者: from cm.services.ServiceRole import legacy_convert [as 别名]
def normalize_user_data(app, ud):
"""
Normalize user data format to a consistent representation used within CloudMan.
This is useful as user data and also persistent data evolve over time and thus
calling this method at app start enables any necessary translation to happen.
"""
if ud.get("persistent_data_version", 1) < app.PERSISTENT_DATA_VERSION:
# First make a backup of the deprecated persistent data file
s3_conn = app.cloud_interface.get_s3_connection()
copy_file_in_bucket(
s3_conn,
ud["bucket_cluster"],
ud["bucket_cluster"],
"persistent_data.yaml",
"persistent_data-deprecated.yaml",
preserve_acl=False,
validate=False,
)
# Convert (i.e., normalize) v2 ud
if "filesystems" in ud:
log.debug("Normalizing v2 user data")
for fs in ud["filesystems"]:
if "roles" not in fs:
fs["roles"] = ServiceRole.legacy_convert(fs["name"])
if "delete_on_termination" not in fs:
if fs["kind"] == "snapshot":
fs["delete_on_termination"] = True
else:
fs["delete_on_termination"] = False
for svc in ud.get("services", []):
if "roles" not in svc:
svc["roles"] = ServiceRole.legacy_convert(svc.get("name", "NoName"))
# Convert (i.e., normalize) v1 ud
if "static_filesystems" in ud or "data_filesystems" in ud:
log.debug("Normalizing v1 user data")
if "filesystems" not in ud:
ud["filesystems"] = []
if "static_filesystems" in ud:
for vol in ud["static_filesystems"]:
# Create a mapping between the old and the new format styles
# Some assumptions are made here; namely, all static file systems
# in the original data are assumed delete_on_termination, their name
# defines their role and they are mounted under /mnt/<name>
roles = ServiceRole.legacy_convert(vol["filesystem"])
fs = {
"kind": "snapshot",
"name": vol["filesystem"],
"roles": roles,
"delete_on_termination": True,
"mount_point": os.path.join("/mnt", vol["filesystem"]),
"ids": [vol["snap_id"]],
}
ud["filesystems"].append(fs)
ud.pop("static_filesystems")
ud["cluster_type"] = "Galaxy"
if "data_filesystems" in ud:
for fs_name, fs in ud["data_filesystems"].items():
fs = {
"kind": "volume",
"name": fs_name,
"roles": ServiceRole.legacy_convert(fs_name),
"delete_on_termination": False,
"mount_point": os.path.join("/mnt", fs_name),
"ids": [fs[0]["vol_id"]],
}
ud["filesystems"].append(fs)
ud.pop("data_filesystems")
if "cluster_type" not in ud:
ud["cluster_type"] = "Data"
if "galaxy_home" in ud:
ud.pop("galaxy_home")
if "services" in ud and "service" in ud["services"][0]:
log.debug("Normalizing v1 service user data")
old_svc_list = ud["services"]
ud["services"] = []
# clear 'services' and replace with the new format
for svc in old_svc_list:
if "roles" not in svc:
normalized_svc = {"name": svc["service"], "roles": ServiceRole.legacy_convert(svc["service"])}
ud["services"].append(normalized_svc)
return ud