lxd/db/storage_pools.go
func (c *Cluster) StoragePoolVolumeCreate(project, volumeName, volumeDescription string, volumeType int, snapshot bool, poolID int64, volumeConfig map[string]string) (int64, error) {
	var thisVolumeID int64

	err := c.Transaction(func(tx *ClusterTx) error {
		nodeIDs := []int{int(c.nodeID)}
		driver, err := storagePoolDriverGet(tx.tx, poolID)
		if err != nil {
			return err
		}
		// If the driver is ceph, create a volume entry for each node.
		if driver == "ceph" {
			nodeIDs, err = query.SelectIntegers(tx.tx, "SELECT id FROM nodes")
			if err != nil {
				return err
			}
		}

		for _, nodeID := range nodeIDs {
			result, err := tx.tx.Exec(`
INSERT INTO storage_volumes (storage_pool_id, node_id, type, snapshot, name, description, project_id) VALUES (?, ?, ?, ?, ?, ?, (SELECT id FROM projects WHERE name = ?))
`,
				poolID, nodeID, volumeType, snapshot, volumeName, volumeDescription, project)
			if err != nil {
				return err
			}

			volumeID, err := result.LastInsertId()
			if err != nil {
				return err
			}
			if int64(nodeID) == c.nodeID {
				// Return the ID of the volume created on this node.
				thisVolumeID = volumeID
			}

			err = StorageVolumeConfigAdd(tx.tx, volumeID, volumeConfig)
			if err != nil {
				tx.tx.Rollback()
				return err
			}
		}
		return nil
	})
	if err != nil {
		thisVolumeID = -1
	}

	return thisVolumeID, err
}
func (c *Cluster) StoragePoolVolumeCreate(project, volumeName, volumeDescription string, volumeType int, snapshot bool, poolID int64, volumeConfig map[string]string) (int64, error) {
	var thisVolumeID int64

	err := c.Transaction(func(tx *ClusterTx) error {
		nodeIDs := []int{int(c.nodeID)}
		driver, err := storagePoolDriverGet(tx.tx, poolID)
		if err != nil {
			return err
		}
		// If the driver is ceph, create a volume entry for each node.
		if driver == "ceph" {
			nodeIDs, err = query.SelectIntegers(tx.tx, "SELECT id FROM nodes")
			if err != nil {
				return err
			}
		}

		for _, nodeID := range nodeIDs {
			result, err := tx.tx.Exec(`
INSERT INTO storage_volumes (storage_pool_id, node_id, type, snapshot, name, description, project_id) VALUES (?, ?, ?, ?, ?, ?, (SELECT id FROM projects WHERE name = ?))
`,
				poolID, nodeID, volumeType, snapshot, volumeName, volumeDescription, project)
			if err != nil {
				return err
			}

			volumeID, err := result.LastInsertId()
			if err != nil {
				return err
			}
			if int64(nodeID) == c.nodeID {
				// Return the ID of the volume created on this node.
				thisVolumeID = volumeID
			}

			err = StorageVolumeConfigAdd(tx.tx, volumeID, volumeConfig)
			if err != nil {
				tx.tx.Rollback()
				return err
			}
		}
		return nil
	})
	if err != nil {
		thisVolumeID = -1
	}

	return thisVolumeID, err
}
func ( c * Cluster ) StoragePoolVolumeCreate ( project , volumeName , volumeDescription string , volumeType int , snapshot bool , poolID int64 , volumeConfig map [ string ] string ) ( int64 , error ) { var thisVolumeID int64 err := c . Transaction ( func ( tx * ClusterTx ) error { nodeIDs := [ ] int { int ( c . nodeID ) } driver , err := storagePoolDriverGet ( tx . tx , poolID ) if err != nil { return err } // If the driver is ceph, create a volume entry for each node. if driver == " " { nodeIDs , err = query . SelectIntegers ( tx . tx , " " ) if err != nil { return err } } for _ , nodeID := range nodeIDs { result , err := tx . tx . Exec ( `
INSERT INTO storage_volumes (storage_pool_id, node_id, type, snapshot, name, description, project_id) VALUES (?, ?, ?, ?, ?, ?, (SELECT id FROM projects WHERE name = ?))
` , poolID , nodeID , volumeType , snapshot , volumeName , volumeDescription , project ) if err != nil { return err } volumeID , err := result . LastInsertId ( ) if err != nil { return err } if int64 ( nodeID ) == c . nodeID { // Return the ID of the volume created on this node. thisVolumeID = volumeID } err = StorageVolumeConfigAdd ( tx . tx , volumeID , volumeConfig ) if err != nil { tx . tx . Rollback ( ) return err } } return nil } ) if err != nil { thisVolumeID = - 1 } return thisVolumeID , err }
// StoragePoolVolumeCreate creates a new storage volume attached to a given
// storage pool.
StoragePoolVolumeCreate creates a new storage volume attached to a given storage pool .