libbe_py.c revision f5c2e7ea56aaa46a9976476fb0cb1f02b9426f07
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2012 OmniTI Computer Consulting, Inc. All rights reserved.
*/
#include <Python.h>
#include <stdio.h>
#include <libnvpair.h>
#include <libbe.h>
#include <libbe_priv.h>
enum {
BE_PY_SUCCESS = 0,
BE_PY_ERR_APPEND = 6000,
} bePyErr;
/*
* public libbe functions
*/
char *beMapLibbePyErrorToString(int);
void initlibbe_py();
/* ~~~~~~~~~~~~~~~ */
/* Public Funtions */
/* ~~~~~~~~~~~~~~~ */
/*
* Function: beCreateSnapshot
* Description: Convert Python args to nvlist pairs and
* call libbe:be_create_snapshot to create a
* snapshot of all the datasets within a BE
* Parameters:
* args - pointer to a python object containing:
* beName - The name of the BE to create a snapshot of
* snapName - The name of the snapshot to create (optional)
*
* The following public attribute values. defined by libbe.h,
* are used by this function:
*
* Returns a pointer to a python object and an optional snapshot name:
* 0, [snapName] - Success
* 1, [snapName] - Failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
int ret = BE_PY_SUCCESS;
}
}
}
}
NULL) != 0) {
return (Py_BuildValue("[is]",
BE_PY_ERR_NVLIST, NULL));
}
return (retVals);
}
}
/*
* Function: beCopy
* Description: Convert Python args to nvlist pairs and call libbe:be_copy
* to create a Boot Environment
* Parameters:
* args - pointer to a python object containing:
* trgtBeName - The name of the BE to create
* srcBeName - The name of the BE used to create trgtBeName (optional)
* rpool - The pool to create the new BE in (optional)
* srcSnapName - The snapshot name (optional)
* beNameProperties - The properties to use when creating
* the BE (optional)
*
* Returns a pointer to a python object. That Python object will consist of
* the return code and optional attributes, trgtBeName and snapshotName
* BE_SUCCESS, [trgtBeName], [trgtSnapName] - Success
* 1, [trgtBeName], [trgtSnapName] - Failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
char *trgtBeName = NULL;
char *srcSnapName = NULL;
char *trgtSnapName = NULL;
char *beDescription = NULL;
Py_ssize_t pos = 0;
int ret = BE_PY_SUCCESS;
}
}
if (beNameProperties != NULL) {
(void) printf("nvlist_alloc failed.\n");
}
PyString_AsString(pvalue))) {
}
}
}
beProps) != 0) {
}
if (trgtBeName == NULL) {
/*
* Caller wants to get back the BE_ATTR_NEW_BE_NAME and
* BE_ATTR_SNAP_NAME
*/
}
/*
* When no trgtBeName is passed to be_copy, be_copy
* returns an auto generated beName and snapshot name.
*/
&trgtBeName) != 0) {
}
&trgtSnapName) != 0) {
}
return (retVals);
} else {
}
}
/*
* Function: beList
* Description: Convert Python args to nvlist pairs and call libbe:be_list
* to gather information about Boot Environments
* Parameters:
* args - pointer to a python object containing:
* beName - The name of the BE to list (optional)
*
* Returns a pointer to a python object. That Python object will consist of
* the return code and a list of Dicts or NULL.
* BE_PY_SUCCESS, listOfDicts - Success
* bePyErr or be_errno_t, NULL - Failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
int ret = BE_PY_SUCCESS;
goto done;
}
goto done;
}
goto done;
}
goto done;
}
/* LINTED */
goto done;
}
/* LINTED */
goto done;
}
/* LINTED */
goto done;
}
/* LINTED */
goto done;
}
/* LINTED */
goto done;
}
/* LINTED */
}
/* LINTED */
goto done;
}
/* LINTED */
goto done;
}
/* LINTED */
goto done;
}
/* LINTED */
}
}
done:
}
/*
* Function: beActivate
* Description: Convert Python args to nvlist pairs and call libbe:be_activate
* to activate a Boot Environment
* Parameters:
* args - pointer to a python object containing:
* beName - The name of the BE to activate
*
* Returns a pointer to a python object:
* BE_SUCCESS - Success
* bePyErr or be_errno_t - Failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
int ret = BE_PY_SUCCESS;
}
}
}
}
/*
* Function: beDestroy
* Description: Convert Python args to nvlist pairs and call libbe:be_destroy
* to destroy a Boot Environment
* Parameters:
* args - pointer to a python object containing:
* beName - The name of the BE to destroy
*
* Returns a pointer to a python object:
* BE_SUCCESS - Success
* bePyErr or be_errno_t - Failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
int destroy_snaps = 0;
int force_unmount = 0;
int destroy_flags = 0;
int ret = BE_PY_SUCCESS;
&force_unmount)) {
}
if (destroy_snaps == 1)
if (force_unmount == 1)
}
!= 0) {
(void) printf("nvlist_add_uint16 failed for "
"BE_ATTR_DESTROY_FLAGS (%d).\n", destroy_flags);
}
}
}
/*
* Function: beDestroySnapshot
* Description: Convert Python args to nvlist pairs and call libbe:be_destroy
* to destroy a snapshot of a Boot Environment
* Parameters:
* args - pointer to a python object containing:
* beName - The name of the BE to destroy
* snapName - The name of the snapshot to destroy
*
* Returns a pointer to a python object:
* BE_SUCCESS - Success
* bePyErr or be_errno_t - Failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
int ret = BE_PY_SUCCESS;
}
}
}
}
/*
* Function: beRename
* Description: Convert Python args to nvlist pairs and call libbe:be_rename
* to rename a Boot Environment
* Parameters:
* args - pointer to a python object containing:
* oldBeName - The name of the old Boot Environment
* newBeName - The name of the new Boot Environment
*
* Returns a pointer to a python object:
* BE_SUCCESS - Success
* bePyErr or be_errno_t - Failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
int ret = BE_PY_SUCCESS;
}
}
}
}
/*
* Function: beMount
* Description: Convert Python args to nvlist pairs and call libbe:be_mount
* to mount a Boot Environment
* Parameters:
* args - pointer to a python object containing:
* beName - The name of the Boot Environment to mount
* mountpoint - The path of the mountpoint to mount the
* Boot Environment on (optional)
*
* Returns a pointer to a python object:
* BE_SUCCESS - Success
* bePyErr or be_errno_t - Failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
char *mountpoint = NULL;
int ret = BE_PY_SUCCESS;
}
}
}
}
/*
* Function: beUnmount
* Description: Convert Python args to nvlist pairs and call libbe:be_unmount
* to unmount a Boot Environment
* Parameters:
* args - pointer to a python object containing:
* beName - The name of the Boot Environment to unmount
*
* Returns a pointer to a python object:
* BE_SUCCESS - Success
* bePyErr or be_errno_t - Failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
int force_unmount = 0;
int unmount_flags = 0;
int ret = BE_PY_SUCCESS;
}
if (force_unmount == 1)
}
!= 0) {
(void) printf("nvlist_add_uint16 failed for "
"BE_ATTR_UNMOUNT_FLAGS (%d).\n", unmount_flags);
}
}
}
/*
* Function: beRollback
* Description: Convert Python args to nvlist pairs and call libbe:be_rollback
* to rollback a Boot Environment to a previously taken
* snapshot.
* Parameters:
* args - pointer to a python object containing:
* beName - The name of the Boot Environment to unmount
*
* Returns a pointer to a python object:
* BE_SUCCESS - Success
* bePyErr or be_errno_t - Failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
int ret = BE_PY_SUCCESS;
}
}
}
}
/*
* Function: bePrintErrors
* Description: Convert Python args to boolean and call libbe_print_errors to
* Parameter:
* args - pointer to a python object containing:
* print_errors - Boolean that turns library error
* printing on or off.
* Parameters:
* args - pointer to a python object containing:
* 0 - do not print errors - Python boolean "False"
* 1 - print errors - Python boolean "True"
*
* Returns 1 on missing or invalid argument, 0 otherwise
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
int print_errors;
}
/*
* Function: beGetErrDesc
* Description: Convert Python args to an int and call be_err_to_str to
* map an error code to an error string.
* Parameter:
* args - pointer to a python object containing:
* errCode - value to map to an error string.
*
* Returns: error string or NULL
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
int errCode = 0;
}
/*
* First check libbe_py errors. If NULL is returned check error codes
* in libbe.
*/
}
}
/*
* Function: beVerifyBEName
* Description: Call be_valid_be_name() to verify the BE name.
* Parameter:
* args - pointer to a python object containing:
* string - value to map to a string.
*
* Returns: 0 for success or 1 for failure
* Scope:
* Public
*/
/* ARGSUSED */
PyObject *
{
}
if (be_valid_be_name(string)) {
return (Py_BuildValue("i", 0));
} else {
}
}
/* ~~~~~~~~~~~~~~~~~ */
/* Private Functions */
/* ~~~~~~~~~~~~~~~~~ */
static boolean_t
{
return (B_FALSE);
}
}
return (B_FALSE);
}
}
return (B_FALSE);
}
}
return (B_FALSE);
}
return (B_FALSE);
}
return (B_FALSE);
}
if (be->be_space_used != 0) {
return (B_FALSE);
}
}
return (B_FALSE);
}
}
return (B_FALSE);
}
}
return (B_FALSE);
}
}
return (B_FALSE);
}
}
return (B_TRUE);
}
static boolean_t
{
return (B_FALSE);
}
}
return (B_FALSE);
}
return (B_FALSE);
}
}
return (B_FALSE);
}
if (ds->be_ds_space_used != 0) {
!= 0) {
return (B_FALSE);
}
}
if (ds->be_dataset_name != 0) {
return (B_FALSE);
}
}
return (B_FALSE);
}
}
return (B_FALSE);
}
}
return (B_TRUE);
}
static boolean_t
{
return (B_FALSE);
}
}
return (B_FALSE);
}
}
return (B_FALSE);
}
}
if (ss->be_snapshot_space_used != 0) {
!= 0) {
return (B_FALSE);
}
}
return (B_TRUE);
}
/*
* Convert string arguments to nvlist attributes
*/
static boolean_t
{
int i;
(void) printf("nvlist_alloc failed.\n");
return (B_FALSE);
}
}
for (i = 0; i < numArgs; i += 2) {
continue;
}
(void) printf("nvlist_add_string failed for %s (%s).\n",
return (B_FALSE);
}
}
return (B_TRUE);
}
/*
* Function: beMapLibbePyErrorToString
* Description: Convert Python args to an int and map an error code to an
* error string.
* Parameter:
* errCode - value to map to an error string.
*
* Returns error string or NULL
* Scope:
* Public
*/
char *
{
switch (errCode) {
case BE_PY_ERR_APPEND:
return ("Unable to append a dictionary to a list "
"of dictinaries.");
case BE_PY_ERR_DICT:
return ("Creation of a Python dictionary failed.");
case BE_PY_ERR_LIST:
return ("beList() failed.");
case BE_PY_ERR_NVLIST:
return ("An nvlist operation failed.");
case BE_PY_ERR_PARSETUPLE:
return ("PyArg_ParseTuple() failed to convert variable to C.");
case BE_PY_ERR_PRINT_ERR:
return ("bePrintErrors() failed.");
case BE_PY_ERR_VAR_CONV:
return ("Unable to add variables to a Python dictionary.");
default:
return (NULL);
}
}
/* Private python initialization structure */
static struct PyMethodDef libbeMethods[] = {
"Create a snapshot."},
"Destroy a snapshot."},
"Map Error codes to strings."},
"Verify BE name."},
};
void
{
/* PyMODINIT_FUNC; */
}