Beispiel #1
0
def pack_openstack_params():
    """
    Packe Openstack Parameters
    """
    if not S.hasValue('OS_AUTH_URL'):
        raise Exception('OpenStack authentication endpoint is missing')

    params = dict(auth=dict(username=S.getValue('OS_USERNAME'),
                            password=S.getValue('OS_PASSWORD'),
                            auth_url=S.getValue('OS_AUTH_URL')),
                  os_region_name=S.getValue('OS_REGION_NAME'),
                  os_cacert=S.getValue('OS_CA_CERT'),
                  os_insecure=S.getValue('OS_INSECURE'))

    if S.hasValue('OS_PROJECT_NAME'):
        value = S.getValue('OS_PROJECT_NAME')
        params['auth']['project_name'] = value
    if S.hasValue('OS_PROJECT_DOMAIN_NAME'):
        value = S.getValue('OS_PROJECT_DOMAIN_NAME')
        params['auth']['project_domain_name'] = value
    if S.hasValue('OS_USER_DOMAIN_NAME'):
        value = S.getValue('OS_USER_DOMAIN_NAME')
        params['auth']['user_domain_name'] = value
    if S.hasValue('OS_INTERFACE'):
        value = S.getValue('OS_INTERFACE')
        params['os_interface'] = value
    if S.hasValue('OS_API_VERSION'):
        value = S.getValue('OS_API_VERSION')
        params['identity_api_version'] = value
    if S.hasValue('OS_PROFILE'):
        value = S.getValue('OS_PROFILE')
        params['os_profile'] = value
    return params
Beispiel #2
0
def normalize_accommodation(accommodation):
    """
    Planning the Accomodation of TestVNFs
    """
    result = {}

    for s in accommodation:
        if isinstance(s, dict):
            result.update(s)
        else:
            result[s] = True

    # override scenario's availability zone accommodation
    if S.hasValue('SCENARIO_AVAILABILITY_ZONE'):
        result['zones'] = S.getValue('SCENARIO_AVAILABILITY_ZONE')
    # override scenario's compute_nodes accommodation
    if S.hasValue('SCENARIO_COMPUTE_NODES'):
        result['compute_nodes'] = S.getValue('SCENARIO_COMPUTE_NODES')

    return result
Beispiel #3
0
    def connect_to_openstack(self, openstack_params, flavor_name, image_name,
                             external_net, dns_nameservers):
        """
        Connect to Openstack
        """
        LOG.debug('Connecting to OpenStack')

        self.openstack_client = openstack.OpenStackClient(openstack_params)

        self.flavor_name = flavor_name
        self.image_name = image_name

        if S.hasValue('STACK_NAME'):
            self.stack_name = S.getValue('STACK_NAME')
        else:
            self.stack_name = 'testvnf_%s' % utils.random_string()

        self.dns_nameservers = dns_nameservers
        # intiailizing self.external_net last so that other attributes don't
        # remain uninitialized in case user forgets to create external network
        self.external_net = (external_net or neutron.choose_external_net(
            self.openstack_client.neutron))
Beispiel #4
0
    def create(self):
        """
        Creation Process
        """
        print("Entering Create Function")
        config.load_kube_config(S.getValue('K8S_CONFIG_FILEPATH'))
        # create vswitchperf namespace
        api = client.CoreV1Api()
        namespace = 'default'
        pod_manifests = S.getValue('POD_MANIFEST_FILEPATH')
        pod_count = int(S.getValue('POD_COUNT'))
        if S.hasValue('POD_NAMESPACE'):
            namespace = S.getValue('POD_NAMESPACE')
        else:
            namespace = 'default'
        dep_pod_list = []

        # sriov configmap
        if S.getValue('PLUGIN') == 'sriov':
            configmap = load_manifest(S.getValue('CONFIGMAP_FILEPATH'))
            self._sriov_config = configmap['metadata']['name']
            self._sriov_config_ns = configmap['metadata']['namespace']
            api.create_namespaced_config_map(self._sriov_config_ns, configmap)


        # create nad(network attachent definitions)
        group = 'k8s.cni.cncf.io'
        version = 'v1'
        kind_plural = 'network-attachment-definitions'
        api = client.CustomObjectsApi()
        assert pod_count <= len(pod_manifests)

        for nad_filepath in S.getValue('NETWORK_ATTACHMENT_FILEPATH'):
            nad_manifest = load_manifest(nad_filepath)

            try:
                response = api.create_namespaced_custom_object(group, version, namespace,
                                                               kind_plural, nad_manifest)
                self._logger.info(str(response))
                self._logger.info("Created Network Attachment Definition: %s", nad_filepath)
            except ApiException as err:
                raise Exception from err

        #create pod workloads
        api = client.CoreV1Api()
        for count in range(pod_count):
            dep_pod_info = {}
            pod_manifest = load_manifest(pod_manifests[count])
            dep_pod_info['name'] = pod_manifest["metadata"]["name"]
            try:
                response = api.create_namespaced_pod(namespace, pod_manifest)
                self._logger.info(str(response))
                self._logger.info("Created POD %d ...", self._number)
            except ApiException as err:
                raise Exception from err

            # Wait for the pod to start
            time.sleep(5)
            status = "Unknown"
            count = 0
            while True:
                if count == 10:
                    break
                try:
                    response = api.read_namespaced_pod_status(dep_pod_info['name'],
                            namespace)
                    status = response.status.phase
                except ApiException as err:
                    raise Exception from err
                if status in ("Running", "Failed", "Unknown"):
                    break
                time.sleep(5)
                count = count + 1
            # Now Get the Pod-IP
            try:
                response = api.read_namespaced_pod_status(dep_pod_info['name'],
                        namespace)
                dep_pod_info['pod_ip'] = response.status.pod_ip
            except ApiException as err:
                raise Exception from err
            dep_pod_info['namespace'] = namespace
            cmd = ['cat', '/etc/podnetinfo/annotations']
            output = util.execute_command(api, dep_pod_info, cmd)
            dep_pod_info['annotations'] = output
            dep_pod_list.append(dep_pod_info)

        S.setValue('POD_LIST',dep_pod_list)
        return dep_pod_list