當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Conn.Connect方法代碼示例

本文整理匯總了Golang中github.com/noahdesu/go-ceph/rados.Conn.Connect方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Connect方法的具體用法?Golang Conn.Connect怎麽用?Golang Conn.Connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/noahdesu/go-ceph/rados.Conn的用法示例。


在下文中一共展示了Conn.Connect方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: New

// New constructs a new Driver
func New(params DriverParameters) (*Driver, error) {
	var conn *rados.Conn
	var err error

	if params.username != "" {
		log.Infof("Opening connection to pool %s using user %s", params.poolname, params.username)
		conn, err = rados.NewConnWithUser(params.username)
	} else {
		log.Infof("Opening connection to pool %s", params.poolname)
		conn, err = rados.NewConn()
	}

	if err != nil {
		return nil, err
	}

	err = conn.ReadDefaultConfigFile()
	if err != nil {
		return nil, err
	}

	err = conn.Connect()
	if err != nil {
		return nil, err
	}

	log.Infof("Connected")

	ioctx, err := conn.OpenIOContext(params.poolname)

	log.Infof("Connected to pool %s", params.poolname)

	if err != nil {
		return nil, err
	}

	d := &driver{
		Ioctx:     ioctx,
		Conn:      conn,
		chunksize: params.chunksize,
	}

	return &Driver{
		baseEmbed: baseEmbed{
			Base: base.Base{
				StorageDriver: d,
			},
		},
	}, nil
}
開發者ID:RomainVabre,項目名稱:origin,代碼行數:51,代碼來源:rados.go

示例2: connect

// connect builds up the ceph conn and default pool
func (d *cephRBDVolumeDriver) connect() {
	log.Println("INFO: connecting to Ceph and default pool context")
	d.m.Lock()
	defer d.m.Unlock()

	// create reusable go-ceph Client Connection
	var cephConn *rados.Conn
	var err error
	if d.cluster == "" {
		cephConn, err = rados.NewConnWithUser(d.user)
	} else {
		// FIXME: TODO: can't seem to use a cluster name -- get error -22 from go-ceph/rados:
		// panic: Unable to create ceph connection to cluster=ceph with user=admin: rados: ret=-22
		cephConn, err = rados.NewConnWithClusterAndUser(d.cluster, d.user)
	}
	if err != nil {
		log.Panicf("ERROR: Unable to create ceph connection to cluster=%s with user=%s: %s", d.cluster, d.user, err)
	}

	// read ceph.conf and setup connection
	if d.config == "" {
		err = cephConn.ReadDefaultConfigFile()
	} else {
		err = cephConn.ReadConfigFile(d.config)
	}
	if err != nil {
		log.Panicf("ERROR: Unable to read ceph config: %s", err)
	}

	err = cephConn.Connect()
	if err != nil {
		log.Panicf("ERROR: Unable to connect to Ceph: %s", err)
	}

	// can now set conn in driver
	d.conn = cephConn

	// setup the default context (pool most likely to be used)
	defaultContext, err := d.openContext(d.defaultPool)
	if err != nil {
		log.Panicf("ERROR: Unable to connect to default Ceph Pool: %s", err)
	}
	d.defaultIoctx = defaultContext
}
開發者ID:bhenderson,項目名稱:rbd-docker-plugin,代碼行數:45,代碼來源:driver.go


注:本文中的github.com/noahdesu/go-ceph/rados.Conn.Connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。