diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 9dcc69c2539..ba1094d2c0d 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -3971,9 +3971,19 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe protected boolean getHostInfo(Connection conn) throws IllegalArgumentException{ try { Host myself = Host.getByUuid(conn, _host.uuid); + Set hcs = null; + for (int i = 0; i < 10; i++) { + hcs = myself.getHostCPUs(conn); + _host.cpus = hcs.size(); + if (_host.cpus > 0) { + break; + } + Thread.sleep(5000); + } + if (_host.cpus <= 0) { + throw new CloudRuntimeException("Cannot get the numbers of cpu from XenServer host " + _host.ip); + } - Set hcs = myself.getHostCPUs(conn); - _host.cpus = hcs.size(); for (final HostCpu hc : hcs) { _host.speed = hc.getSpeed(conn).intValue(); break; @@ -4047,7 +4057,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } catch (XenAPIException e) { s_logger.warn("Unable to get host information for " + _host.ip, e); return false; - } catch (XmlRpcException e) { + } catch (Exception e) { s_logger.warn("Unable to get host information for " + _host.ip, e); return false; } diff --git a/setup/db/templates.sql b/setup/db/templates.sql index 2f619eba09a..536d4792abc 100755 --- a/setup/db/templates.sql +++ b/setup/db/templates.sql @@ -204,6 +204,8 @@ INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (157, 10, INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (158, 9, 'Sun Solaris 11 (64-bit)'); INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (159, 9, 'Sun Solaris 11 (32-bit)'); INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (160, 6, 'Windows PV'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (161, 1, 'CentOS 5.7 (32-bit)'); +INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (162, 1, 'CentOS 5.7 (64-bit)'); INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (200, 1, 'Other CentOS (32-bit)'); INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (201, 1, 'Other CentOS (64-bit)'); diff --git a/test/src/com/cloud/test/demo/Demo.java b/test/src/com/cloud/test/demo/Demo.java index 9753c971504..bad961b06e5 100644 --- a/test/src/com/cloud/test/demo/Demo.java +++ b/test/src/com/cloud/test/demo/Demo.java @@ -58,7 +58,7 @@ public class Demo { setupHttpd(publicIp, "cloud.com"); //return web access url - System.out.println("\nURL is " + "http://" + publicIp + "/cloudcom-faq.html"); + System.out.println("\nApache server is running on " + "http://" + publicIp); } private static void readProperties() { @@ -120,9 +120,9 @@ public class Demo { } try { - System.out.println("Sleeping for 1 min before trying to ssh into linux host "); + System.out.println("\nSleeping for 1 min before trying to ssh into linux host "); Thread.sleep(60000); - System.out.println("Attempting to SSH into linux host " + host); + System.out.println("\nAttempting to SSH into linux host " + host); Connection conn = new Connection(host); conn.connect(null, 60000, 60000); @@ -137,7 +137,8 @@ public class Demo { } boolean success = false; - String linuxCommand = "yum install httpd -y && service httpd start && service iptables stop && cd /var/www/html && wget cloud.com"; + String linuxCommand = "yum install httpd -y && service httpd start && service iptables stop"; + //String linuxCommand = "yum install tomcat* -y && service iptables stop && /etc/init.d/tomcat5 start"; Session sess = conn.openSession(); System.out.println("User root executing : " + linuxCommand); @@ -186,22 +187,21 @@ public class Demo { System.out.println("ERROR: SSH Linux Network test fail with error " + e.getMessage()); System.exit(1); } - System.out.println("Httpd is setup succesfully on the user vm"); + System.out.println("Apache is setup succesfully on the user vm"); } public static String createDeployment() { + System.out.println("\nCreating cloudStack deployment..."); CloudStackHttpClient client = new CloudStackHttpClient(); - boolean success = true; //1) deployVm String urlToSign = "command=deployVirtualMachine&serviceOfferingId=" + properties.getProperty("serviceOfferingId") + "&networkIds=" + properties.getProperty("networkId") + "&templateId=" + properties.getProperty("templateId") + "&zoneId=" + properties.getProperty("zoneId") + "&response=json"; - String url = signUrl(urlToSign, properties.getProperty("apikey"), + String url = signRequest(urlToSign, properties.getProperty("apikey"), properties.getProperty("secretkey")); String requestUrl = _host + url; - System.out.println(requestUrl); CloudStackUserVm vm = client.execute(requestUrl, _apiCommands.get("deployVirtualMachine"), "deployvirtualmachineresponse", @@ -210,7 +210,7 @@ public class Demo { String vmId = null; if(vm != null){ vmId = vm.getId(); - System.out.println("Successfully deployed vm with id " + vmId); + System.out.println("\nDeployed vm with id " + vmId); } else { System.out.println("ERROR: failed to deploy the vm"); System.exit(1); @@ -218,7 +218,7 @@ public class Demo { //2) List public IP address - source nat urlToSign = "command=listPublicIpAddresses&zoneId=" + properties.getProperty("zoneId") + "&response=json"; - url = signUrl(urlToSign, properties.getProperty("apikey"), + url = signRequest(urlToSign, properties.getProperty("apikey"), properties.getProperty("secretkey")); requestUrl = _host + url; @@ -228,7 +228,7 @@ public class Demo { if (ipList.isEmpty()) { System.out.println("ERROR: account doesn't own any public ip address"); System.exit(1); - } + } CloudStackIpAddress ip = ipList.get(0); String ipId = ip.getId(); @@ -238,7 +238,7 @@ public class Demo { //3) create portForwarding rules for port 22 and 80 urlToSign = "command=createPortForwardingRule&privateport=22&publicport=22&protocol=tcp&ipaddressid=" + ipId + "&virtualmachineid=" + vmId + "&response=json"; - url = signUrl(urlToSign, properties.getProperty("apikey"), + url = signRequest(urlToSign, properties.getProperty("apikey"), properties.getProperty("secretkey")); requestUrl = _host + url; CloudStackPortForwardingRule pfrule1 = client.execute(requestUrl, _apiCommands.get("createPortForwardingRule"), @@ -247,24 +247,25 @@ public class Demo { if (pfrule1 == null) { System.out.println("ERROR: failed to create pf rule for the port 22"); System.exit(1); - } else { - } urlToSign = "command=createPortForwardingRule&privateport=80&publicport=80&protocol=tcp&ipaddressid=" + ipId + "&virtualmachineid=" + vmId + "&response=json"; - url = signUrl(urlToSign, properties.getProperty("apikey"), + url = signRequest(urlToSign, properties.getProperty("apikey"), properties.getProperty("secretkey")); requestUrl = _host + url; CloudStackPortForwardingRule pfrule2 = client.execute(requestUrl, _apiCommands.get("createPortForwardingRule"), "createportforwardingruleresponse", "portforwardingrule", CloudStackPortForwardingRule.class); - if (pfrule1 == null) { + if (pfrule2 == null) { System.out.println("ERROR: failed to create pf rule for the port 80"); System.exit(1); } + System.out.println("\nCreated PF rules for ports 22 and 80 "); + System.out.println("\nCloudStack finished the deployment "); + return ipAddress; } @@ -277,25 +278,24 @@ public class Demo { mac.init(keySpec); mac.update(request.getBytes()); byte[] encryptedBytes = mac.doFinal(); - //System.out.println("HmacSHA1 hash: " + encryptedBytes); return Base64.encodeBytes(encryptedBytes); } catch (Exception ex) { - System.out.println("unable to sign request"); - ex.printStackTrace(); + System.out.println("unable to sign request due to exception " + ex.getMessage()); + System.exit(1); } return null; } - public static String signUrl(String url, String apiKey, String secretKey) { + public static String signRequest(String request, String apiKey, String secretKey) { //sorted map (sort by key) TreeMap param = new TreeMap(); - String temp = ""; + String finalRequest = ""; param.put("apikey", apiKey); //1) Parse the URL and put all parameters to sorted map - StringTokenizer str1 = new StringTokenizer (url, "&"); + StringTokenizer str1 = new StringTokenizer (request, "&"); while(str1.hasMoreTokens()) { String newEl = str1.nextToken(); StringTokenizer str2 = new StringTokenizer(newEl, "="); @@ -304,25 +304,29 @@ public class Demo { param.put(name, value); } - //2) URL encode parameters' values + //2) Go through sorted map, pull out the parameters, form the url and URL encode parameters' values Set> c = param.entrySet(); Iterator> it = c.iterator(); + boolean firstElement = true; while (it.hasNext()) { + if (!firstElement) { + finalRequest = finalRequest + "&"; + } Map.Entry me = (Map.Entry)it.next(); String key = (String) me.getKey(); String value = (String) me.getValue(); try { - temp = temp + key + "=" + URLEncoder.encode(value, "UTF-8") + "&"; + //url encode values only + finalRequest = finalRequest + key + "=" + URLEncoder.encode(value, "UTF-8"); } catch (Exception ex) { System.out.println("Unable to set parameter " + value + " for the command " + param.get("command")); System.exit(1); } - + firstElement = false; } - temp = temp.substring(0, temp.length()-1 ); //3) Lower case the request - String requestToSign = temp.toLowerCase(); + String requestToSign = finalRequest.toLowerCase(); //4) Generate the signature String signature = generateSignature(requestToSign, secretKey); @@ -337,13 +341,13 @@ public class Demo { } //6) append the signature to the url - url = temp + "&signature=" + encodedSignature; - return url; + request = finalRequest + "&signature=" + encodedSignature; + return request; } public static String getQueryAsyncCommandString(String jobId){ String req = "command=queryAsyncJobResult&response=json&jobId=" + jobId; - String url = signUrl(req, properties.getProperty("apikey"), + String url = signRequest(req, properties.getProperty("apikey"), properties.getProperty("secretkey")); String requestUrl = _host + url; return requestUrl; diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js index f9033091924..512cf678993 100644 --- a/ui/scripts/storage.js +++ b/ui/scripts/storage.js @@ -172,73 +172,93 @@ poll: pollAsyncJobResult } }, - uploadVolume: { - isHeader: true, - label: 'label.upload.volume', + + //??? + uploadVolume: { + isHeader: true, + label: 'label.upload.volume', messages: { - notification: function() { return 'label.upload.volume'; } + notification: function() { + return 'label.upload.volume'; + } }, - notification: { poll: function(args) { args.complete(); } }, - action: { - custom: cloudStack.uiCustom.uploadVolume({ - listView: $.extend(true, {}, cloudStack.sections.instances, { - listView: { - filters: false, - dataProvider: function(args) { - var searchByArgs = args.filterBy.search.value && - args.filterBy.search.value.length ? - '&name=' + args.filterBy.search.value : ''; - - $.ajax({ - url: createURL('listVirtualMachines' + searchByArgs), - data: { - page: args.page, - pageSize: pageSize, - listAll: true - }, - dataType: 'json', - async: true, - success: function(data) { - args.response.success({ - data: $.grep( - data.listvirtualmachinesresponse.virtualmachine ? - data.listvirtualmachinesresponse.virtualmachine : [], - function(instance) { - return $.inArray(instance.state, [ - 'Destroyed', 'Error', 'Stopping', 'Starting' - ]) == -1; - } - ) - }); - }, - error: function(data) { - args.response.error(parseXMLHttpResponse(data)); - } - }); - } + createForm: { + title: 'label.upload.volume', + fields: { + name: { + label: 'label.name', + validation: { required: true } + }, + availabilityZone: { + label: 'label.availability.zone', + select: function(args) { + $.ajax({ + url: createURL("listZones&available=true"), + dataType: "json", + async: true, + success: function(json) { + var items = json.listzonesresponse.zone; + args.response.success({descriptionField: 'name', data: items}); + } + }); } - }), - action: function(args) { - $.ajax({ - url: createURL('uploadVolume'), - data: { - hypervisor: 'XenServer', // Replace with instances' hypervisor - format: 'VHD', // Replace with format of uploaded volume - name: args.data.name, - url: args.data.url, - zoneid: 1 // Replace with instances' zone ID - }, - success: function(json) { - args.response.success(); - }, - error: function(json) { - args.response.error(parseXMLHttpResponse(json)); + }, + format: { + label: 'label.format', + select: function(args) { + var items = []; + items.push({ id: 'VHD', description: 'VHD' }); + items.push({ id: 'OVA', description: 'OVA' }); + items.push({ id: 'QCOW2', description: 'QCOW2' }); + args.response.success({ data: items }); + } + }, + url: { + label: 'label.url', + validation: { required: true } + } + } + }, + + action: function(args) { + var array1 = []; + array1.push("&name=" + todb(args.data.name)); + array1.push("&zoneId=" + args.data.availabilityZone); + array1.push("&format=" + args.data.format); + array1.push("&url=" + todb(args.data.url)); + + $.ajax({ + url: createURL("uploadVolume" + array1.join("")), + dataType: "json", + async: true, + success: function(json) { + debugger; + var jid = json.uploadvolumeresponse.jobid; + args.response.success( + {_custom: + {jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.volume; + }, + getActionFilter: function() { + return volumeActionfilter; + } + } } - }); + ); + }, + error: function(json) { + args.response.error(parseXMLHttpResponse(json)); } - }) + }); + }, + + notification: { + poll: pollAsyncJobResult } } + //??? + }, dataProvider: function(args) {