ä 2011å02æ22æ 16:39, Michal Novotny åé: > On 02/22/2011 09:05 AM, Lyre wrote: >> Added the following functions for storagepool: >> >> * string libvirt_storagepool_get_uuid_string (resource $connection) >> return the uuid string or false on failure. >> >> * string libvirt_storagepool_get_name (resource $pool) >> return the name or false on failure. >> >> * resource libvirt_storagepool_lookup_by_uuid_string (resource >> $connection, string $uuid_string) >> return the storagepool resource or false on failure. >> >> * string libvirt_storagepool_get_xml_desc (resource $pool [, interger >> $flags]) >> return the xml description or false on failure. >> >> * resource libvirt_storagepool_define_xml (resource $connection, >> string $xml [, integer $flags]) >> return the resource defined by the xml, or false on failure. >> >> * bool libvirt_storagepool_undefine (resource $pool) >> return ture on success or false on failure. >> >> * bool libvirt_storagepool_create (resource $pool) >> return ture on success or false on failure. >> >> * bool libvirt_storagepool_destroy (resource $pool) >> return ture on success or false on failure. >> >> * integer libvirt_storagepool_is_active (resource $pool) >> return 1, 0, and -1 indicates true, false, and failure. >> >> * integer libvirt_storagepool_get_volume_count (resource $pool) >> return the number of volumes in the storagepool, or -1 on failure. >> >> * bool libvirt_storagepool_refresh (resource $pool [, integer $flags]) >> return ture on success or false on failure. >> >> * bool libvirt_storagepool_set_autostart (resource $pool, bool >> $autostart) >> return ture on success or false on failure. >> >> * integer libvirt_storagepool_get_autostart (resource $pool) >> return 1, 0, and -1 indicates true, false, and failure. >> >> modified: src/libvirt.c >> modified: src/php_libvirt.h >> --- >> src/libvirt.c | 226 >> +++++++++++++++++++++++++++++++++++++++++++++++++++++ >> src/php_libvirt.h | 13 +++ >> 2 files changed, 239 insertions(+), 0 deletions(-) >> >> diff --git a/src/libvirt.c b/src/libvirt.c >> index 748d898..6e39c99 100644 >> --- a/src/libvirt.c >> +++ b/src/libvirt.c >> @@ -78,6 +78,19 @@ static function_entry libvirt_functions[] = { >> PHP_FE(libvirt_storagepool_lookup_by_name,NULL) >> PHP_FE(libvirt_storagepool_list_volumes,NULL) >> PHP_FE(libvirt_storagepool_get_info,NULL) >> + PHP_FE(libvirt_storagepool_get_uuid_string, NULL) >> + PHP_FE(libvirt_storagepool_get_name, NULL) >> + PHP_FE(libvirt_storagepool_lookup_by_uuid_string, NULL) >> + PHP_FE(libvirt_storagepool_get_xml_desc, NULL) >> + PHP_FE(libvirt_storagepool_define_xml, NULL) >> + PHP_FE(libvirt_storagepool_undefine, NULL) >> + PHP_FE(libvirt_storagepool_create, NULL) >> + PHP_FE(libvirt_storagepool_destroy, NULL) >> + PHP_FE(libvirt_storagepool_is_active, NULL) >> + PHP_FE(libvirt_storagepool_get_volume_count, NULL) >> + PHP_FE(libvirt_storagepool_refresh, NULL) >> + PHP_FE(libvirt_storagepool_set_autostart, NULL) >> + PHP_FE(libvirt_storagepool_get_autostart, NULL) >> PHP_FE(libvirt_storagevolume_lookup_by_name,NULL) >> PHP_FE(libvirt_storagevolume_get_info,NULL) >> PHP_FE(libvirt_storagevolume_get_xml_desc,NULL) >> @@ -887,8 +900,221 @@ PHP_FUNCTION(libvirt_storagepool_get_info) >> add_assoc_long(return_value, "available", poolInfo.available); >> } >> >> +PHP_FUNCTION(libvirt_storagepool_get_uuid_string) >> +{ >> + php_libvirt_storagepool *pool=NULL; >> + zval *zpool; >> + char *uuid; >> + >> + GET_STORAGEPOOL_FROM_ARGS ("r",&zpool); >> + >> + uuid = emalloc (VIR_UUID_STRING_BUFLEN); >> + if (virStoragePoolGetUUIDString (pool->pool, uuid) != 0) >> + { >> + RETURN_FALSE; >> + } >> + >> + RETURN_STRING(uuid, 0); >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_get_name) >> +{ >> + php_libvirt_storagepool *pool = NULL; >> + zval *zpool; >> + const char *name=NULL; >> + >> + GET_STORAGEPOOL_FROM_ARGS("r",&zpool); >> + >> + name = virStoragePoolGetName (pool->pool); >> + if (name == NULL) >> + { >> + RETURN_FALSE; >> + } >> + >> + RETURN_STRING(name, 1); >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_lookup_by_uuid_string) >> +{ >> + php_libvirt_connection *conn = NULL; >> + zval *zconn; >> + char *uuid = NULL; >> + int uuid_len; >> + virStoragePoolPtr storage=NULL; >> + php_libvirt_storagepool *res_pool; >> + >> + GET_CONNECTION_FROM_ARGS("rs",&zconn,&uuid,&uuid_len); >> + >> + if ((uuid == NULL) || (uuid_len< 1)) >> + { >> + RETURN_FALSE; >> + } >> + storage = virStoragePoolLookupByUUIDString (conn->conn, uuid); >> + if (storage == NULL) >> + { >> + RETURN_FALSE; >> + } >> + >> + res_pool = emalloc (sizeof (php_libvirt_storagepool)); >> + res_pool->pool = storage; >> + >> + ZEND_REGISTER_RESOURCE (return_value, res_pool, >> le_libvirt_storagepool); >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_get_xml_desc) >> +{ >> + php_libvirt_storagepool *pool = NULL; >> + zval *zpool; >> + char *xml; >> + char *xml_out; >> + long flags = 0; >> + >> + GET_STORAGEPOOL_FROM_ARGS("r|l",&zpool,&flags); >> + >> + xml = virStoragePoolGetXMLDesc (pool->pool, flags); >> + if (xml == NULL) >> + { >> + RETURN_FALSE; >> + } >> + >> + RECREATE_STRING_WITH_E (xml_out, xml); >> + RETURN_STRING (xml_out, 1); >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_define_xml) >> +{ >> + php_libvirt_storagepool *res_pool = NULL; >> + php_libvirt_connection *conn = NULL; >> + zval *zconn; >> + virStoragePoolPtr pool = NULL; >> + char *xml; >> + int xml_len; >> + long flags = 0; >> + >> + >> + GET_CONNECTION_FROM_ARGS ("rs|l",&zconn,&xml,&xml_len,&flags); >> + >> + pool = virStoragePoolDefineXML (conn->conn, xml, (unsigned int)flags); >> + if (pool == NULL) >> + { >> + RETURN_FALSE; >> + } >> + >> + res_pool = emalloc (sizeof (php_libvirt_storagepool)); >> + res_pool->pool = pool; >> + >> + ZEND_REGISTER_RESOURCE (return_value, res_pool, >> le_libvirt_storagepool); >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_undefine) >> +{ >> + php_libvirt_storagepool *pool = NULL; >> + zval *zpool; >> + >> + GET_STORAGEPOOL_FROM_ARGS ("r",&zpool); >> + >> + if (virStoragePoolUndefine (pool->pool) != 0) >> + { >> + RETURN_FALSE; >> + } >> + RETURN_TRUE; >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_create) >> +{ >> + php_libvirt_storagepool *pool = NULL; >> + zval *zpool; >> + >> + GET_STORAGEPOOL_FROM_ARGS ("r",&zpool); >> + >> + if (virStoragePoolCreate (pool->pool, 0) != 0) >> + { >> + RETURN_FALSE; >> + } >> + RETURN_TRUE; >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_destroy) >> +{ >> + php_libvirt_storagepool *pool = NULL; >> + zval *zpool; >> + >> + GET_STORAGEPOOL_FROM_ARGS ("r",&zpool); >> + >> + if (virStoragePoolDestroy (pool->pool) != 0) >> + { >> + RETURN_FALSE; >> + } >> + RETURN_TRUE; >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_is_active) >> +{ >> + php_libvirt_storagepool *pool = NULL; >> + zval *zpool; >> + >> + GET_STORAGEPOOL_FROM_ARGS ("r",&zpool); >> + >> + RETURN_LONG (virStoragePoolIsActive (pool->pool)); >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_get_volume_count) >> +{ >> + php_libvirt_storagepool *pool = NULL; >> + zval *zpool; >> >> + GET_STORAGEPOOL_FROM_ARGS ("r",&zpool); >> >> + RETURN_LONG (virStoragePoolNumOfVolumes(pool->pool)); >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_refresh) >> +{ >> + php_libvirt_storagepool *pool = NULL; >> + zval *zpool; >> + unsigned long flags = 0; >> + >> + GET_STORAGEPOOL_FROM_ARGS ("rl",&zpool,&flags); >> + >> + if (virStoragePoolRefresh (pool->pool, flags)< 0) >> + { >> + RETURN_FALSE; >> + } >> + RETURN_TRUE; >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_set_autostart) >> +{ >> + php_libvirt_storagepool *pool = NULL; >> + zval *zpool; >> + zend_bool flags = 0; >> + >> + GET_STORAGEPOOL_FROM_ARGS ("rb",&zpool,&flags); >> + >> + if (virStoragePoolSetAutostart (pool->pool, flags) != 0) >> + { >> + RETURN_FALSE; >> + } >> + RETURN_TRUE; >> +} >> + >> +PHP_FUNCTION(libvirt_storagepool_get_autostart) >> +{ >> + php_libvirt_storagepool *pool = NULL; >> + zval *zpool; >> + int flags = 0; >> + >> + GET_STORAGEPOOL_FROM_ARGS ("r",&zpool); >> + >> + if (virStoragePoolGetAutostart (pool->pool,&flags) == 0) >> + { >> + RETURN_LONG ((long)flags); >> + } >> + else >> + { >> + RETURN_LONG (-1); >> + } >> +} >> >> PHP_FUNCTION(libvirt_storagevolume_lookup_by_name) >> { >> diff --git a/src/php_libvirt.h b/src/php_libvirt.h >> index 213d27f..64fb9d0 100644 >> --- a/src/php_libvirt.h >> +++ b/src/php_libvirt.h >> @@ -122,6 +122,19 @@ PHP_FUNCTION(libvirt_list_storagepools); >> PHP_FUNCTION(libvirt_storagepool_lookup_by_name); >> PHP_FUNCTION(libvirt_storagepool_list_volumes); >> PHP_FUNCTION(libvirt_storagepool_get_info); >> +PHP_FUNCTION(libvirt_storagepool_get_uuid_string); >> +PHP_FUNCTION(libvirt_storagepool_get_name); >> +PHP_FUNCTION(libvirt_storagepool_lookup_by_uuid_string); >> +PHP_FUNCTION(libvirt_storagepool_get_xml_desc); >> +PHP_FUNCTION(libvirt_storagepool_define_xml); >> +PHP_FUNCTION(libvirt_storagepool_undefine); >> +PHP_FUNCTION(libvirt_storagepool_create); >> +PHP_FUNCTION(libvirt_storagepool_destroy); >> +PHP_FUNCTION(libvirt_storagepool_is_active); >> +PHP_FUNCTION(libvirt_storagepool_get_volume_count); >> +PHP_FUNCTION(libvirt_storagepool_refresh); >> +PHP_FUNCTION(libvirt_storagepool_set_autostart); >> +PHP_FUNCTION(libvirt_storagepool_get_autostart); >> PHP_FUNCTION(libvirt_storagevolume_lookup_by_name); >> PHP_FUNCTION(libvirt_storagevolume_get_info); >> PHP_FUNCTION(libvirt_storagevolume_get_xml_desc); > Thanks! Applied and pushed to the repo. Should be fine to catch_error > to catch libvirt error from the function to set the last error. > > Michal > I'll take a look at it. Michal, I noticed you added comments for functions, so they'll be automatically generated? How is it done? And, did you noticed a patch from me yesterday, which added three functions for domain. -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list