Ejemplo n.º 1
0
    def __init__(self, username, password, auth_url):
        self.username = username
        self.password = password
        self.auth_url = auth_url

        self.config = {}
        self.users = []
        self.tenant = None
        self.network = None
        self.router = None

        self.keystone = keystone_client(
            username=username,
            password=password,
            tenant_name=username,
            auth_url=auth_url
        )
        self.neutron = neutron_client(
            username=username,
            password=password,
            tenant_name=username,
            auth_url=auth_url
        )
        self.nova = nova_client.Client(
            username=username,
            api_key=password,
            project_id=username,
            auth_url=auth_url
        )
    def set_context(self, project_type="admin", project_info=None, **kwargs):
        '''It sets the context to the project passed.
        NOTE: For non-admin project pass the project_info.

        :param project_type str: Project type. (admin/non-admin)
        :param project_info dict: Detail info of the project.
                like project_name, user_name, and password
                Ignore this if it is admin project
        :optional params:
            domain_name: Name of the project and user domain,
                        if the set up is domain based.
        '''
        try:
            old_context = self.get_context()
            session = kwargs.get('session')
            if session is None:
                session = KeystoneDriver.get_keystone_auth_session(
                    project_type=project_type,
                    project_info=project_info, **kwargs)
                if session is None:
                    LOG.error("Unable to get the session object.")
                    return
            self.session = session
            # Note: internally the properties of super class is called.
            self.nova = nova_client.Client(self.nova_api_version,
                                           session=session)
            self.neutron = neutron_client(session=session)

            LOG.debug("Context is set to :%s project, id:%s", project_type,
                      self.session.get_project_id())

            return old_context

        except Exception as err:
            LOG.exception(err)
Ejemplo n.º 3
0
    def __init__(self, username, password, auth_url):
        self.keystone = keystone_client(
            username=username,
            password=password,
            tenant_name=username,
            auth_url=auth_url)

        self.endpoints = self.keystone.service_catalog.get_endpoints()
        self.token = self.keystone.auth_ref['token']['id']

        self.glance = glance_client(
            endpoint=self.endpoints['image'][0]['internalURL'],
            token=self.token)

        self.neutron = neutron_client(
            username=username,
            password=password,
            tenant_name=username,
            auth_url=auth_url,
            endpoint_type='internalURL')

        self.nova = nova_client.Client(
            username=username,
            api_key=password,
            project_id=username,
            auth_url=auth_url,
            endpoint_type='internalURL')

        self.images = []
        self.network = {}
        self.router = {}
        self.users = {}
        self.admin = {'username': username, 'password': password}
Ejemplo n.º 4
0
    def neutronclient(self):
        """Openstack neutronclient generator."""
        logger.debug(
            'neutron connection created using token "%s" and url "%s"'
            % (self.creds['username'], self.creds['auth_url'])
        )

        args = ["auth_url", "username", "password", "tenant_name"]
        return neutron_client(**self.build_args(args))
Ejemplo n.º 5
0
    def neutronclient(self):
        """
        Openstack neutronclient generator
        """
        util.logger.debug(
            'neutron connection created using token "%s" and url "%s"' %
            (self.creds['username'], self.creds['auth_url']))

        client = neutron_client(auth_url=self.creds['auth_url'],
                                username=self.creds['username'],
                                password=self.creds['password'],
                                tenant_name=self.creds['username'],
                                api_key=self.creds['api_key'])
        return client
Ejemplo n.º 6
0
    def neutronclient(self):
        """
        Openstack neutronclient generator
        """
        util.logger.debug(
            'neutron connection created using token "%s" and url "%s"'
            % (self.creds['username'], self.creds['auth_url'])
        )

        client = neutron_client(auth_url=self.creds['auth_url'],
                                username=self.creds['username'],
                                password=self.creds['password'],
                                tenant_name=self.creds['username'],
                                api_key=self.creds['api_key'])
        return client
Ejemplo n.º 7
0
    def __init__(self, deployment, progress):
        super(HATest, self).__init__(deployment)
        self.iterations = 1
        self.progress = progress
        self.current_iteration = 0
        controllers = list(self.deployment.search_role("controller"))
        self.controller1 = controllers[0]
        self.controller2 = controllers[1]
        # get creds
        creds = self.gather_creds(deployment)

        # Setup clients
        self.nova = nova_client.Client(creds.user, creds.password, creds.user,
                                       auth_url=creds.url)
        self.neutron = neutron_client(auth_url=creds.url, username=creds.user,
                                      password=creds.password,
                                      tenant_name=creds.user)
        self.rabbit = deployment.rabbitmq_mgmt_client
Ejemplo n.º 8
0
	def __init__(topo,info):
		topo.info=info
		topo.subnet_route_route = len(info['link']['route_route'])
		topo.subnet_route_host = len(info['link']['route_host'])
		topo.subnet_num = topo.subnet_route_route+topo.subnet_route_host
		topo.router_num = info['routes']
		topo.network_id = u'' 
		topo.subnet_id = {}
		topo.subnet_cidr = {}
		topo.router_cidr = {}
		topo.ports_id = {}
		topo.router_id = {}
		topo.route_ip = {}
		topo.neutron_credentials = get_credentials()
		topo.nova_credentials = get_nova_credentials_v2()
		topo.neutron = neutron_client(**topo.neutron_credentials)
		topo.nova = nova_client(**topo.nova_credentials)
		for tmp in range(topo.subnet_num):
			topo.ports_id[tmp] = {}
		for tmp in range(topo.subnet_num):
			topo.route_ip[tmp] = {}
Ejemplo n.º 9
0
def overview(request, template_name, template_data):
    """overview页面"""
    password = request.session.get("password", None)
    username = template_data["username"]
    tenant_name = template_data["tenant_name"]
    keystone_client_1 = template_data["keystone_client"]

    try:
        # 获取主机数量
        nova_client_1 = nova_client(
            2, username, password, tenant_name, AUTH_URL_V2)
        servers_sum = len(nova_client_1.servers.list())
        template_data['servers_sum'] = servers_sum

        # 获取volume数量
        cinder_client_1 = cinder_client(
            username, password, tenant_name,
            AUTH_URL_V2, service_type="volume")
        volumes_sum = len(cinder_client_1.volumes.list())
        template_data['volumes_sum'] = volumes_sum

        # volume_snapshot数量
        volume_snapshots_sum = len(cinder_client_1.volume_snapshots.list())
        template_data['volume_snapshots_sum'] = volume_snapshots_sum

        # 获取私有网络数量
        # FIXME 如果使用普通的网络,而非使用neutron
        neutron_client_1 = neutron_client(
            username=username,
            password=password,
            tenant_name=tenant_name,
            auth_url=AUTH_URL_V2)
        networks_1 = neutron_client_1.list_networks()
        private_network_sum = 0
        for net in networks_1['networks']:
            if net['tenant_id'] == keystone_client_1.tenant_id:
                private_network_sum = private_network_sum + 1
        template_data['private_network_sum'] = private_network_sum

        # floating ip 数量
        floating_ip_sum = \
            len(neutron_client_1.list_floatingips()['floatingips'])
        template_data['floating_ip_sum'] = floating_ip_sum

        # 获取该组中的用户个数
        group1 = Group.objects.get(
            tenantid=keystone_client_1.tenant_id, enable=1)
        group_users = User.objects.filter(groupid=group1.id, enable=1)
        group_users_sum = len(group_users)
        template_data['group_users_sum'] = group_users_sum

        # 获取防火墙数
        # TODO

        # 获取映像数
        glance = glance_client(
            keystone_client_1.service_catalog.url_for(service_type="image"),
            token=keystone_client_1.auth_token)
        images_sum = len(list(glance.images.list()))
        template_data['images_sum'] = images_sum

    except Exception as exc:
        print exc.message
        django_messages.add_message(
            request, 50, "nova client error: %s" % exc.message,
            extra_tags="danger")
        template_data['servers_sum'] = 0
        return render(request, "project/overview.html", template_data)
    return render(request, "project/overview.html", template_data)