コード例 #1
0
    def __init__(self, controller_ip, user='******', password='******',
                 tenant='admin', cert=None, env=None):
        logger.debug('Init OpenStack clients on {0}'.format(controller_ip))
        self.controller_ip = controller_ip

        if cert is None:
            auth_url = 'http://{0}:5000/v2.0/'.format(self.controller_ip)
            path_to_cert = None
        else:
            auth_url = 'https://{0}:5000/v2.0/'.format(self.controller_ip)
            with NamedTemporaryFile(prefix="fuel_cert_", suffix=".pem",
                                    delete=False) as f:
                f.write(cert)
            path_to_cert = f.name

        logger.debug('Auth URL is {0}'.format(auth_url))
        self.nova = nova_client.Client(version=2,
                                       username=user,
                                       api_key=password,
                                       project_id=tenant,
                                       auth_url=auth_url,
                                       cacert=path_to_cert)

        self.cinder = cinderclient.Client(2, user, password,
                                          tenant, auth_url,
                                          cacert=path_to_cert)

        self.neutron = neutronclient.Client(username=user,
                                            password=password,
                                            tenant_name=tenant,
                                            auth_url=auth_url,
                                            ca_cert=path_to_cert)

        self.keystone = self._get_keystoneclient(username=user,
                                                 password=password,
                                                 tenant_name=tenant,
                                                 auth_url=auth_url,
                                                 ca_cert=path_to_cert)

        token = self.keystone.auth_token
        logger.debug('Token is {0}'.format(token))
        glance_endpoint = self.keystone.service_catalog.url_for(
            service_type='image', endpoint_type='publicURL')
        logger.debug('Glance endpoint is {0}'.format(glance_endpoint))

        self.glance = GlanceClient(endpoint=glance_endpoint,
                                   token=token,
                                   cacert=path_to_cert)

        heat_endpoint = self.keystone.service_catalog.url_for(
            service_type='orchestration', endpoint_type='publicURL')
        logger.debug('Heat endpoint is {0}'.format(heat_endpoint))
        self.heat = heat_client(endpoint=heat_endpoint,
                                token=token,
                                cacert=path_to_cert,
                                ca_file=path_to_cert)
        self.env = env
コード例 #2
0
    def setUpClass(cls):
        OS_AUTH_URL = os.environ.get("OS_AUTH_URL")
        OS_USERNAME = os.environ.get("OS_USERNAME")
        OS_PASSWORD = os.environ.get("OS_PASSWORD")
        OS_TENANT_NAME = os.environ.get("OS_TENANT_NAME")
        OS_PROJECT_NAME = os.environ.get("OS_PROJECT_NAME")

        cls.keystone = keystone_client.Client(
            auth_url=OS_AUTH_URL,
            username=OS_USERNAME,
            password=OS_PASSWORD,
            tenat_name=OS_TENANT_NAME,
            project_name=OS_PROJECT_NAME,
        )
        services = cls.keystone.service_catalog
        heat_endpoint = services.url_for(service_type="orchestration", endpoint_type="internalURL")

        cls.heat = heat_client(endpoint=heat_endpoint, token=cls.keystone.auth_token)

        # Get path on node to 'templates' dir
        cls.templates_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")
        # Get path on node to 'images' dir
        cls.images_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "images")

        # Neutron connect
        cls.neutron = neutron_client.Client(
            username=OS_USERNAME, password=OS_PASSWORD, tenant_name=OS_TENANT_NAME, auth_url=OS_AUTH_URL, insecure=True
        )

        # Nova connect
        OS_TOKEN = cls.keystone.get_token(cls.keystone.session)
        RAW_TOKEN = cls.keystone.get_raw_token_from_identity_service(
            auth_url=OS_AUTH_URL, username=OS_USERNAME, password=OS_PASSWORD, tenant_name=OS_TENANT_NAME
        )
        OS_TENANT_ID = RAW_TOKEN["token"]["tenant"]["id"]

        cls.nova = nova_client.Client(
            "2", auth_url=OS_AUTH_URL, username=OS_USERNAME, auth_token=OS_TOKEN, tenant_id=OS_TENANT_ID, insecure=True
        )

        # Glance connect
        glance_endpoint = services.url_for(service_type="image", endpoint_type="publicURL")
        cls.glance = glance_client.Client(endpoint=glance_endpoint, token=OS_TOKEN, insecure=True)
        cls.uid_list = []