本文整理汇总了Python中openstack.exceptions.SDKException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.SDKException方法的具体用法?Python exceptions.SDKException怎么用?Python exceptions.SDKException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openstack.exceptions
的用法示例。
在下文中一共展示了exceptions.SDKException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update_listener_acls
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def _update_listener_acls(self, loadbalancer, listener_id, allowed_cidrs):
admin_state_up = True
if allowed_cidrs is None:
# World accessible, no restriction on the listeners
pass
elif len(allowed_cidrs) == 0:
# Prevent any traffic as no CIDR is allowed
admin_state_up = False
request = {
'allowed_cidrs': allowed_cidrs,
'admin_state_up': admin_state_up,
}
# Wait for the loadbalancer to be ACTIVE
self._wait_for_provisioning(loadbalancer, _ACTIVATION_TIMEOUT,
_LB_STS_POLL_FAST_INTERVAL)
lbaas = clients.get_loadbalancer_client()
try:
lbaas.update_listener(listener_id, **request)
except os_exc.SDKException:
LOG.exception('Error when updating listener %s' % listener_id)
raise k_exc.ResourceNotReady(listener_id)
示例2: tag_neutron_resources
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def tag_neutron_resources(resources):
"""Set tags to the provided resources.
param resources: list of openstacksdk objects to tag.
"""
tags = CONF.neutron_defaults.resource_tags
if not tags:
return
os_net = clients.get_network_client()
for res in resources:
try:
os_net.set_tags(res, tags=tags)
except os_exc.SDKException:
LOG.warning("Failed to tag %s with %s. Ignoring, but this is "
"still unexpected.", res, tags, exc_info=True)
示例3: _get_parent_port_by_host_ip
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def _get_parent_port_by_host_ip(self, node_fixed_ip):
os_net = clients.get_network_client()
node_subnet_id = oslo_cfg.CONF.pod_vif_nested.worker_nodes_subnet
if not node_subnet_id:
raise oslo_cfg.RequiredOptError(
'worker_nodes_subnet', oslo_cfg.OptGroup('pod_vif_nested'))
try:
fixed_ips = ['subnet_id=%s' % str(node_subnet_id),
'ip_address=%s' % str(node_fixed_ip)]
ports = os_net.ports(fixed_ips=fixed_ips)
except os_exc.SDKException:
LOG.error("Parent vm port with fixed ips %s not found!",
fixed_ips)
raise
try:
return next(ports)
except StopIteration:
LOG.error("Neutron port for vm port with fixed ips %s not found!",
fixed_ips)
raise kl_exc.NoResourceException
示例4: test_request_vif_port_create_failed
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def test_request_vif_port_create_failed(self, m_to_vif):
cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
m_driver = mock.Mock(spec=cls)
os_net = self.useFixture(k_fix.MockNetworkClient()).client
pod = mock.sentinel.pod
project_id = mock.sentinel.project_id
subnets = mock.sentinel.subnets
security_groups = mock.sentinel.security_groups
port_request = {'foo': mock.sentinel.port_request}
m_driver._get_port_request.return_value = port_request
os_net.create_port.side_effect = o_exc.SDKException
self.assertRaises(o_exc.SDKException, cls.request_vif,
m_driver, pod, project_id, subnets, security_groups)
m_driver._get_port_request.assert_called_once_with(
pod, project_id, subnets, security_groups)
os_net.create_port.assert_called_once_with(**port_request)
m_driver._try_update_port.assert_not_called()
m_to_vif.assert_not_called()
示例5: test_update_port_address_pairs_failure
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def test_update_port_address_pairs_failure(self):
cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
m_driver = mock.Mock(spec=cls)
os_net = self.useFixture(k_fix.MockNetworkClient()).client
port_id = lib_utils.get_hash()
pairs = mock.sentinel.allowed_address_pairs
os_net.update_port.side_effect = o_exc.SDKException
self.assertRaises(o_exc.SDKException,
cls._update_port_address_pairs, m_driver,
port_id, pairs, revision_number=9)
os_net.update_port.assert_called_with(
port_id,
allowed_address_pairs=pairs,
if_match='revision_number=9')
示例6: test_try_update_port_failure
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def test_try_update_port_failure(self, aaapf_mock):
cls = nested_macvlan_vif.NestedMacvlanPodVIFDriver
m_driver = mock.Mock(spec=cls)
m_driver.lock = mock.MagicMock(spec=threading.Lock())
self.useFixture(k_fix.MockNetworkClient()).client
port_id = lib_utils.get_hash()
vm_port = fake.get_port_obj(port_id)
mac_addr = 'fa:16:3e:1b:30:00'
address_pairs = [
{'ip_address': '10.0.0.30',
'mac_address': mac_addr},
{'ip_address': 'fe80::f816:3eff:fe1c:36a9',
'mac_address': mac_addr},
]
vm_port['allowed_address_pairs'].extend(address_pairs)
ip_addr = ['10.0.0.29']
aaapf_mock.side_effect = o_exc.SDKException
self.assertRaises(o_exc.SDKException,
cls._try_update_port, m_driver, 1,
cls._add_to_allowed_address_pairs,
vm_port, frozenset(ip_addr), mac_addr)
示例7: test_request_vifs_exception
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def test_request_vifs_exception(self, m_to_vif):
cls = neutron_vif.NeutronPodVIFDriver
m_driver = mock.Mock(spec=cls)
os_net = self.useFixture(k_fix.MockNetworkClient()).client
pod = mock.sentinel.pod
project_id = mock.sentinel.project_id
subnets = mock.sentinel.subnets
security_groups = mock.sentinel.security_groups
num_ports = 2
port_request = mock.sentinel.port_request
m_driver._get_port_request.return_value = port_request
bulk_rq = {'ports': [port_request for _ in range(num_ports)]}
os_net.create_ports.side_effect = os_exc.SDKException
self.assertRaises(os_exc.SDKException, cls.request_vifs,
m_driver, pod, project_id, subnets,
security_groups, num_ports)
m_driver._get_port_request.assert_called_once_with(
pod, project_id, subnets, security_groups, unbound=True)
os_net.create_ports.assert_called_once_with(bulk_rq)
m_to_vif.assert_not_called()
示例8: test_add_subnet_to_router_exception
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def test_add_subnet_to_router_exception(self):
cls = subnet_drv.NamespacePodSubnetDriver
m_driver = mock.MagicMock(spec=cls)
subnet_id = mock.sentinel.subnet_id
os_net = self.useFixture(k_fix.MockNetworkClient()).client
os_net.add_interface_to_router.side_effect = (
os_exc.SDKException)
router_id = 'router1'
oslo_cfg.CONF.set_override('pod_router',
router_id,
group='namespace_subnet')
self.assertRaises(os_exc.SDKException,
cls.add_subnet_to_router, m_driver, subnet_id)
os_net.add_interface_to_router.assert_called_once()
示例9: test_release_parent_not_found
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def test_release_parent_not_found(self):
cls = nested_dpdk_vif.NestedDpdkPodVIFDriver
m_driver = mock.Mock(spec=cls)
compute = self.useFixture(k_fix.MockComputeClient()).client
pod = mock.sentinel.pod
vif = mock.Mock()
vif.id = mock.sentinel.vif_id
vm_id = mock.sentinel.parent_port_id
parent_port = mock.MagicMock()
parent_port.__getitem__.return_value = vm_id
m_driver._get_parent_port.side_effect = \
o_exc.SDKException
self.assertRaises(o_exc.SDKException, cls.release_vif,
m_driver, pod, vif)
m_driver._get_parent_port.assert_called_once_with(pod)
compute.delete_server_interface.assert_not_called()
示例10: test_release_detach_failed
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def test_release_detach_failed(self):
cls = nested_dpdk_vif.NestedDpdkPodVIFDriver
m_driver = mock.Mock(spec=cls)
compute = self.useFixture(k_fix.MockComputeClient()).client
pod = mock.sentinel.pod
vif = mock.Mock()
vif.id = mock.sentinel.vif_id
vm_id = mock.sentinel.parent_port_id
parent_port = mock.MagicMock()
parent_port.device_id = vm_id
compute.delete_server_interface.side_effect = o_exc.SDKException
m_driver._get_parent_port.return_value = parent_port
self.assertRaises(o_exc.SDKException, cls.release_vif,
m_driver, pod, vif)
m_driver._get_parent_port.assert_called_once_with(pod)
compute.delete_server_interface.assert_called_once_with(
vif.id, server=vm_id)
示例11: test_associate_lb_fip_id_not_exist_neutron_exception
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def test_associate_lb_fip_id_not_exist_neutron_exception(self):
cls = d_lb_public_ip.FloatingIpServicePubIPDriver
m_driver = mock.Mock(spec=cls)
m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
os_net = self.useFixture(k_fix.MockNetworkClient()).client
os_net.update_ip.side_effect = os_exc.SDKException
fip = munch.Munch({'floating_ip_address': '1.2.3.5',
'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'})
service_pub_ip_info = (obj_lbaas
.LBaaSPubIp(ip_id=fip.id,
ip_addr=fip.floating_ip_address,
alloc_method='pool'))
vip_port_id = 'ec29d641-fec4-4f67-928a-124a76b3a777'
self.assertRaises(os_exc.SDKException, cls.associate_pub_ip,
m_driver, service_pub_ip_info, vip_port_id)
示例12: restore
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def restore(self, session, volume_id=None, name=None):
"""Restore current backup to volume
:param session: openstack session
:param volume_id: The ID of the volume to restore the backup to.
:param name: The name for new volume creation to restore.
:return: Updated backup instance
"""
url = utils.urljoin(self.base_path, self.id, "restore")
body = {'restore': {}}
if volume_id:
body['restore']['volume_id'] = volume_id
if name:
body['restore']['name'] = name
if not (volume_id or name):
raise exceptions.SDKException('Either of `name` or `volume_id`'
' must be specified.')
response = session.post(url,
json=body)
self._translate_response(response, has_body=False)
return self
示例13: delete_backup
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def delete_backup(self, backup, ignore_missing=True):
"""Delete a CloudBackup
:param backup: The value can be the ID of a backup or a
:class:`~openstack.block_storage.v2.backup.Backup` instance
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be raised when
the zone does not exist.
When set to ``True``, no exception will be set when attempting to
delete a nonexistent zone.
:returns: ``None``
"""
if not self._connection.has_service('object-store'):
raise exceptions.SDKException(
'Object-store service is required for block-store backups'
)
self._delete(_backup.Backup, backup,
ignore_missing=ignore_missing)
示例14: restore_backup
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def restore_backup(self, backup, volume_id, name):
"""Restore a Backup to volume
:param backup: The value can be the ID of a backup or a
:class:`~openstack.block_storage.v2.backup.Backup` instance
:param volume_id: The ID of the volume to restore the backup to.
:param name: The name for new volume creation to restore.
:returns: Updated backup instance
:rtype: :class:`~openstack.block_storage.v2.backup.Backup`
"""
if not self._connection.has_service('object-store'):
raise exceptions.SDKException(
'Object-store service is required for block-store backups'
)
backup = self._get_resource(_backup.Backup, backup)
return backup.restore(self, volume_id=volume_id, name=name)
示例15: delete_backup
# 需要导入模块: from openstack import exceptions [as 别名]
# 或者: from openstack.exceptions import SDKException [as 别名]
def delete_backup(self, backup, ignore_missing=True):
"""Delete a CloudBackup
:param backup: The value can be the ID of a backup or a
:class:`~openstack.block_storage.v3.backup.Backup` instance
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be raised when
the zone does not exist.
When set to ``True``, no exception will be set when attempting to
delete a nonexistent zone.
:returns: ``None``
"""
if not self._connection.has_service('object-store'):
raise exceptions.SDKException(
'Object-store service is required for block-store backups'
)
self._delete(_backup.Backup, backup,
ignore_missing=ignore_missing)