github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/bcs/v2/blockchains/requests.go (about)

     1  package blockchains
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  //CreateOpts is a struct which will be used to create a bcs instance
     8  type CreateOpts struct {
     9  	Name                string          `json:"name" required:"true"`
    10  	ClusterType         string          `json:"cluster_type" required:"true"`
    11  	CreateNewCluster    *bool           `json:"create_new_cluster" required:"true"`
    12  	EnterpriseProjectId string          `json:"enterprise_project_id" required:"true"`
    13  	FabricVersion       string          `json:"fabric_version" required:"true"`
    14  	Password            string          `json:"resource_password" required:"true"`
    15  	VersionType         int             `json:"version_type" required:"true"`
    16  	BlockChainType      string          `json:"blockchain_type,omitempty"`
    17  	Consensus           string          `json:"consensus,omitempty"`
    18  	SignAlgorithm       string          `json:"sign_algorithm,omitempty"`
    19  	VolumeType          string          `json:"volume_type,omitempty"`
    20  	EvsDiskType         string          `json:"evs_disk_type,omitempty"`
    21  	OrgDiskSize         int             `json:"org_disk_size,omitempty"`
    22  	DatabaseType        string          `json:"database_type,omitempty"`
    23  	OrdererNodeNumber   int             `json:"orderer_node_number,omitempty"`
    24  	EIPEnable           bool            `json:"use_eip,omitempty"`
    25  	BandwidthSize       int             `json:"bandwidth_size,omitempty"`
    26  	CCEClusterInfo      *CCEClusterInfo `json:"cce_cluster_info,omitempty"`
    27  	CCECreateInfo       *CCECreateInfo  `json:"cce_create_info,omitempty"`
    28  	IEFDeployMode       int             `json:"ief_deploy_mode,omitempty"`
    29  	IEFNodesInfo        []IEFNode       `json:"ief_nodes_info,omitempty"`
    30  	PeerOrgs            []PeerOrg       `json:"peer_orgs,omitempty"`
    31  	Channels            []ChannelInfo   `json:"channels,omitempty"`
    32  	CouchDBInfo         *CouchDBInfo    `json:"couchdb_info,omitempty"`
    33  	SFSTurbo            *SFSTurbo       `json:"turbo_info,omitempty"`
    34  	Block               *BlockInfo      `json:"block_info,omitempty"`
    35  	Kafka               *KafkaInfo      `json:"kafka_create_info,omitempty"`
    36  	TC3Need             bool            `json:"tc3_need,omitempty"`
    37  	RestfulAPISupport   bool            `json:"restful_api_support,omitempty"`
    38  	IsInvitee           bool            `json:"is_invitee,omitempty"`
    39  	InvitorInfo         *InvitorInfo    `json:"invitor_infos,omitempty"`
    40  }
    41  
    42  //CCEClusterInfo is the CCE cluster struct that will be used to associate when creating a bcs instance
    43  type CCEClusterInfo struct {
    44  	ID   string `json:"cluster_id" required:"true"`
    45  	Name string `json:"cluster_name" required:"true"`
    46  }
    47  
    48  //CCECreateInfo is the struct that will be used to specify the creation of a new CCE cluster
    49  //when creating a bcs instance
    50  type CCECreateInfo struct {
    51  	NodeNum          int    `json:"node_num" required:"true"`
    52  	Flavor           string `json:"node_flavor" required:"true"`
    53  	ClusterFlavor    string `json:"cce_flavor" required:"true"`
    54  	Password         string `json:"init_node_pwd" required:"true"`
    55  	AvailabilityZone string `json:"az" required:"true"`
    56  	PlatformType     string `json:"cluster_platform_type" required:"true"`
    57  }
    58  
    59  //IEFNode is the IEF node struct that will be used to associate when creating a bcs instance
    60  type IEFNode struct {
    61  	ID        string `json:"id" required:"true"`
    62  	Status    string `json:"status" required:"true"`
    63  	IPAddress string `json:"public_ip_address" required:"true"`
    64  }
    65  
    66  //PeerOrg is the peer organization struct that will be used to creating a bcs instance
    67  type PeerOrg struct {
    68  	Name      string `json:"name" required:"true"`
    69  	NodeCount int    `json:"node_count" required:"true"`
    70  }
    71  
    72  //ChannelInfo is the channel struct that will be used to creating a bcs instance
    73  type ChannelInfo struct {
    74  	Name        string   `json:"name" required:"true"`
    75  	OrgNames    []string `json:"org_names" required:"true"`
    76  	Description string   `json:"desctiption,omitempty"`
    77  }
    78  
    79  //CouchDBInfo is the couch database struct that will be used to creating a bcs instance
    80  type CouchDBInfo struct {
    81  	UserName string `json:"user_name" required:"true"`
    82  	Password string `json:"password" required:"true"`
    83  }
    84  
    85  //SFSTurbo is the turbo struct that will be used to creating a bcs instance
    86  type SFSTurbo struct {
    87  	ShareType        string `json:"share_type" required:"true"`
    88  	Type             string `json:"type" required:"true"`
    89  	AvailabilityZone string `json:"availability_zone" required:"true"`
    90  	Flavor           string `json:"resource_spec_code" required:"true"`
    91  }
    92  
    93  //BlockInfo is the turbo struct that will be used to creating a bcs instance
    94  type BlockInfo struct {
    95  	BatchTimeout      int `json:"batch_timeout,omitempty"`
    96  	MaxMessageCount   int `json:"max_message_count,omitempty"`
    97  	PreferredMaxbytes int `json:"preferred_maxbytes,omitempty"`
    98  }
    99  
   100  //KafkaInfo is the block generation struct that be used to config when creating a bcs instance
   101  type KafkaInfo struct {
   102  	Flavor           string `json:"spec" required:"true"`
   103  	Storage          int    `json:"storage" required:"true"`
   104  	AvailabilityZone string `json:"az" required:"true"`
   105  }
   106  
   107  //InvitorInfo is the invitor struct that be used to config when creating a bcs instance
   108  type InvitorInfo struct {
   109  	TenantID     string `json:"tenant_id" required:"true"`
   110  	ProjectID    string `json:"project_id" required:"true"`
   111  	BlockchainID string `json:"blockchain_id" required:"true"`
   112  }
   113  
   114  type CreateOptsBuilder interface {
   115  	ToInstancesCreateMap() (map[string]interface{}, error)
   116  }
   117  
   118  func (opts CreateOpts) ToInstancesCreateMap() (map[string]interface{}, error) {
   119  	b, err := golangsdk.BuildRequestBody(opts, "")
   120  	if err != nil {
   121  		return nil, err
   122  	}
   123  	return b, nil
   124  }
   125  
   126  //Create is a method by which can be able to access the create function that create a bcs instance
   127  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   128  	b, err := opts.ToInstancesCreateMap()
   129  	if err != nil {
   130  		r.Err = err
   131  		return
   132  	}
   133  
   134  	_, r.Err = client.Post(rootURL(client), b, &r.Body, &golangsdk.RequestOpts{
   135  		OkCodes: []int{200, 202},
   136  	})
   137  	return
   138  }
   139  
   140  //DeleteOpts is a struct which will be used to delete an existing bcs instance
   141  type DeleteOpts struct {
   142  	IsDeleteStorage  bool `q:"is_delete_storage"`
   143  	IsDeleteOBS      bool `q:"is_delete_obs"`
   144  	IsDeleteResource bool `q:"is_delete_resource"`
   145  }
   146  
   147  type DeleteOptsBuilder interface {
   148  	ToInstanceDeleteQuery() (string, error)
   149  }
   150  
   151  func (opts DeleteOpts) ToInstanceDeleteQuery() (string, error) {
   152  	q, err := golangsdk.BuildQueryString(opts)
   153  	if err != nil {
   154  		return "", err
   155  	}
   156  	return q.String(), err
   157  }
   158  
   159  //Delete is a method to delete an existing bcs instance
   160  func Delete(client *golangsdk.ServiceClient, opts DeleteOptsBuilder, id string) (r DeleteResult) {
   161  	url := resourceURL(client, id)
   162  	if opts != nil {
   163  		query, err := opts.ToInstanceDeleteQuery()
   164  		if err != nil {
   165  			r.Err = err
   166  			return
   167  		}
   168  		url += query
   169  	}
   170  	_, r.Err = client.Delete(url, &golangsdk.RequestOpts{
   171  		OkCodes:      []int{200, 202, 204},
   172  		JSONResponse: nil,
   173  		MoreHeaders:  map[string]string{"Content-Type": "application/json"},
   174  	})
   175  	return
   176  }
   177  
   178  //Get is a method to obtain the detailed information of an existing bcs instance
   179  func Get(client *golangsdk.ServiceClient, id string) (r ShowResult) {
   180  	_, r.Err = client.Get(resourceURL(client, id), &r.Body, nil)
   181  	return
   182  }
   183  
   184  //GetStatus is a method to obtain all block status of an existing bcs instance
   185  func GetStatus(client *golangsdk.ServiceClient, id string) (r StatusResult) {
   186  	_, r.Err = client.Get(extraURL(client, id, "status"), &r.Body, nil)
   187  	return
   188  }
   189  
   190  //List is a method to obtain the detailed information list of all existing bcs instance
   191  func List(client *golangsdk.ServiceClient) (r ListResult) {
   192  	_, r.Err = client.Get(rootURL(client), &r.Body, nil)
   193  	return
   194  }
   195  
   196  //GetNodes is a method to obtain the node information list of an existing bcs instance
   197  func GetNodes(client *golangsdk.ServiceClient, id string) (r NodesResult) {
   198  	_, r.Err = client.Get(extraURL(client, id, "nodes"), &r.Body, nil)
   199  	return
   200  }
   201  
   202  //UpdateOpts is a struct which will be used to update an existing bcs instance
   203  type UpdateOpts struct {
   204  	NodePeer  []NodePeer `json:"node_orgs" required:"true"`
   205  	PublicIPs []IEFNode  `json:"publicips,omitempty"`
   206  }
   207  
   208  //NodePeer is the peer organization struct that will be used to add a peer organization to an existing bcs instance
   209  type NodePeer struct {
   210  	Name    string `json:"name" required:"true"`
   211  	Count   int    `json:"node_count" required:"true"`
   212  	PVCName string `json:"pvc_name,omitempty"`
   213  }
   214  
   215  type UpdateOptsBuilder interface {
   216  	ToInstancesUpdateMap() (map[string]interface{}, error)
   217  }
   218  
   219  func (opts UpdateOpts) ToInstancesUpdateMap() (map[string]interface{}, error) {
   220  	b, err := golangsdk.BuildRequestBody(opts, "")
   221  	if err != nil {
   222  		return nil, err
   223  	}
   224  	return b, nil
   225  }
   226  
   227  //Update is a method to update an existing bcs instance
   228  func Update(client *golangsdk.ServiceClient, opts UpdateOptsBuilder, id string) (r UpdateResult) {
   229  	b, err := opts.ToInstancesUpdateMap()
   230  	if err != nil {
   231  		r.Err = err
   232  		return
   233  	}
   234  
   235  	_, r.Err = client.Post(resourceURL(client, id), b, nil, &golangsdk.RequestOpts{
   236  		OkCodes: []int{200, 202},
   237  	})
   238  	return
   239  }