Beispiel #1
0
def _get_quantum_client(token):
    if token:
        my_client = q_clientv2.Client(endpoint_url=CONF.quantum_url,
                                      token=token,
                                      timeout=CONF.quantum_url_timeout)
    else:
        my_client = q_clientv2.Client(endpoint_url=CONF.quantum_url,
                                      auth_strategy=None,
                                      timeout=CONF.quantum_url_timeout)
    return my_client
Beispiel #2
0
def get_client(context):
    token = context.auth_token
    if not token:
        if FLAGS.quantum_auth_strategy:
            token = _get_auth_token()
    if token:
        my_client = clientv20.Client(endpoint_url=FLAGS.quantum_url,
                                     token=token,
                                     timeout=FLAGS.quantum_url_timeout)
    else:
        my_client = clientv20.Client(endpoint_url=FLAGS.quantum_url,
                                     auth_strategy=None,
                                     timeout=FLAGS.quantum_url_timeout)
    return my_client
Beispiel #3
0
    def __init__(self, conf):
        self.conf = conf
        self.router_info = {}

        if not conf.interface_driver:
            LOG.error(_('You must specify an interface driver'))
            sys.exit(1)
        try:
            self.driver = importutils.import_object(conf.interface_driver,
                                                    conf)
        except:
            LOG.exception(
                _("Error importing interface driver '%s'" %
                  conf.interface_driver))
            sys.exit(1)

        self.polling_interval = conf.polling_interval

        if not ip_lib.device_exists(self.conf.external_network_bridge):
            raise Exception("external network bridge '%s' does not exist" %
                            self.conf.external_network_bridge)

        self.qclient = client.Client(username=self.conf.admin_user,
                                     password=self.conf.admin_password,
                                     tenant_name=self.conf.admin_tenant_name,
                                     auth_url=self.conf.auth_url,
                                     auth_strategy=self.conf.auth_strategy,
                                     auth_region=self.conf.auth_region)

        self._destroy_all_router_namespaces()
Beispiel #4
0
def get_client():
	try: 
		os_client=nec.Client(username=cr._OS_USERNAME, password=cr._OS_PASSWORD, tenant_name=cr._OS_TENANT_NAME, auth_url=cr._OS_AUTH_URL)
		return os_client
	except Exception as e:
		log.error( str(type(e)) + str(e.args) + e.message )
		return None
Beispiel #5
0
    def __init__(self, conf):
        self.conf = conf
        self.router_info = {}

        if not conf.interface_driver:
            LOG.error(_('You must specify an interface driver'))
            sys.exit(1)
        try:
            self.driver = importutils.import_object(conf.interface_driver,
                                                    conf)
        except:
            LOG.exception(_("Error importing interface driver '%s'"),
                          conf.interface_driver)
            sys.exit(1)

        self.polling_interval = conf.polling_interval

        self.qclient = client.Client(
            username=self.conf.admin_user,
            password=self.conf.admin_password,
            tenant_name=self.conf.admin_tenant_name,
            auth_url=self.conf.auth_url,
            auth_strategy=self.conf.auth_strategy,
            region_name=self.conf.auth_region
        )

        if self.conf.use_namespaces:
            self._destroy_all_router_namespaces()
Beispiel #6
0
def _get_client(token=None):
    global cached_admin_client

    should_cache = False
    params = {
        'endpoint_url': CONF.quantum_url,
        'timeout': CONF.quantum_url_timeout,
        'insecure': CONF.quantum_api_insecure,
    }
    if token:
        params['token'] = token
    else:
        if CONF.quantum_auth_strategy:
            should_cache = True
            _fill_admin_details(params)
        else:
            params['auth_strategy'] = None

    new_client = client.Client(**params)
    if should_cache:
        # in this case, we don't have the token yet
        try:
            new_client.httpclient.authenticate()
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.exception(_("quantum authentication failed"))

        cached_admin_client = new_client
    return new_client
Beispiel #7
0
    def quantum(self):
        if quantumclient is None:
            return None
        if self._quantum:
            logger.debug('using existing _quantum')
            return self._quantum

        con = self.context
        args = {
            'auth_url': con.auth_url,
            'service_type': 'network',
        }

        if con.password is not None:
            args['username'] = con.username
            args['password'] = con.password
            args['tenant_name'] = con.tenant
        elif con.auth_token is not None:
            args['token'] = con.auth_token
            args['endpoint_url'] = self.url_for(service_type='network')
        else:
            logger.error("Quantum connection failed, "
                         "no password or auth_token!")
            return None
        logger.debug('quantum args %s', args)

        self._quantum = quantumclient.Client(**args)

        return self._quantum
def get_quantum_client():
    nc = quantumClient.Client(username=OS_USERNAME,
                              tenant_name=OS_TENANT_NAME,
                              password=OS_PASSWORD,
                              auth_url=OS_AUTH_URL,
                              service_type="compute",
                              no_cache=True)
    return nc
Beispiel #9
0
def quantumclient(request):
    LOG.debug('quantumclient connection created using token "%s" and url "%s"'
              % (request.user.token.id, url_for(request, 'network')))
    LOG.debug('user_id=%(user)s, tenant_id=%(tenant)s' %
              {'user': request.user.id, 'tenant': request.user.tenant_id})
    c = quantum_client.Client(token=request.user.token.id,
                              endpoint_url=url_for(request, 'network'))
    return c
Beispiel #10
0
    def __init__(self, conf):
        self.conf = conf

        self.qclient = client.Client(username=self.conf.admin_user,
                                     password=self.conf.admin_password,
                                     tenant_name=self.conf.admin_tenant_name,
                                     auth_url=self.conf.auth_url,
                                     auth_strategy=self.conf.auth_strategy,
                                     region_name=self.conf.auth_region)
 def __init__(self, configfile=None):
     db.configure_db()
     self.quantum = client.Client(
         username=cfg.CONF.PROXY.admin_user,
         password=cfg.CONF.PROXY.admin_password,
         tenant_name=cfg.CONF.PROXY.admin_tenant_name,
         auth_url=cfg.CONF.PROXY.auth_url,
         auth_strategy=cfg.CONF.PROXY.auth_strategy,
         auth_region=cfg.CONF.PROXY.auth_region)
Beispiel #12
0
 def _get_quantum_client(self):
     qclient = client.Client(
         username=self.conf.admin_user,
         password=self.conf.admin_password,
         tenant_name=self.conf.admin_tenant_name,
         auth_url=self.conf.auth_url,
         auth_strategy=self.conf.auth_strategy,
         region_name=self.conf.auth_region,
     )
     return qclient
Beispiel #13
0
def _get_client(token=None):
    if not token and CONF.quantum_auth_strategy:
        token = _get_auth_token()
    params = {
        'endpoint_url': CONF.quantum_url,
        'timeout': CONF.quantum_url_timeout,
    }
    if token:
        params['token'] = token
    else:
        params['auth_strategy'] = None
    return clientv20.Client(**params)
Beispiel #14
0
 def _get_quantum_client(self):
     qclient = client.Client(
         username=self.conf.admin_user,
         password=self.conf.admin_password,
         tenant_name=self.conf.admin_tenant_name,
         auth_url=self.conf.auth_url,
         auth_strategy=self.conf.auth_strategy,
         region_name=self.conf.auth_region,
         auth_token=self.auth_info.get('auth_token'),
         endpoint_url=self.auth_info.get('endpoint_url'),
         endpoint_type=self.conf.endpoint_type)
     return qclient
Beispiel #15
0
def quantumclient(request):
    insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
    LOG.debug(
        'quantumclient connection created using token "%s" and url "%s"' %
        (request.user.token.id, url_for(request, 'network')))
    LOG.debug('user_id=%(user)s, tenant_id=%(tenant)s' % {
        'user': request.user.id,
        'tenant': request.user.tenant_id
    })
    c = quantum_client.Client(token=request.user.token.id,
                              endpoint_url=url_for(request, 'network'),
                              insecure=insecure)
    return c
Beispiel #16
0
 def __init__(self, conf):
     super(MetaInterfaceDriver, self).__init__(conf)
     from quantumclient.v2_0 import client
     self.quantum = client.Client(username=self.conf.admin_user,
                                  password=self.conf.admin_password,
                                  tenant_name=self.conf.admin_tenant_name,
                                  auth_url=self.conf.auth_url,
                                  auth_strategy=self.conf.auth_strategy,
                                  auth_region=self.conf.auth_region)
     self.flavor_driver_map = {}
     for flavor, driver_name in [
             driver_set.split(':') for driver_set in
             self.conf.meta_flavor_driver_mappings.split(',')
     ]:
         self.flavor_driver_map[flavor] = self._load_driver(driver_name)
 def __init__(self, configfile=None):
     options = {"sql_connection": cfg.CONF.DATABASE.sql_connection}
     options.update({'base': models_v2.model_base.BASEV2})
     sql_max_retries = cfg.CONF.DATABASE.sql_max_retries
     options.update({"sql_max_retries": sql_max_retries})
     reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
     options.update({"reconnect_interval": reconnect_interval})
     db.configure_db(options)
     self.quantum = client.Client(
         username=cfg.CONF.PROXY.admin_user,
         password=cfg.CONF.PROXY.admin_password,
         tenant_name=cfg.CONF.PROXY.admin_tenant_name,
         auth_url=cfg.CONF.PROXY.auth_url,
         auth_strategy=cfg.CONF.PROXY.auth_strategy,
         auth_region=cfg.CONF.PROXY.auth_region)
Beispiel #18
0
    def get_quantum_client(self):
        env = self.get_env()
        if not env:
            LOG.info('Unable to re-assign resources at this time')
            return None

        try:
            from quantumclient.v2_0 import client
        except ImportError:
            # Try to import neutronclient instead for havana+
            from neutronclient.v2_0 import client

        auth_url = '%(auth_protocol)s://%(keystone_host)s:%(auth_port)s/v2.0' \
                   % env
        quantum = client.Client(username=env['service_username'],
                                password=env['service_password'],
                                tenant_name=env['service_tenant'],
                                auth_url=auth_url,
                                region_name=env['region'])
        return quantum
def reassign_agent_resources():
    ''' Use agent scheduler API to detect down agents and re-schedule '''
    env = NetworkServiceContext()()
    if not env:
        log('Unable to re-assign resources at this time')
        return
    try:
        from quantumclient.v2_0 import client
    except ImportError:
        ''' Try to import neutronclient instead for havana+ '''
        from neutronclient.v2_0 import client

    auth_url = '%(auth_protocol)s://%(keystone_host)s:%(auth_port)s/v2.0' % env
    quantum = client.Client(username=env['service_username'],
                            password=env['service_password'],
                            tenant_name=env['service_tenant'],
                            auth_url=auth_url,
                            region_name=env['region'])

    partner_gateways = [unit_private_ip().split('.')[0]]
    for partner_gateway in relations_of_type(reltype='cluster'):
        gateway_hostname = get_hostname(partner_gateway['private-address'])
        partner_gateways.append(gateway_hostname.partition('.')[0])

    agents = quantum.list_agents(agent_type=DHCP_AGENT)
    dhcp_agents = []
    l3_agents = []
    networks = {}
    for agent in agents['agents']:
        if not agent['alive']:
            log('DHCP Agent %s down' % agent['id'])
            for network in \
                    quantum.list_networks_on_dhcp_agent(
                        agent['id'])['networks']:
                networks[network['id']] = agent['id']
        else:
            if agent['host'].partition('.')[0] in partner_gateways:
                dhcp_agents.append(agent['id'])

    agents = quantum.list_agents(agent_type=L3_AGENT)
    routers = {}
    for agent in agents['agents']:
        if not agent['alive']:
            log('L3 Agent %s down' % agent['id'])
            for router in \
                    quantum.list_routers_on_l3_agent(
                        agent['id'])['routers']:
                routers[router['id']] = agent['id']
        else:
            if agent['host'].split('.')[0] in partner_gateways:
                l3_agents.append(agent['id'])

    if len(dhcp_agents) == 0 or len(l3_agents) == 0:
        log('Unable to relocate resources, there are %s dhcp_agents and %s \
             l3_agents in this cluster' % (len(dhcp_agents), len(l3_agents)))
        return

    index = 0
    for router_id in routers:
        agent = index % len(l3_agents)
        log('Moving router %s from %s to %s' %
            (router_id, routers[router_id], l3_agents[agent]))
        quantum.remove_router_from_l3_agent(l3_agent=routers[router_id],
                                            router_id=router_id)
        quantum.add_router_to_l3_agent(l3_agent=l3_agents[agent],
                                       body={'router_id': router_id})
        index += 1

    index = 0
    for network_id in networks:
        agent = index % len(dhcp_agents)
        log('Moving network %s from %s to %s' %
            (network_id, networks[network_id], dhcp_agents[agent]))
        quantum.remove_network_from_dhcp_agent(dhcp_agent=networks[network_id],
                                               network_id=network_id)
        quantum.add_network_to_dhcp_agent(dhcp_agent=dhcp_agents[agent],
                                          body={'network_id': network_id})
        index += 1
Beispiel #20
0
                secgroup=nshell._get_secgroup(c, sec_group_name)
                try:
                    c.security_group_rules.create(secgroup.id, "TCP", 22, 22, "10.0.0.0/8")
                except:
                    pass
                try:
                    c.security_group_rules.create(secgroup.id, "UDP", 4789, 4789, "10.0.0.0/8")
                except:
                    pass
                try:
                    c.security_group_rules.create(secgroup.id, "ICMP", -1, 255, "10.0.0.0/8")
                except:
                    pass

                #create quantum client for floating ip address creation/association and VM network
                quantum=qclient.Client(username=user, password=password, tenant_name=tenant_name, auth_url=auth_url, region_name=region_name)
                #look for network id of the external network
                _network_id = quantumv20.find_resourceid_by_name_or_id(quantum, 'network', tenant_name+'-net')
                v_nics=[]
                v_nic={}

                x = PrettyTable(["Property", "Value"])
                x.add_row(["VM name", instance_name])
                x.add_row(["VM number", i+1])
                x.add_row(["Network ID",_network_id])
                v_nic['net-id']=_network_id
                v_nic['v4-fixed-ip']=None
                v_nics.append(v_nic)
                hints={}
                if server_name:
                    hints['force_hosts']=server_name
Beispiel #21
0
 def quantum(self):
     return qc.Client(auth_url=self.authinfo['OS_AUTH_URL'], username=self.authinfo['OS_USERNAME'],
                      password=self.authinfo['OS_PASSWORD'], tenant_name=self.authinfo['OS_TENANT_NAME'])