From 0b33147b732e26a07d2566346908e3c0fb026dfc Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Wed, 3 Dec 2008 17:36:30 +0000 Subject: [PATCH] Use pyplnet. --- NodeManager.spec | 11 ++-- net.py | 7 +++ setup.py | 5 -- sioc.c | 160 ----------------------------------------------- 4 files changed, 13 insertions(+), 170 deletions(-) delete mode 100644 sioc.c diff --git a/NodeManager.spec b/NodeManager.spec index 69f4ec1..e0e909c 100644 --- a/NodeManager.spec +++ b/NodeManager.spec @@ -25,6 +25,8 @@ Packager: PlanetLab Central Distribution: PlanetLab %{plrelease} URL: %(echo %{url} | cut -d ' ' -f 2) +BuildArch: noarch + # Old Node Manager Obsoletes: sidewinder, sidewinder-common @@ -44,6 +46,9 @@ Requires: curl # Uses function decorators Requires: python >= 2.4 +# sioc/plnet +Requires: pyplnet >= 4.3 + %description The PlanetLab Node Manager manages all aspects of PlanetLab node and slice management once the node has been initialized and configured by @@ -95,11 +100,7 @@ rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root,-) -%doc -%dir %{_datadir}/NodeManager -%dir %{_datadir}/NodeManager/plugins -%{_datadir}/NodeManager/* -%{_datadir}/NodeManager/plugins/* +%{_datadir}/NodeManager/ %{_bindir}/forward_api_calls %{_initrddir}/nm %{_initrddir}/conf_files diff --git a/net.py b/net.py index 9628bc2..bb60f1f 100644 --- a/net.py +++ b/net.py @@ -9,8 +9,10 @@ import logger import string import iptables import os +import plnet def GetSlivers(plc, data): + InitInterfaces(plc, data) InitNodeLimit(data) InitI2(plc, data) InitNAT(plc, data) @@ -123,5 +125,10 @@ def InitNAT(plc, data): ipt.add_pf(fields) ipt.commit() +def InitInterfaces(plc, data): + if not 'networks' in data: + return + plnet.InitInterfaces(logger, plc, data) + def start(options, config): pass diff --git a/setup.py b/setup.py index 14608ca..8d00d1f 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,6 @@ setup( 'api', 'api_calls', 'bwmon', - 'codemux', 'conf_files', 'config', 'curlwrapper', @@ -32,14 +31,10 @@ setup( 'sm', 'ticket', 'tools', - 'vsys', ], scripts = [ 'forward_api_calls', ], - ext_modules=[ - Extension('sioc', ['sioc.c']), - ], packages =[ 'plugins', ], diff --git a/sioc.c b/sioc.c deleted file mode 100644 index 0ddeb31..0000000 --- a/sioc.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Extension to gather information about network interfaces - * - * Mark Huang - * Copyright (C) 2006 The Trustees of Princeton University - * - * $Id$ - */ - -#include - -/* struct ifreq */ -#include - -/* socket() */ -#include -#include - -/* ioctl() */ -#include - -/* inet_ntoa() */ -#include -#include - -/* ARPHRD_ETHER */ -#include - -/* ETH_ALEN */ -#include - -static PyObject * -gifconf(PyObject *self, PyObject *args) -{ - struct ifconf ifc; - int len; - int s; - PyObject *addrs; - void *buf; - struct ifreq *ifr; - struct sockaddr_in *sin; - - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) - return PyErr_SetFromErrno(PyExc_OSError); - - len = sizeof(struct ifreq); - ifc.ifc_len = 0; - ifc.ifc_req = NULL; - - do { - len *= 2; - buf = realloc(ifc.ifc_req, len); - if (!buf) - break; - ifc.ifc_len = len; - ifc.ifc_req = buf; - if (ioctl(s, SIOCGIFCONF, &ifc) < 0) - break; - } while (ifc.ifc_len >= len); - - close(s); - - addrs = Py_BuildValue("{}"); - - for (ifr = ifc.ifc_req, len = ifc.ifc_len; len > 0; ifr++, len -= sizeof(struct ifreq)) { - sin = (struct sockaddr_in *) &ifr->ifr_addr; - PyDict_SetItem(addrs, - Py_BuildValue("s", ifr->ifr_name), - Py_BuildValue("s", inet_ntoa(sin->sin_addr))); - } - - if (ifc.ifc_req) - free(ifc.ifc_req); - - return addrs; -} - -static PyObject * -gifaddr(PyObject *self, PyObject *args) -{ - const char *name; - struct ifreq ifr; - int s; - struct sockaddr_in *sin; - - if (!PyArg_ParseTuple(args, "s", &name)) - return NULL; - - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, name, IFNAMSIZ); - - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) - return PyErr_SetFromErrno(PyExc_OSError); - - if (ioctl(s, SIOCGIFADDR, &ifr) < 0) { - close(s); - return PyErr_SetFromErrno(PyExc_OSError); - } - - close(s); - - sin = (struct sockaddr_in *) &ifr.ifr_addr; - return Py_BuildValue("s", inet_ntoa(sin->sin_addr)); -} - -static PyObject * -gifhwaddr(PyObject *self, PyObject *args) -{ - const char *name; - struct ifreq ifr; - int s; - char mac[sizeof(ifr.ifr_hwaddr.sa_data) * 3], *c; - int len, i; - - if (!PyArg_ParseTuple(args, "s", &name)) - return NULL; - - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, name, IFNAMSIZ); - - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) - return PyErr_SetFromErrno(PyExc_OSError); - - if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { - close(s); - return PyErr_SetFromErrno(PyExc_OSError); - } - - close(s); - - switch (ifr.ifr_hwaddr.sa_family) { - case ARPHRD_ETHER: - len = ETH_ALEN; - break; - default: - len = sizeof(ifr.ifr_hwaddr.sa_data); - break; - } - - for (i = 0, c = mac; i < len; i++) { - if (i) - c += sprintf(c, ":"); - c += sprintf(c, "%02X", (unsigned char)(ifr.ifr_hwaddr.sa_data[i] & 0xFF)); - } - - return Py_BuildValue("s", mac); -} - -static PyMethodDef methods[] = { - { "gifconf", gifconf, METH_VARARGS, "Get all interface addresses" }, - { "gifaddr", gifaddr, METH_VARARGS, "Get interface address" }, - { "gifhwaddr", gifhwaddr, METH_VARARGS, "Get interface hardware address" }, - { NULL, NULL, 0, NULL } -}; - -PyMODINIT_FUNC -initsioc(void) -{ - Py_InitModule("sioc", methods); -} -- 2.43.0