2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <Python.h>
2N/A#include <zone.h>
2N/A
2N/A/* ARGSUSED */
2N/Astatic PyObject *
2N/A_getzoneid(PyObject *self, PyObject *junk)
2N/A{
2N/A return (Py_BuildValue("l", getzoneid()));
2N/A}
2N/A
2N/A/* ARGSUSED */
2N/Astatic PyObject *
2N/A_getzoneidbyname(PyObject *self, PyObject *args)
2N/A{
2N/A char *zonename;
2N/A zoneid_t zid;
2N/A
2N/A if (PyArg_ParseTuple(args, "s", &zonename) == NULL) {
2N/A return (NULL);
2N/A }
2N/A
2N/A if ((zid = getzoneidbyname(zonename)) == -1) {
2N/A return (PyErr_SetFromErrno(PyExc_OSError));
2N/A }
2N/A
2N/A return (Py_BuildValue("l", zid));
2N/A}
2N/A
2N/Astatic PyObject *
2N/A_getzonenamebyid(PyObject *self, PyObject *args)
2N/A{
2N/A zoneid_t zid;
2N/A char buf[ZONENAME_MAX];
2N/A ssize_t ret;
2N/A
2N/A if (PyArg_ParseTuple(args, "l", &zid) == NULL) {
2N/A return (NULL);
2N/A }
2N/A
2N/A if ((ret = getzonenamebyid(zid, buf, ZONENAME_MAX)) == -1) {
2N/A return (PyErr_SetFromErrno(PyExc_OSError));
2N/A }
2N/A
2N/A return (Py_BuildValue("s", buf));
2N/A}
2N/A
2N/Astatic struct PyMethodDef zonesMethods[] = {
2N/A {"getzoneid", (PyCFunction)_getzoneid, METH_NOARGS,
2N/A "getzoneid() -> zoneid\n\nReturn the zone ID of the calling "
2N/A "process."},
2N/A {"getzoneidbyname", (PyCFunction)_getzoneidbyname, METH_VARARGS,
2N/A "getzoneidbyname(name) -> zoneid\n\nReturn the zone ID "
2N/A "corresponding to the named zone, if that zone is currently "
2N/A "active. If name is None, return the zone ID of the calling "
2N/A "process."},
2N/A {"getzonenamebyid", (PyCFunction)_getzonenamebyid, METH_VARARGS,
2N/A "getzonenamebyid(id) -> name\n\nReturn the zone name "
2N/A "corresponding to the given zone ID."},
2N/A {NULL, NULL, 0, NULL}
2N/A};
2N/A
2N/APyMODINIT_FUNC
2N/Ainitzones(void)
2N/A{
2N/A /* PyMODINIT_FUNC; */
2N/A (void) Py_InitModule("zones", zonesMethods);
2N/A}