本文整理汇总了Python中cinder.volume.drivers.netapp.api.NaElement类的典型用法代码示例。如果您正苦于以下问题:Python NaElement类的具体用法?Python NaElement怎么用?Python NaElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NaElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_lun_map
def _get_lun_map(self, path):
"""Gets the lun map by lun path."""
tag = None
map_list = []
while True:
lun_map_iter = NaElement('lun-map-get-iter')
lun_map_iter.add_new_child('max-records', '100')
if tag:
lun_map_iter.add_new_child('tag', tag, True)
query = NaElement('query')
lun_map_iter.add_child_elem(query)
query.add_node_with_children('lun-map-info', **{'path': path})
result = self.client.invoke_successfully(lun_map_iter, True)
tag = result.get_child_content('next-tag')
if result.get_child_content('num-records') and \
int(result.get_child_content('num-records')) >= 1:
attr_list = result.get_child_by_name('attributes-list')
lun_maps = attr_list.get_children()
for lun_map in lun_maps:
lun_m = dict()
lun_m['initiator-group'] = lun_map.get_child_content(
'initiator-group')
lun_m['lun-id'] = lun_map.get_child_content('lun-id')
lun_m['vserver'] = lun_map.get_child_content('vserver')
map_list.append(lun_m)
if tag is None:
break
return map_list
示例2: _get_lun_map
def _get_lun_map(self, path):
"""Gets the lun map by lun path."""
tag = None
map_list = []
while True:
lun_map_iter = NaElement("lun-map-get-iter")
lun_map_iter.add_new_child("max-records", "100")
if tag:
lun_map_iter.add_new_child("tag", tag, True)
query = NaElement("query")
lun_map_iter.add_child_elem(query)
query.add_node_with_children("lun-map-info", **{"path": path})
result = self.client.invoke_successfully(lun_map_iter, True)
tag = result.get_child_content("next-tag")
if result.get_child_content("num-records") and int(result.get_child_content("num-records")) >= 1:
attr_list = result.get_child_by_name("attributes-list")
lun_maps = attr_list.get_children()
for lun_map in lun_maps:
lun_m = dict()
lun_m["initiator-group"] = lun_map.get_child_content("initiator-group")
lun_m["lun-id"] = lun_map.get_child_content("lun-id")
lun_m["vserver"] = lun_map.get_child_content("vserver")
map_list.append(lun_m)
if tag is None:
break
return map_list
示例3: _get_vol_luns
def _get_vol_luns(self, vol_name):
"""Gets the luns for a volume."""
api = NaElement("lun-list-info")
if vol_name:
api.add_new_child("volume-name", vol_name)
result = self.client.invoke_successfully(api, True)
luns = result.get_child_by_name("luns")
return luns.get_children()
示例4: _add_igroup_initiator
def _add_igroup_initiator(self, igroup, initiator):
"""Adds initiators to the specified igroup."""
igroup_add = NaElement.create_node_with_children(
'igroup-add',
**{'initiator-group-name': igroup,
'initiator': initiator})
self.client.invoke_successfully(igroup_add, True)
示例5: _get_actual_path_for_export
def _get_actual_path_for_export(self, export_path):
"""Gets the actual path on the filer for export path."""
storage_path = NaElement.create_node_with_children("nfs-exportfs-storage-path", **{"pathname": export_path})
result = self._invoke_successfully(storage_path, None)
if result.get_child_content("actual-pathname"):
return result.get_child_content("actual-pathname")
raise exception.NotFound(_("No storage path found for export path %s") % (export_path))
示例6: _map_lun
def _map_lun(self, name, initiator, initiator_type='iscsi', lun_id=None):
"""Maps lun to the initiator and returns lun id assigned."""
metadata = self._get_lun_attr(name, 'metadata')
os = metadata['OsType']
path = metadata['Path']
if self._check_allowed_os(os):
os = os
else:
os = 'default'
igroup_name = self._get_or_create_igroup(initiator,
initiator_type, os)
lun_map = NaElement.create_node_with_children(
'lun-map', **{'path': path,
'initiator-group': igroup_name})
if lun_id:
lun_map.add_new_child('lun-id', lun_id)
try:
result = self.client.invoke_successfully(lun_map, True)
return result.get_child_content('lun-id-assigned')
except NaApiError as e:
code = e.code
message = e.message
msg = _('Error mapping lun. Code :%(code)s, Message:%(message)s')
msg_fmt = {'code': code, 'message': message}
exc_info = sys.exc_info()
LOG.warn(msg % msg_fmt)
(igroup, lun_id) = self._find_mapped_lun_igroup(path, initiator)
if lun_id is not None:
return lun_id
else:
raise exc_info[0], exc_info[1], exc_info[2]
示例7: _create_lun_on_eligible_vol
def _create_lun_on_eligible_vol(self, name, size, metadata,
extra_specs=None):
"""Creates an actual lun on filer."""
req_size = float(size) *\
float(self.configuration.netapp_size_multiplier)
volumes = self._get_avl_volumes(req_size, extra_specs)
if not volumes:
msg = _('Failed to get vol with required'
' size and extra specs for volume: %s')
raise exception.VolumeBackendAPIException(data=msg % name)
for volume in volumes:
try:
path = '/vol/%s/%s' % (volume.id['name'], name)
lun_create = NaElement.create_node_with_children(
'lun-create-by-size',
**{'path': path, 'size': size,
'ostype': metadata['OsType']})
self.client.invoke_successfully(lun_create, True)
metadata['Path'] = '/vol/%s/%s' % (volume.id['name'], name)
metadata['Volume'] = volume.id['name']
metadata['Qtree'] = None
return
except NaApiError:
LOG.warn(_("Error provisioning vol %(name)s on %(volume)s")
% {'name': name, 'volume': volume.id['name']})
finally:
self._update_stale_vols(volume=volume)
示例8: _map_lun
def _map_lun(self, name, initiator, initiator_type="iscsi", lun_id=None):
"""Maps lun to the initiator and returns lun id assigned."""
metadata = self._get_lun_attr(name, "metadata")
os = metadata["OsType"]
path = metadata["Path"]
if self._check_allowed_os(os):
os = os
else:
os = "default"
igroup_name = self._get_or_create_igroup(initiator, initiator_type, os)
lun_map = NaElement.create_node_with_children("lun-map", **{"path": path, "initiator-group": igroup_name})
if lun_id:
lun_map.add_new_child("lun-id", lun_id)
try:
result = self.client.invoke_successfully(lun_map, True)
return result.get_child_content("lun-id-assigned")
except NaApiError as e:
code = e.code
message = e.message
msg = _("Error mapping lun. Code :%(code)s, Message:%(message)s")
msg_fmt = {"code": code, "message": message}
exc_info = sys.exc_info()
LOG.warn(msg % msg_fmt)
(igroup, lun_id) = self._find_mapped_lun_igroup(path, initiator)
if lun_id is not None:
return lun_id
else:
raise exc_info[0], exc_info[1], exc_info[2]
示例9: _clone_lun
def _clone_lun(self, name, new_name, space_reserved):
"""Clone LUN with the given handle to the new name."""
metadata = self._get_lun_attr(name, 'metadata')
path = metadata['Path']
(parent, splitter, name) = path.rpartition('/')
clone_path = '%s/%s' % (parent, new_name)
clone_start = NaElement.create_node_with_children(
'clone-start',
**{'source-path': path, 'destination-path': clone_path,
'no-snap': 'true'})
result = self.client.invoke_successfully(clone_start, True)
clone_id_el = result.get_child_by_name('clone-id')
cl_id_info = clone_id_el.get_child_by_name('clone-id-info')
vol_uuid = cl_id_info.get_child_content('volume-uuid')
clone_id = cl_id_info.get_child_content('clone-op-id')
if vol_uuid:
self._check_clone_status(clone_id, vol_uuid, name, new_name)
cloned_lun = self._get_lun_by_args(path=clone_path)
if cloned_lun:
self._set_space_reserve(clone_path, space_reserved)
clone_meta = self._create_lun_meta(cloned_lun)
handle = self._create_lun_handle(clone_meta)
self._add_lun_to_table(
NetAppLun(handle, new_name,
cloned_lun.get_child_content('size'),
clone_meta))
else:
raise NaApiError('ENOLUNENTRY', 'No Lun entry found on the filer')
示例10: _get_cluster_file_usage
def _get_cluster_file_usage(self, path, vserver):
"""Gets the file unique bytes."""
LOG.debug(_("Getting file usage for %s"), path)
file_use = NaElement.create_node_with_children("file-usage-get", **{"path": path})
res = self._invoke_successfully(file_use, vserver)
bytes = res.get_child_content("unique-bytes")
LOG.debug(_("file-usage for path %(path)s is %(bytes)s") % {"path": path, "bytes": bytes})
return bytes
示例11: _create_igroup
def _create_igroup(self, igroup, igroup_type='iscsi', os_type='default'):
"""Creates igoup with specified args."""
igroup_create = NaElement.create_node_with_children(
'igroup-create',
**{'initiator-group-name': igroup,
'initiator-group-type': igroup_type,
'os-type': os_type})
self.client.invoke_successfully(igroup_create, True)
示例12: _get_lun_by_args
def _get_lun_by_args(self, **args):
"""Retrives lun with specified args."""
lun_iter = NaElement("lun-get-iter")
lun_iter.add_new_child("max-records", "100")
query = NaElement("query")
lun_iter.add_child_elem(query)
query.add_node_with_children("lun-info", **args)
luns = self.client.invoke_successfully(lun_iter)
attr_list = luns.get_child_by_name("attributes-list")
return attr_list.get_children()
示例13: _check_vol_not_root
def _check_vol_not_root(self, vol):
"""Checks if a volume is not root."""
vol_options = NaElement.create_node_with_children("volume-options-list-info", **{"volume": vol["name"]})
result = self.client.invoke_successfully(vol_options, True)
options = result.get_child_by_name("options")
ops = options.get_children()
for op in ops:
if op.get_child_content("name") == "root" and op.get_child_content("value") == "true":
return False
return True
示例14: _clone_file
def _clone_file(self, volume, src_path, dest_path, vserver=None):
"""Clones file on vserver"""
LOG.debug(_("""Cloning with params volume %(volume)s,src %(src_path)s,
dest %(dest_path)s, vserver %(vserver)s""")
% locals())
clone_create = NaElement.create_node_with_children(
'clone-create',
**{'volume': volume, 'source-path': src_path,
'destination-path': dest_path})
self._invoke_successfully(clone_create, vserver)
示例15: _get_if_info_by_ip
def _get_if_info_by_ip(self, ip):
"""Gets the network interface info by ip."""
net_if_iter = NaElement("net-interface-get-iter")
net_if_iter.add_new_child("max-records", "10")
query = NaElement("query")
net_if_iter.add_child_elem(query)
query.add_node_with_children("net-interface-info", **{"address": ip})
result = self._invoke_successfully(net_if_iter)
if result.get_child_content("num-records") and int(result.get_child_content("num-records")) >= 1:
attr_list = result.get_child_by_name("attributes-list")
return attr_list.get_children()
raise exception.NotFound(_("No interface found on cluster for ip %s") % (ip))