You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by jf...@apache.org on 2013/10/25 21:55:45 UTC

svn commit: r1535845 - in /vcl/trunk/web/.ht-inc: conf-default.php images.php utils.php xmlrpcWrappers.php

Author: jfthomps
Date: Fri Oct 25 19:55:44 2013
New Revision: 1535845

URL: http://svn.apache.org/r1535845
Log:
VCL-409
Improvements to vcld -setup

utils.php - modified xmlrpccall - added line to register XMLRPCfinishBaseImageCapture
xmlrpcWrappers.php - added XMLRPCfinishBaseImageCapture
images.php - modified addImage - split permission, grouping, and mapping out into new function named addImagePermissions so that it can be called by an XMLRPC function


Modified:
    vcl/trunk/web/.ht-inc/conf-default.php
    vcl/trunk/web/.ht-inc/images.php
    vcl/trunk/web/.ht-inc/utils.php
    vcl/trunk/web/.ht-inc/xmlrpcWrappers.php

Modified: vcl/trunk/web/.ht-inc/conf-default.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/conf-default.php?rev=1535845&r1=1535844&r2=1535845&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/conf-default.php (original)
+++ vcl/trunk/web/.ht-inc/conf-default.php Fri Oct 25 19:55:44 2013
@@ -98,6 +98,8 @@ define("ALLOWADDSHIBUSERS", 0); // this 
 
 $ENABLE_ITECSAUTH = 0;     // use ITECS accounts (also called "Non-NCSU" accounts)
 
+# xmlrpcBlockAPIUsers is an array of ids from user table for users that are
+# allowed to call XMLRPC functions designed specifically to be called by vcld
 $xmlrpcBlockAPIUsers = array(3, # 3 = vclsystem
 );
 

Modified: vcl/trunk/web/.ht-inc/images.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/images.php?rev=1535845&r1=1535844&r2=1535845&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/images.php (original)
+++ vcl/trunk/web/.ht-inc/images.php Fri Oct 25 19:55:44 2013
@@ -3405,13 +3405,36 @@ function addImage($data) {
 	$row = mysql_fetch_row($qh);
 	$resourceid = $row[0];
 
-	if(strncmp($OSs[$data['osid']]['name'], 'vmware', 6) == 0)
-		$vmware = 1;
+	$installtype = $OSs[$data['osid']]['installtype'];
+	if($installtype == 'none' ||
+	   $installtype == 'partimage' ||
+	   $installtype == 'kickstart')
+		$virtual = 0;
 	else
-		$vmware = 0;
+		$virtual = 1;
 
+	addImagePermissions($ownerdata, $resourceid, $virtual);
+
+	return $imageid;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn addImagePermissions($ownerdata, $resourceid, $virtual)
+///
+/// \param $ownerdata - array of data returned from getUserInfo for the owner of
+/// the image
+/// \param $resourceid - id from resource table for the image
+/// \param $virtual - (bool) 0 if bare metal image, 1 if virtual
+///
+/// \brief sets up permissions, grouping, and mapping for the owner of the image
+/// to be able to make a reservation for it
+///
+////////////////////////////////////////////////////////////////////////////////
+function addImagePermissions($ownerdata, $resourceid, $virtual) {
+	$ownerid = $ownerdata['id'];
 	// create new node if it does not exist
-	if($vmware)
+	if($virtual)
 		$nodename = 'newvmimages';
 	else
 		$nodename = 'newimages';
@@ -3460,7 +3483,7 @@ function addImage($data) {
 	$qh = doQuery($query, 101);
 	$row = mysql_fetch_assoc($qh);
 	$ownergroupid = $row['id'];
-	if($vmware)
+	if($virtual)
 		$prefix = 'newvmimages';
 	else
 		$prefix = 'newimages';
@@ -3486,7 +3509,7 @@ function addImage($data) {
 		$resourcegroupid = $row[0];
 
 		// map group to newimages/newvmimages comp group
-		if($vmware)
+		if($virtual)
 			$rgroupname = 'newvmimages';
 		else
 			$rgroupname = 'newimages';
@@ -3511,7 +3534,7 @@ function addImage($data) {
 
 	// make image group available at new node
 	$adds = array('available', 'administer');
-	if($vmware)
+	if($virtual)
 		updateResourcePrivs("image/newvmimages-{$ownerdata['login']}-$ownerid", $newnode, $adds, array());
 	else
 		updateResourcePrivs("image/newimages-{$ownerdata['login']}-$ownerid", $newnode, $adds, array());
@@ -3521,8 +3544,6 @@ function addImage($data) {
 	       . "(resourceid, resourcegroupid) "
 	       . "VALUES ($resourceid, $resourcegroupid)";
 	doQuery($query, 101);
-
-	return $imageid;
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: vcl/trunk/web/.ht-inc/utils.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/utils.php?rev=1535845&r1=1535844&r2=1535845&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/utils.php (original)
+++ vcl/trunk/web/.ht-inc/utils.php Fri Oct 25 19:55:44 2013
@@ -9841,6 +9841,7 @@ function xmlrpccall() {
 	xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCgetGroupImages", "xmlRPChandler");
 	xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCaddImageGroupToComputerGroup", "xmlRPChandler");
 	xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCremoveImageGroupFromComputerGroup", "xmlRPChandler");
+	xmlrpc_server_register_method($xmlrpc_handle, "XMLRPCfinishBaseImageCapture", "xmlRPChandler");
 
 	print xmlrpc_server_call_method($xmlrpc_handle, $HTTP_RAW_POST_DATA, '');
 	xmlrpc_server_destroy($xmlrpc_handle);

Modified: vcl/trunk/web/.ht-inc/xmlrpcWrappers.php
URL: http://svn.apache.org/viewvc/vcl/trunk/web/.ht-inc/xmlrpcWrappers.php?rev=1535845&r1=1535844&r2=1535845&view=diff
==============================================================================
--- vcl/trunk/web/.ht-inc/xmlrpcWrappers.php (original)
+++ vcl/trunk/web/.ht-inc/xmlrpcWrappers.php Fri Oct 25 19:55:44 2013
@@ -3505,4 +3505,69 @@ function XMLRPCprocessBlockTime($blockTi
 	$return['unallocated'] = $rqdata['numMachines'] - $return['allocated'];
 	return $return;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \fn XMLRPCfinishBaseImageCapture($ownerid, $resourceid, $virtual=1)
+///
+/// \param $ownerdata - array of data returned from getUserInfo for the owner of
+/// the image
+/// \param $resourceid - id from resource table for the image
+/// \param $virtual - (bool) 0 if bare metal image, 1 if virtual
+///
+/// \return an array with at least one index named 'status' which will have
+/// one of these values\n
+/// \b error - error occurred; there will be 2 additional elements in the array:
+/// \li \b errorcode - error number\n
+/// \li \b errormsg - error string\n
+///
+/// \b success - the permissions, groupings, and mappings were set up
+/// successfully
+///
+/// \brief calls addImagePermissions to create and set up permissions,
+/// groupings, and mappings so that the owner of a new base image will be able
+/// to make a reservation for it after capturing it using 'vcld -setup';
+/// specifically designed to be called by vcld as part of the process of
+/// capturing a new base image
+///
+////////////////////////////////////////////////////////////////////////////////
+function XMLRPCfinishBaseImageCapture($ownerid, $resourceid, $virtual=1) {
+	global $user, $xmlrpcBlockAPIUsers;
+	if(! in_array($user['id'], $xmlrpcBlockAPIUsers)) {
+		return array('status' => 'error',
+		             'errorcode' => 89,
+		             'errormsg' => 'access denied for call to XMLRPCfinishBaseImageCapture');
+	}
+	if(! is_numeric($ownerid)) {
+		return array('status' => 'error',
+		             'errorcode' => 90,
+		             'errormsg' => 'Invalid ownerid submitted');
+	}
+	if(! is_numeric($resourceid)) {
+		return array('status' => 'error',
+		             'errorcode' => 91,
+		             'errormsg' => 'Invalid resourceid submitted');
+	}
+	$ownerdata = getUserInfo($ownerid, 1, 1);
+	if(is_null($ownerdata) || empty($ownerdata)) {
+		return array('status' => 'error',
+		             'errorcode' => 90,
+		             'errormsg' => 'Invalid ownerid passed as second argument');
+	}
+	$query = "SELECT i.id "
+	       . "FROM image i, "
+	       .      "resource r "
+	       . "WHERE r.id = $resourceid AND "
+	       .       "r.subid = i.id AND "
+	       .       "r.resourcetypeid = 13";
+	$qh = doQuery($query);
+	if(mysql_num_rows($qh) != 1) {
+		return array('status' => 'error',
+		             'errorcode' => 91,
+		             'errormsg' => 'Invalid resourceid submitted');
+	}
+	require_once(".ht-inc/images.php");
+	addImagePermissions($ownerdata, $resourceid, $virtual);
+	return array('status' => 'success');
+}
 ?>