本文整理汇总了Python中shade.openstack_cloud函数的典型用法代码示例。如果您正苦于以下问题:Python openstack_cloud函数的具体用法?Python openstack_cloud怎么用?Python openstack_cloud使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openstack_cloud函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: initialize_cloud
def initialize_cloud(cloud_name):
"""Initialize cloud object.
Cloud configs are read with os-client-config.
:param cloud_name: the cloud name
"""
if not cloud_name:
return shade.openstack_cloud()
else:
return shade.openstack_cloud(cloud=cloud_name)
开发者ID:sileht,项目名称:shade_janitor,代码行数:12,代码来源:janitor.py
示例2: main
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--max_routers', type=int, default=100)
args = parser.parse_args()
agent_status = STATE_OK
search_opts = {
'all_tenants': True,
}
cloud = shade.openstack_cloud()
neutron = cloud.neutron_client
router_list = neutron.list_routers()
if len(router_list['routers']) > args.max_routers:
print("WARNING: Number of routers more than the max: %d"
% args.max_routers)
sys.exit(STATE_WARNING)
for router in router_list['routers']:
search_opts['router'] = router['id']
router_agents = neutron.list_l3_agent_hosting_routers(**search_opts)
agent_status = check_router(router, router_agents)
if agent_status == STATE_CRITICAL:
sys.exit(STATE_CRITICAL)
elif agent_status == STATE_WARNING:
sys.exit(STATE_WARNING)
if agent_status == STATE_OK:
print("OK: No routers with multiple active or all inactive l3 agents")
sys.exit(STATE_OK)
开发者ID:ddaskal,项目名称:ursula-monitoring,代码行数:31,代码来源:check-neutron-l3-routers.py
示例3: __init__
def __init__(self, molecule):
super(OpenstackDriver, self).__init__(molecule)
self._provider = self._get_provider()
self._platform = self._get_platform()
self._openstack = shade.openstack_cloud()
self._keypair_name = self.get_keypair_name()
self._molecule_generated_ssh_key = False
开发者ID:russ216,项目名称:molecule,代码行数:7,代码来源:openstackdriver.py
示例4: main
def main():
''' Main module function '''
module = AnsibleModule(argument_spec={}, supports_check_mode=True)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
try:
cloud = shade.openstack_cloud()
# pylint: disable=broad-except
except Exception:
module.fail_json(msg='Failed to connect to the cloud')
try:
service_catalog = cloud.cloud_config.get_service_catalog()
# pylint: disable=broad-except
except Exception:
module.fail_json(msg='Failed to retrieve the service catalog')
try:
endpoints = service_catalog.get_endpoints()
# pylint: disable=broad-except
except Exception:
module.fail_json(msg='Failed to retrieve the service catalog '
'endpoints')
module.exit_json(
changed=False,
ansible_facts={'openstack_service_catalog': endpoints})
开发者ID:Mangirdaz,项目名称:openshift-ansible,代码行数:29,代码来源:os_service_catalog.py
示例5: setUp
def setUp(self):
super(TestImage, self).setUp()
self.cloud = shade.openstack_cloud(validate=False)
self.image_id = str(uuid.uuid4())
self.fake_search_return = [{
u'image_state': u'available',
u'container_format': u'bare',
u'min_ram': 0,
u'ramdisk_id': None,
u'updated_at': u'2016-02-10T05:05:02Z',
u'file': '/v2/images/' + self.image_id + '/file',
u'size': 3402170368,
u'image_type': u'snapshot',
u'disk_format': u'qcow2',
u'id': self.image_id,
u'schema': u'/v2/schemas/image',
u'status': u'active',
u'tags': [],
u'visibility': u'private',
u'locations': [{
u'url': u'http://127.0.0.1/images/' + self.image_id,
u'metadata': {}}],
u'min_disk': 40,
u'virtual_size': None,
u'name': u'fake_image',
u'checksum': u'ee36e35a297980dee1b514de9803ec6d',
u'created_at': u'2016-02-10T05:03:11Z',
u'protected': False}]
self.output = six.BytesIO()
self.output.write(uuid.uuid4().bytes)
self.output.seek(0)
开发者ID:erickcantwell,项目名称:shade,代码行数:31,代码来源:test_image.py
示例6: _getClient
def _getClient(self):
kwargs = {}
if self.provider.region_name:
kwargs['region_name'] = self.provider.region_name
if self.provider.api_timeout:
kwargs['api_timeout'] = self.provider.api_timeout
# These are named from back when we only talked to Nova. They're
# actually compute service related
if self.provider.service_type:
kwargs['compute_service_type'] = self.provider.service_type
if self.provider.service_name:
kwargs['compute_service_name'] = self.provider.service_name
if self.provider.cloud is not None:
kwargs['cloud'] = self.provider.cloud
auth_kwargs = {}
for auth_attr in ('username', 'password', 'auth_url'):
auth_val = getattr(self.provider, auth_attr)
if auth_val is not None:
auth_kwargs[auth_attr] = auth_val
if self.provider.project_id is not None:
auth_kwargs['project_name'] = self.provider.project_id
kwargs['auth'] = auth_kwargs
return shade.openstack_cloud(**kwargs)
开发者ID:jianghuaw,项目名称:nodepool,代码行数:26,代码来源:provider_manager.py
示例7: _get_cloud
def _get_cloud(cloud, region, project=None):
if project:
domain_id = project.domain_id
domain_name = project.domain_name
project_id = project.id
project_name = project.name
kwargs = dict(
project_domain_id=domain_id,
project_domain_name=domain_name,
project_id=project_id,
project_name=project_name,
)
else:
domain_id = domain_name = project_id = project_name = None
kwargs = {}
key = _make_cloud_key(
cloud, region,
domain_id or domain_name,
project_id or project_name
)
if key not in all_clouds:
all_clouds[key] = shade.openstack_cloud(
cloud=cloud, region_name=region,
debug=True, strict=True, **kwargs)
return all_clouds[key]
开发者ID:emonty,项目名称:oaktree,代码行数:26,代码来源:_clouds.py
示例8: main
def main():
argument_spec = openstack_full_argument_spec(
display_name=dict(required=True, aliases=['name']),
display_description=dict(default=None, aliases=['description']),
volume=dict(required=True),
force=dict(required=False, default=False, type='bool'),
state=dict(default='present', choices=['absent', 'present']),
)
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec,
supports_check_mode=True,
**module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
state = module.params['state']
try:
cloud = shade.openstack_cloud(**module.params)
if cloud.volume_exists(module.params['volume']):
if module.check_mode:
module.exit_json(changed=_system_state_change(module, cloud))
if state == 'present':
_present_volume_snapshot(module, cloud)
if state == 'absent':
_absent_volume_snapshot(module, cloud)
else:
module.fail_json(
msg="No volume with name or id '{0}' was found.".format(
module.params['volume']))
except (shade.OpenStackCloudException, shade.OpenStackCloudTimeout) as e:
module.fail_json(msg=e.message)
开发者ID:awiddersheim,项目名称:ansible,代码行数:34,代码来源:os_volume_snapshot.py
示例9: main
def main():
''' Main module function '''
module = AnsibleModule(
argument_spec=dict(
trunk_name=dict(default=False, type='str'),
),
supports_check_mode=True,
)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
try:
cloud = shade.openstack_cloud()
# pylint: disable=broad-except
except Exception:
module.fail_json(msg='Failed to connect to the cloud')
try:
adapter = keystoneauth1.adapter.Adapter(
session=cloud.keystone_session,
service_type=cloud.cloud_config.get_service_type('network'),
interface=cloud.cloud_config.get_interface('network'),
endpoint_override=cloud.cloud_config.get_endpoint('network'),
version=cloud.cloud_config.get_api_version('network'))
# pylint: disable=broad-except
except Exception:
module.fail_json(msg='Failed to get an adapter to talk to the Neutron '
'API')
try:
trunk_response = adapter.get('/trunks')
# pylint: disable=broad-except
except Exception:
module.fail_json(msg='Failed to retrieve Neutron trunk information')
subports = []
for trunk in trunk_response.json()['trunks']:
if trunk['name'] == module.params['trunk_name']:
trunk_id = trunk['id']
for subport in trunk['sub_ports']:
subports.append(subport['port_id'])
data = _get_data(subports)
try:
adapter.put('/trunks/' + trunk_id + '/remove_subports',
**data)
# pylint: disable=broad-except
except Exception:
module.fail_json(msg='Failed to detach subports')
try:
for port in subports:
adapter.delete('/ports/' + port)
# pylint: disable=broad-except
except Exception:
module.fail_json(msg='Failed to delete Neutron subports')
module.exit_json(
changed=True)
开发者ID:Mangirdaz,项目名称:openshift-ansible,代码行数:60,代码来源:os_subports_deletion.py
示例10: main
def main():
argument_spec = openstack_full_argument_spec(
size=dict(default=None),
volume_type=dict(default=None),
display_name=dict(required=True, aliases=['name']),
display_description=dict(default=None, aliases=['description']),
image=dict(default=None),
snapshot_id=dict(default=None),
state=dict(default='present', choices=['absent', 'present']),
)
module_kwargs = openstack_module_kwargs(
mutually_exclusive=[
['image', 'snapshot_id'],
],
)
module = AnsibleModule(argument_spec=argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
state = module.params['state']
if state == 'present' and not module.params['size']:
module.fail_json(msg="Size is required when state is 'present'")
try:
cloud = shade.openstack_cloud(**module.params)
if state == 'present':
_present_volume(module, cloud)
if state == 'absent':
_absent_volume(module, cloud)
except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e))
开发者ID:alextricity25,项目名称:setup-infra,代码行数:33,代码来源:os_volume.py
示例11: main
def main():
argument_spec = openstack_full_argument_spec(
name=dict(required=True),
description=dict(required=False, default=None),
domain_id=dict(required=False, default=None, aliases=['domain']),
enabled=dict(default=True, type='bool'),
state=dict(default='present', choices=['absent', 'present'])
)
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(
argument_spec,
supports_check_mode=True,
**module_kwargs
)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
name = module.params['name']
description = module.params['description']
domain = module.params['domain_id']
enabled = module.params['enabled']
state = module.params['state']
try:
cloud = shade.openstack_cloud(**module.params)
project = cloud.get_project(name)
if module.check_mode:
module.exit_json(changed=_system_state_change(module, project))
if state == 'present':
if project is None:
project = cloud.create_project(
name=name, description=description,
domain_id=domain,
enabled=enabled)
changed = True
else:
if _needs_update(module, project):
project = cloud.update_project(
project['id'], description=description,
enabled=enabled)
changed = True
else:
changed = False
module.exit_json(changed=changed, project=project)
elif state == 'absent':
if project is None:
changed=False
else:
cloud.delete_project(project['id'])
changed=True
module.exit_json(changed=changed)
except shade.OpenStackCloudException as e:
module.fail_json(msg=e.message, extra_data=e.extra_data)
开发者ID:RajeevNambiar,项目名称:temp,代码行数:60,代码来源:os_project.py
示例12: main
def main():
argument_spec = openstack_full_argument_spec(
security_group=dict(required=False),
filters=dict(required=False, type='dict', default=None),
)
# module_kwargs = openstack_module_kwargs()
# module = AnsibleModule(argument_spec, **module_kwargs)
module = AnsibleModule(argument_spec)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
# security_group =module.params.pop('security_group')
# filters = module.params.pop('filters')
try:
cloud = shade.openstack_cloud(**module.params)
openstack_security_groups = cloud.list_security_groups()
module.exit_json(changed=False, ansible_facts=dict(
openstack_security_groups=openstack_security_groups))
except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e))
开发者ID:jeanlouisferey,项目名称:openstack-securitygroup-grapher,代码行数:27,代码来源:os_security_groups_facts.py
示例13: main
def main():
argument_spec = openstack_full_argument_spec(
server=dict(required=False),
detailed=dict(required=False, type='bool'),
)
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
try:
cloud = shade.openstack_cloud(**module.params)
openstack_servers = cloud.list_servers(
detailed=module.params['detailed'])
if module.params['server']:
# filter servers by name
pattern = module.params['server']
openstack_servers = [server for server in openstack_servers
if fnmatch.fnmatch(server['name'], pattern)]
module.exit_json(changed=False, ansible_facts=dict(
openstack_servers=openstack_servers))
except shade.OpenStackCloudException as e:
module.fail_json(msg=e.message)
开发者ID:RajeevNambiar,项目名称:temp,代码行数:27,代码来源:os_server_facts.py
示例14: setUp
def setUp(self):
super(TestNetwork, self).setUp()
self.cloud = openstack_cloud(cloud='devstack-admin')
if not self.cloud.has_service('network'):
self.skipTest('Network service not supported by cloud')
self.network_name = self.getUniqueString('network')
self.addCleanup(self._cleanup_networks)
开发者ID:erickcantwell,项目名称:shade,代码行数:7,代码来源:test_network.py
示例15: main
def main():
argument_spec = openstack_full_argument_spec(
server=dict(required=True),
state=dict(default='present', choices=['absent', 'present']),
network=dict(required=False, default=None),
floating_ip_address=dict(required=False, default=None),
reuse=dict(required=False, type='bool', default=False),
fixed_address=dict(required=False, default=None),
wait=dict(required=False, type='bool', default=False),
timeout=dict(required=False, type='int', default=60),
)
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
server_name_or_id = module.params['server']
state = module.params['state']
network = module.params['network']
floating_ip_address = module.params['floating_ip_address']
reuse = module.params['reuse']
fixed_address = module.params['fixed_address']
wait = module.params['wait']
timeout = module.params['timeout']
cloud = shade.openstack_cloud(**module.params)
try:
server = cloud.get_server(server_name_or_id)
if server is None:
module.fail_json(
msg="server {0} not found".format(server_name_or_id))
if state == 'present':
server = cloud.add_ips_to_server(
server=server, ips=floating_ip_address, ip_pool=network,
reuse=reuse, fixed_address=fixed_address, wait=wait,
timeout=timeout)
fip_address = cloud.get_server_public_ip(server)
# Update the floating IP status
f_ip = _get_floating_ip(cloud, fip_address)
module.exit_json(changed=True, floating_ip=f_ip)
elif state == 'absent':
if floating_ip_address is None:
module.fail_json(msg="floating_ip_address is required")
f_ip = _get_floating_ip(cloud, floating_ip_address)
cloud.detach_ip_from_server(
server_id=server['id'], floating_ip_id=f_ip['id'])
# Update the floating IP status
f_ip = cloud.get_floating_ip(id=f_ip['id'])
module.exit_json(changed=True, floating_ip=f_ip)
except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e), extra_data=e.extra_data)
开发者ID:matthewbga,项目名称:blargotron,代码行数:59,代码来源:os_floating_ip.py
示例16: main
def main():
argument_spec = openstack_full_argument_spec(
name = dict(required=True),
public_key = dict(default=None),
public_key_file = dict(default=None),
state = dict(default='present',
choices=['absent', 'present']),
)
module_kwargs = openstack_module_kwargs(
mutually_exclusive=[['public_key', 'public_key_file']])
module = AnsibleModule(argument_spec,
supports_check_mode=True,
**module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
state = module.params['state']
name = module.params['name']
public_key = module.params['public_key']
if module.params['public_key_file']:
public_key = open(module.params['public_key_file']).read()
public_key = public_key.rstrip()
try:
cloud = shade.openstack_cloud(**module.params)
keypair = cloud.get_keypair(name)
if module.check_mode:
module.exit_json(changed=_system_state_change(module, keypair))
if state == 'present':
if keypair and keypair['name'] == name:
if public_key and (public_key != keypair['public_key']):
module.fail_json(
msg="Key name %s present but key hash not the same"
" as offered. Delete key first." % name
)
else:
changed = False
else:
keypair = cloud.create_keypair(name, public_key)
changed = True
module.exit_json(changed=changed,
key=keypair,
id=keypair['id'])
elif state == 'absent':
if keypair:
cloud.delete_keypair(name)
module.exit_json(changed=True)
module.exit_json(changed=False)
except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e))
开发者ID:ernstp,项目名称:ansible,代码行数:59,代码来源:os_keypair.py
示例17: get_cloud
def get_cloud(self):
""" Get shade openstack and operator cloud objects
:return: cloud, opcloud are the shade openstack and operator objects
"""
cloud = shade.openstack_cloud()
opcloud = shade.operator_cloud()
return cloud, opcloud
开发者ID:LIP-Computing,项目名称:openstack-nagios-plugins,代码行数:8,代码来源:openstacknagios.py
示例18: setUp
def setUp(self):
super(TestNetwork, self).setUp()
self.cloud = openstack_cloud(cloud='devstack-admin')
if not self.cloud.has_service('network'):
self.skipTest('Network service not supported by cloud')
self.network_prefix = 'test_network' + ''.join(
random.choice(string.ascii_lowercase) for _ in range(5))
self.addCleanup(self._cleanup_networks)
开发者ID:ruizink,项目名称:shade,代码行数:8,代码来源:test_network.py
示例19: test_get_server_external_ipv4_neutron_accessIPv4
def test_get_server_external_ipv4_neutron_accessIPv4(self):
srv = meta.obj_to_dict(fakes.FakeServer(
id='test-id', name='test-name', status='ACTIVE',
accessIPv4=PUBLIC_V4))
ip = meta.get_server_external_ipv4(
cloud=shade.openstack_cloud(validate=False), server=srv)
self.assertEqual(PUBLIC_V4, ip)
开发者ID:insequent,项目名称:shade,代码行数:8,代码来源:test_meta.py
示例20: build_inventory
def build_inventory():
'''Build the dynamic inventory.'''
cloud = shade.openstack_cloud()
# TODO(shadower): filter the servers based on the `OPENSHIFT_CLUSTER`
# environment variable.
cluster_hosts = [
server for server in cloud.list_servers()
if 'metadata' in server and 'clusterid' in server.metadata]
inventory = base_openshift_inventory(cluster_hosts)
inventory['_meta'] = {'hostvars': {}}
# Some clouds don't have Cinder. That's okay:
try:
volumes = cloud.list_volumes()
except EndpointNotFound:
volumes = []
# cinder volumes used for docker storage
docker_storage_mountpoints = get_docker_storage_mountpoints(volumes)
for server in cluster_hosts:
inventory['_meta']['hostvars'][server.name] = _get_hostvars(
server,
docker_storage_mountpoints)
stout = _get_stack_outputs(cloud)
if stout is not None:
try:
inventory['localhost'].update({
'openshift_openstack_api_lb_provider':
stout['api_lb_provider'],
'openshift_openstack_api_lb_port_id':
stout['api_lb_vip_port_id'],
'openshift_openstack_api_lb_sg_id':
stout['api_lb_sg_id']})
except KeyError:
pass # Not an API load balanced deployment
try:
inventory['OSEv3']['vars'][
'openshift_master_cluster_hostname'] = stout['private_api_ip']
except KeyError:
pass # Internal LB not specified
inventory['localhost']['openshift_openstack_private_api_ip'] = \
stout.get('private_api_ip')
inventory['localhost']['openshift_openstack_public_api_ip'] = \
stout.get('public_api_ip')
inventory['localhost']['openshift_openstack_public_router_ip'] = \
stout.get('public_router_ip')
try:
inventory['OSEv3']['vars'] = _get_kuryr_vars(cloud, stout)
except KeyError:
pass # Not a kuryr deployment
return inventory
开发者ID:Mangirdaz,项目名称:openshift-ansible,代码行数:58,代码来源:inventory.py
注:本文中的shade.openstack_cloud函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论