Adding networkCreateXML, networkDestroy, networkIsActive and
networkLookupByName.
In the function phypCreateNetwork I just use the def-domain information to
create
the new network interface because of the behaviour of the HMC and the
hypervisor:
* HMC can't simply create a network interface without assigning it to a
specific
LPAR.
* I also can't assign an IP addr or any other information from the HMC or
VIOS
side, but I can control in which vlan or vswitch it will be attached - but
thought just in the simplest case scenarion now, I'll make some
improvements
in the future.
That's why I used a very simple XML for testing:
network
uuid3e3fce45-4f53-4fa7-bb32-11f34168b82b/uuid
domain name=LPAR01 /
namewhatever/name
bridge name=whatever /
/network
The only information I really need is the domain name which I'll assign the
created
network interface. Name, MAC Addr MUST be created automatically by the
hypervisor,
they're all unique. I had to put those two other tags name and bridge so
the
function virNetworkDefParseString can return successfully, otherwise it would
say
that the XML is malformed.
---
src/phyp/phyp_driver.c | 400 +++-
src/phyp/phyp_driver.h |2 +-
2 files changed, 396 insertions(+), 6 deletions(-)
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index c44fc69..244561e 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2010 Red Hat, Inc.
- * Copyright IBM Corp. 2009
+ * Copyright IBM Corp. 2010
*
* phyp_driver.c: ssh layer to access Power Hypervisors
*
@@ -2829,6 +2829,396 @@ phypGetStoragePoolXMLDesc(virStoragePoolPtr pool,
unsigned int flags)
return NULL;
}
+static int
+networkDestroy(virNetworkPtr net)
+{
+ConnectionData *connection_data = net-conn-networkPrivateData;
+phyp_driverPtr phyp_driver = net-conn-privateData;
+LIBSSH2_SESSION *session = connection_data-session;
+virBuffer buf = VIR_BUFFER_INITIALIZER;
+uuid_nettablePtr uuid_nettable = phyp_driver-uuid_nettable;
+char *managed_system = phyp_driver-managed_system;
+int system_type = phyp_driver-system_type;
+int exit_status = 0;
+int slot_num = 0;
+char *char_ptr;
+char *cmd = NULL;
+char *ret = NULL;
+unsigned int i = 0;
+int lpar_id = 0;
+long long mac = 0;
+
+for (i = 0; i uuid_nettable-nnets; i++) {
+if (STREQ(uuid_nettable-nets[i]-name, net-name)) {
+mac = uuid_nettable-nets[i]-mac;
+break;
+}
+}
+
+/* Getting the LPAR ID */
+
+virBufferAddLit(buf, lshwres );
+if (system_type == HMC)
+virBufferVSprintf(buf, -m %s , managed_system);
+
+virBufferVSprintf(buf,
+ -r virtualio --rsubtype slot --level slot
+ -F drc_name,lpar_id|grep %s|
+ sed -e 's/^.*,//g', net-name);
+
+if (virBufferError(buf)) {
+virBufferFreeAndReset(buf);
+virReportOOMError();
+return -1;
+}
+cmd = virBufferContentAndReset(buf);
+
+ret = phypExec(session, cmd, exit_status, net-conn);
+
+if (exit_status 0 || ret == NULL)
+goto err;
+
+if (virStrToLong_i(ret, char_ptr, 10, lpar_id) == -1)
+goto err;
+
+/* Getting the remote slot number */
+
+virBufferAddLit(buf, lshwres );
+if (system_type == HMC)
+virBufferVSprintf(buf, -m %s , managed_system);
+
+virBufferVSprintf(buf,
+ -r virtualio --rsubtype eth --level lpar
+ -F mac_addr,slot_num|grep %lld|
+ sed -e 's/^.*,//g', mac);
+
+if (virBufferError(buf)) {
+virBufferFreeAndReset(buf);
+virReportOOMError();
+return -1;
+}
+cmd = virBufferContentAndReset(buf);
+
+ret = phypExec(session, cmd, exit_status, net-conn);
+
+if (exit_status 0 || ret == NULL)
+goto err;
+
+if (virStrToLong_i(ret, char_ptr, 10, slot_num) == -1)
+goto err;
+
+/* excluding interface */
+
+virBufferAddLit(buf, chhwres );
+if (system_type == HMC)
+virBufferVSprintf(buf, -m %s , managed_system);
+
+virBufferVSprintf(buf,
+ -r virtualio --rsubtype eth
+ --id %d -o r -s %d, lpar_id, slot_num);
+
+if (virBufferError(buf)) {
+virBufferFreeAndReset(buf);
+virReportOOMError();
+return -1;
+}
+cmd = virBufferContentAndReset(buf);
+
+ret = phypExec(session, cmd, exit_status, net-conn);
+
+if (exit_status 0 || ret != NULL)
+goto err;
+
+if (phypUUIDTable_RemNetwork(net-conn, mac) 0)
+goto err;
+
+VIR_FREE(cmd);
+VIR_FREE(ret);
+return 0;
+
+ err:
+VIR_FREE(cmd);
+VIR_FREE(ret);
+return -1;
+}
+
+static virNetworkPtr
+phypCreateNetwork(virConnectPtr conn, const char *xml)