(self, cluster)
return ClusterID(new_cluster.uuid)
Create a new cluster.

        :param cluster: a cluster within the request body.
Create a new cluster.
Create a new cluster .
def _post(self, cluster):
        """Create a new cluster.

        :param cluster: a cluster within the request body.
        """
        context = pecan.request.context
        policy.enforce(context, 'cluster:create',
                       action='cluster:create')

        self._check_cluster_quota_limit(context)

        temp_id = cluster.cluster_template_id
        cluster_template = objects.ClusterTemplate.get(context, temp_id)
        # We are not sure if we got a uuid or name here. So just set
        # explicitly the uuid of the cluster template in the cluster.
        cluster.cluster_template_id = cluster_template.uuid
        # If keypair not present, use cluster_template value
        if cluster.keypair is None:
            cluster.keypair = cluster_template.keypair_id

        # If labels is not present, use cluster_template value
        if cluster.labels == wtypes.Unset or not cluster.labels:
            cluster.labels = cluster_template.labels
        else:
            # If labels are provided check if the user wishes to merge
            # them with the values from the cluster template.
            if cluster.merge_labels:
                labels = cluster_template.labels
                labels.update(cluster.labels)
                cluster.labels = labels

        cinder_csi_enabled = cluster.labels.get('cinder_csi_enabled', True)
        if (cluster_template.volume_driver == 'cinder' and
                not strutils.bool_from_string(cinder_csi_enabled)):
            warnings.warn(self._in_tree_cinder_volume_driver_deprecation_note,
                          DeprecationWarning)
            LOG.warning(self._in_tree_cinder_volume_driver_deprecation_note)

        # If floating_ip_enabled is not present, use cluster_template value
        if cluster.floating_ip_enabled == wtypes.Unset:
            cluster.floating_ip_enabled = cluster_template.floating_ip_enabled

        # If master_lb_enabled is not present, use cluster_template value
        if cluster.master_lb_enabled == wtypes.Unset:
            cluster.master_lb_enabled = cluster_template.master_lb_enabled

        attributes = ["docker_volume_size", "master_flavor_id", "flavor_id",
                      "fixed_network", "fixed_subnet"]
        for attr in attributes:
            if (getattr(cluster, attr) == wtypes.Unset or
                    not getattr(cluster, attr)):
                setattr(cluster, attr, getattr(cluster_template, attr))

        cluster_dict = cluster.as_dict()

        attr_validator.validate_os_resources(context,
                                             cluster_template.as_dict(),
                                             cluster_dict)
        attr_validator.validate_master_count(cluster_dict,
                                             cluster_template.as_dict())

        cluster_dict['project_id'] = context.project_id
        cluster_dict['user_id'] = context.user_id
        # NOTE(yuywz): We will generate a random human-readable name for
        # cluster if the name is not specified by user.
        name = cluster_dict.get('name') or \
            self._generate_name_for_cluster(context)
        cluster_dict['name'] = name
        cluster_dict['coe_version'] = None
        cluster_dict['container_version'] = None

        node_count = cluster_dict.pop('node_count')
        master_count = cluster_dict.pop('master_count')
        new_cluster = objects.Cluster(context, **cluster_dict)
        new_cluster.uuid = uuid.uuid4()
        pecan.request.rpcapi.cluster_create_async(new_cluster,
                                                  master_count, node_count,
                                                  cluster.create_timeout)

        return ClusterID(new_cluster.uuid)
def _post ( self , cluster ) : context = pecan . request . context policy . enforce ( context , 'cluster:create' , action = 'cluster:create' ) self . _check_cluster_quota_limit ( context ) temp_id = cluster . cluster_template_id cluster_template = objects . ClusterTemplate . get ( context , temp_id ) # We are not sure if we got a uuid or name here. So just set # explicitly the uuid of the cluster template in the cluster. cluster . cluster_template_id = cluster_template . uuid # If keypair not present, use cluster_template value if cluster . keypair is None : cluster . keypair = cluster_template . keypair_id # If labels is not present, use cluster_template value if cluster . labels == wtypes . Unset or not cluster . labels : cluster . labels = cluster_template . labels else : # If labels are provided check if the user wishes to merge # them with the values from the cluster template. if cluster . merge_labels : labels = cluster_template . labels labels . update ( cluster . labels ) cluster . labels = labels cinder_csi_enabled = cluster . labels . get ( 'cinder_csi_enabled' , True ) if ( cluster_template . volume_driver == 'cinder' and not strutils . bool_from_string ( cinder_csi_enabled ) ) : warnings . warn ( self . _in_tree_cinder_volume_driver_deprecation_note , DeprecationWarning ) LOG . warning ( self . _in_tree_cinder_volume_driver_deprecation_note ) # If floating_ip_enabled is not present, use cluster_template value if cluster . floating_ip_enabled == wtypes . Unset : cluster . floating_ip_enabled = cluster_template . floating_ip_enabled # If master_lb_enabled is not present, use cluster_template value if cluster . master_lb_enabled == wtypes . Unset : cluster . master_lb_enabled = cluster_template . master_lb_enabled attributes = [ "docker_volume_size" , "master_flavor_id" , "flavor_id" , "fixed_network" , "fixed_subnet" ] for attr in attributes : if ( getattr ( cluster , attr ) == wtypes . Unset or not getattr ( cluster , attr ) ) : setattr ( cluster , attr , getattr ( cluster_template , attr ) ) cluster_dict = cluster . as_dict ( ) attr_validator . validate_os_resources ( context , cluster_template . as_dict ( ) , cluster_dict ) attr_validator . validate_master_count ( cluster_dict , cluster_template . as_dict ( ) ) cluster_dict [ 'project_id' ] = context . project_id cluster_dict [ 'user_id' ] = context . user_id # NOTE(yuywz): We will generate a random human-readable name for # cluster if the name is not specified by user. name = cluster_dict . get ( 'name' ) or self . _generate_name_for_cluster ( context ) cluster_dict [ 'name' ] = name cluster_dict [ 'coe_version' ] = None cluster_dict [ 'container_version' ] = None node_count = cluster_dict . pop ( 'node_count' ) master_count = cluster_dict . pop ( 'master_count' ) new_cluster = objects . Cluster ( context , * * cluster_dict ) new_cluster . uuid = uuid . uuid4 ( ) pecan . request . rpcapi . cluster_create_async ( new_cluster , master_count , node_count , cluster . create_timeout ) return ClusterID ( new_cluster . uuid )