def create_router(self, router): _('... Creating router') router.cloud_router = self._neutron.create_router( router.name, router.ext_network.cloud_network['id'] if router.ext_network else None) self.routers_cache[router.cloud_router['id']] = router.cloud_router __() return router
def ports(self, network=None, device_id=None, device_name=None, compute_only=False, override_cache=False): external = network['router:external'] if network else False if compute_only and external: return list() if not override_cache and device_id in self.ports_cache: if network: ports = self.filter_ports_by_network(self.ports_cache[device_id], network_id=network['id']) else: ports = self.ports_cache[device_id] else: if device_id: device_info = ' (' + device_name + ')' if device_name else '' _('... Retrieving device ports' + device_info) ports = self._neutron.ports(device_id=device_id) __() self.ports_cache[device_id] = ports if network: ports = self.filter_ports_by_network(ports, network['id']) else: _('... Retrieving network ports') ports = self._neutron.ports(network_id=network['id'] if network else None) __() # TODO to be made more performant, move logic up if compute_only: compute_ports = list() for port in ports: if 'compute' in str(port['device_owner']): compute_ports.append(port) return compute_ports else: return ports
def get_cloud_driver_context(self, cloud_manager): if cloud_manager: if cloud_manager.name not in self.driver_contexts: if cloud_manager.type.lower() == "openstack": _("... Building context") context = OSDriverContext(OSClient(cloud_manager.path, cloud_manager.username, cloud_manager.tenant, cloud_manager.password)) __() elif cloud_manager.type.lower() == "stub": context = StubDriverContext() else: error('%s type of CLOUD MANAGER IS UNKNOWN!', cloud_manager.type) raise IntegrityException if context.authenticated(): self.driver_contexts[cloud_manager.name] = context self.cloud_manager.set_authenticated(cloud_manager.name) else: self.driver_contexts[cloud_manager.name] = None self.cloud_manager.set_authenticated(cloud_manager.name, False) output() warn('Cloud manager %s failed authentication.', cloud_manager.name) return self.driver_contexts[cloud_manager.name] else: error('No driver found for None cloud manager') raise IntegrityException
def flavor(self, cloud_flavor=None): _('... Retrieving flavor') flavor = self._nova.flavors(cloud_flavor['id']) __() if len(flavor) > 0: return flavor[0] else: error('Flavor %s not found!', cloud_flavor) return None
def image(self, cloud_image=None): _('... Retrieving image') image = self._nova.images(cloud_image['id']) __() if len(image) > 0: return image[0] else: error('Image %s not found!', cloud_image) error('All retrieved images are: %s', self.images()) return None
def routers(self, name=None, info=None, override_cache=False): if self.routers_cache is None or override_cache: _('... Retrieving router' + ((' ' + name) if name else (('s (' + info + ")") if info else 's'))) self.routers_cache = dict() for cloud_router in self._neutron.routers(): self.routers_cache[cloud_router['id']] = cloud_router __() return self.routers_cache.values() elif name: return self._neutron.routers(name) else: return self._neutron.routers()
def __init__(self, auth_url, username, tenant_name, password): _('... Authenticating') me = OSCredentials(auth_url, username, tenant_name, password) self.keystone = Keystone(me) __() self.authenticated = self.keystone.authentication_success if self.authenticated: self.neutron = Neutron(me) self.nova = Nova(me)
def boot(self, instance): sg_names = None if instance.cloud_sg: sg_names = list() sg_names.append(instance.cloud_sg) _('... Booting instance') instance.cloud_instance = self._nova.boot( instance.name, instance.cloud_image, instance.cloud_flavor, sg_names, instance.cloud_network['id'], {'cluster': instance.cluster_name} if instance.cluster_name else None) __() self.set_instance_runtime_data(instance) return instance.cloud_instance
def detach_from_router(self, subnet, router): if router is None: error('detach_to_router: there is no router') raise IntegrityException if subnet is None: error('detach_to_router: there is no subnet') raise IntegrityException _('... Detaching from router') self._neutron.remove_router_interface(router['id'], subnet['id']) # invalidate the port cache if router['id'] in self.ports_cache: del self.ports_cache[router['id']] __()
def delete_nova_sg(self, nova_sg): _('... Deleting nova sg') nova_sg = self._nova.delete_sg(nova_sg.cloud_sg) __() return nova_sg
def create_nova_sg(self, nova_sg): _('... Creating nova sg') nova_sg = self._nova.create_sg(nova_sg.name, nova_sg.description) __() return nova_sg
def nova_sgs(self, name=None): _('... Retrieving nova sg\'s') nova_sgs = self._nova.security_groups(name=name) __() return nova_sgs
def images(self, name=None): _('... Retrieving images') images = self._nova.images(name=name) __() return images
def kill(self, instance): _('... Killing instance') self._nova.delete(instance.cloud_instance) __()
def networks(self, name=None): _("... Retrieving network" + ((" " + name) if name else "s")) networks = self._neutron.networks(name) __() return networks
def associate_floating_ip(self, fip, port=None): _('... Associating floating ip') self._neutron.associate_floating_ip(fip, port['id']) __()
def allocate_floating_ip(self, network, port=None): _('... Allocating floating ip') fip = self._neutron.allocate_floating_ip(network['id'], port['id'])['floating_ip_address'] __() return fip
def uplink_router(self, router, ext_network): _('... Uplinking router') self._neutron.uplink_router(router.cloud_router['id'], ext_network.cloud_network['id']) self.routers_cache[router.cloud_router['id']] = router.cloud_router __()
def instances(self, name=None): _('... Retrieving instance' + ((' ' + name) if name else 's')) instances = self._nova.servers(name=name) __() return instances
def create_subnet(self, network): _('... Creating subnet') network.cloud_subnet = self._neutron.create_subnet(network.cloud_network['id'], network.cidr) __() return network
def create_network(self, network): _("... Creating network") network.cloud_network = self._neutron.create_network(network.name, network.external) __() return network
def subnets(self, cloud_network=None): _('... Retrieving subnet' + ((' for network ' + cloud_network['name']) if cloud_network else 's')) subnets = self._neutron.subnets(cloud_network['id']) __() return subnets
def create_nova_sg_rule(self, nova_sg_rule): _('... Creating nova sg rule') nova_sg = self._nova.create_sg_rule(nova_sg_rule) __() return nova_sg
def flavors(self, name=None): _('... Retrieving flavors') flavors = self._nova.flavors(name=name) __() return flavors
def unlink_router(self, router): _('... Unlinking router') self._neutron.unlink_router(router.cloud_router['id']) self.routers_cache[router.cloud_router['id']] = router.cloud_router __()