mirror of https://github.com/apache/cloudstack.git
move simulator and test to opensource
This commit is contained in:
parent
ef9ab5f7a9
commit
860e259227
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/deps/cloud-log4j.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/server"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/agent"/>
|
||||
<classpathentry kind="lib" path="/deps/cloud-gson.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/core-premium"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/premium"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/agent-premium"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/console"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/console-proxy"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/console-viewer"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/setup"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/test"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/thirdparty"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/tools"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/ui"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/usage"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/vmopsClient"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/vmware-base"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>agent-simulator</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
DROP TABLE IF EXISTS `cloud`.`mockhost`;
|
||||
DROP TABLE IF EXISTS `cloud`.`mocksecstorage`;
|
||||
DROP TABLE IF EXISTS `cloud`.`mockstoragepool`;
|
||||
DROP TABLE IF EXISTS `cloud`.`mockvm`;
|
||||
DROP TABLE IF EXISTS `cloud`.`mockvolume`;
|
||||
|
||||
CREATE TABLE `cloud`.`mockhost` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`private_ip_address` char(40),
|
||||
`private_mac_address` varchar(17),
|
||||
`private_netmask` varchar(15),
|
||||
`storage_ip_address` char(40),
|
||||
`storage_netmask` varchar(15),
|
||||
`storage_mac_address` varchar(17),
|
||||
`public_ip_address` char(40),
|
||||
`public_netmask` varchar(15),
|
||||
`public_mac_address` varchar(17),
|
||||
`guid` varchar(255) UNIQUE,
|
||||
`version` varchar(40) NOT NULL,
|
||||
`data_center_id` bigint unsigned NOT NULL,
|
||||
`pod_id` bigint unsigned,
|
||||
`cluster_id` bigint unsigned COMMENT 'foreign key to cluster',
|
||||
`cpus` int(10) unsigned,
|
||||
`speed` int(10) unsigned,
|
||||
`ram` bigint unsigned,
|
||||
`capabilities` varchar(255) COMMENT 'host capabilities in comma separated list',
|
||||
`vm_id` bigint unsigned,
|
||||
`resource` varchar(255) DEFAULT NULL COMMENT 'If it is a local resource, this is the class name',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `cloud`.`mocksecstorage` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
`url` varchar(255),
|
||||
`capacity` bigint unsigned,
|
||||
`mount_point` varchar(255),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `cloud`.`mockstoragepool` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
`guid` varchar(255),
|
||||
`mount_point` varchar(255),
|
||||
`capacity` bigint,
|
||||
`pool_type` varchar(40),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
CREATE TABLE `cloud`.`mockvm` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
`name` varchar(255),
|
||||
`host_id` bigint unsigned,
|
||||
`type` varchar(40),
|
||||
`state` varchar(40),
|
||||
`vnc_port` bigint unsigned,
|
||||
`memory` bigint unsigned,
|
||||
`cpu` bigint unsigned,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
CREATE TABLE `cloud`.`mockvolume` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
`name` varchar(255),
|
||||
`size` bigint unsigned,
|
||||
`path` varchar(255),
|
||||
`pool_id` bigint unsigned,
|
||||
`type` varchar(40),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
pod_query="GET http://10.91.30.226:8096/client/?command=deletePod&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
delete_so="GET http://10.91.30.226:8096/client/?command=deleteServiceOffering&id=$x HTTP/1.0\n\n"
|
||||
|
||||
echo -e $delete_so | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
vlan_query="GET http://10.91.30.226:8096/client/?command=deleteVlanIpRange&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
zoneid=$1
|
||||
templateId=$2
|
||||
serviceOfferingId=$3
|
||||
|
||||
query="GET http://10.91.30.226:8096/client/?command=deployVirtualMachine&zoneId=$1&templateId=$2&serviceOfferingId=$3&account=admin&domainid=1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 20 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.226:8096/client/?command=listRouters&zoneId=$1&account=admin&domainid=1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.28.33:8096/client/?command=listVirtualMachines&zoneId=$1&account=admin&domainid=1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 20 10.91.28.33 8096
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
#run.sh runs the agent simulator client.
|
||||
java -cp cloud-utils.jar:agent-simulator.jar:log4j-1.2.15.jar:apache-log4j-extras-1.0.jar:ws-commons-util-1.0.2.jar:xmlrpc-client-3.1.3.jar:cloud-agent.jar:cloud-core.jar:xmlrpc-common-3.1.3.jar:javaee-api-5.0-1.jar:gson-1.3.jar:commons-httpclient-3.1.jar:commons-logging-1.1.1.jar:commons-codec-1.4.jar:commons-collections-3.2.1.jar:commons-pool-1.4.jar:.:./conf com.cloud.agent.AgentSimulator $@
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
y=$2
|
||||
name=$3
|
||||
|
||||
pod_query="GET http://10.91.30.226:8096/client/?command=createPod&zoneId=1&name=SSP$name&cidr=182.$x.$y.0%2F24&startIp=182.$x.$y.2&endIp=182.$x.$y.252&gateway=182.$x.$y.1
|
||||
HTTP/1.0\n\n"
|
||||
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
#vlan_query="GET http://10.91.30.226/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$name&forVirtualNetwork=false&gateway=172.$y.$x.1&netmask=255.255.255.0&startip=172.$y.$x.2&endip=172.$y.$x.252 HTTP/1.0\n\n"
|
||||
|
||||
#echo -e $vlan_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
name=$1
|
||||
|
||||
host_query="GET http://10.91.30.226:8096/client/?command=addHost&zoneId=1&podId=$((name+250))&username=sim&password=sim&clustername=simulator-$name&hosttags=RP$name&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -q 60 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
workers=$1
|
||||
x=$2 #CIDR - 16bytes
|
||||
y=$3 #CIDR - 8 bytes
|
||||
|
||||
for name in `seq 1 $workers`
|
||||
do
|
||||
pod_query="GET http://10.91.30.226:8096/client/?command=createPod&zoneId=1&name=RP$name&cidr=182.$x.$y.0%2F24&startIp=182.$x.$y.2&endIp=182.$x.$y.252&gateway=182.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://10.91.30.226:8096/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$((name+250))&forVirtualNetwork=false&gateway=182.$y.$x.1&netmask=255.255.255.0&startip=182.$y.$x.2&endip=182.$y.$x.252 HTTP/1.0\n\n"
|
||||
so_query="GET http://10.91.30.226:8096/client/?command=createServiceOffering&name=RP$name&displayText=RP$name&storageType=local&cpuNumber=1&cpuSpeed=1000&memory=512&offerha=false&usevirtualnetwork=false&hosttags=RP$name HTTP/1.0\n\n"
|
||||
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.226 8096
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.226 8096
|
||||
echo -e $so_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
let x+=1
|
||||
let y+=1
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
so_query="GET http://10.91.30.226:8096/client/?command=createServiceOffering&name=SO$x&displayText=SO$x&storageType=local&cpuNumber=1&cpuSpeed=1000&memory=512&offerha=false&usevirtualnetwork=false&hosttags=SP$x HTTP/1.0\n\n"
|
||||
|
||||
echo -e $so_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
y=$2
|
||||
name=$3
|
||||
|
||||
vlan_query="GET http://10.91.30.226/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$name&forVirtualNetwork=false&gateway=172.$x.$y.1&netmask=255.255.255.0&startip=172.$x.$y.2&endip=172.$x.$y.252 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/bash
|
||||
|
||||
a=$1 #CIDR - 16bytes
|
||||
b=$2 #CIDR - 8 bytes
|
||||
host=$3
|
||||
zoneid=$4
|
||||
|
||||
zone_query="GET http://$host/client/?command=createZone&networktype=Advanced&securitygroupenabled=false&name=SimulatorAdvanced&dns1=4.2.2.2&internaldns1=4.2.2.2&vlan=10-4000&guestcidraddress=10.1.1.0%2F24 HTTP/1.0\n\n"
|
||||
echo -e $zone_query | nc -v -w 120 $host 8096
|
||||
|
||||
let x=a
|
||||
let y=b
|
||||
for name in `seq 1 1`
|
||||
do
|
||||
pod_query="GET http://$host/client/?command=createPod&zoneid=$zoneid&name=POD$name&netmask=255.255.0.0&startIp=172.$x.$y.2&endIp=172.$x.$y.252&gateway=172.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://$host/client/?command=createVlanIpRange&forVirtualNetwork=true&vlan=untagged&zoneid=$zoneid&podId=$name&gateway=172.$y.$x.1&netmask=255.255.255.0&startip=172.$y.$x.2&endip=172.$y.$x.252 HTTP/1.0\n\n"
|
||||
echo -e $pod_query | nc -v -w 20 $host 8096
|
||||
echo -e $vlan_query | nc -v -w 20 $host 8096
|
||||
done
|
||||
let x+=1
|
||||
let y+=1
|
||||
|
||||
name=1
|
||||
|
||||
clusterid=1
|
||||
for cluster in `seq 1 1`
|
||||
do
|
||||
cluster_query="GET http://$host/client/?command=addCluster&hypervisor=Simulator&clustertype=CloudManaged&zoneid=$zoneid&podId=1&clustername=POD$name-CLUSTER$cluster HTTP/1.0\n\n"
|
||||
echo -e $cluster_query | nc -v -w 120 $host 8096
|
||||
|
||||
host_query="GET http://$host/client/?command=addHost&zoneid=$zoneid&podId=1&username=sim&password=sim&clusterid=$cluster&hypervisor=Simulator&clustertype=CloudManaged&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -w 6000 $host 8096
|
||||
|
||||
spool_query="GET http://$host/client/?command=createStoragePool&zoneid=$zoneid&podId=1&clusterid=$cluster&name=SPOOL$cluster&url=nfs://172.1.25.$((cluster+1))/export/share/$cluster HTTP/1.0\n\n"
|
||||
echo -e $spool_query | nc -v -w 6000 $host 8096
|
||||
let clusterid+=1
|
||||
done
|
||||
|
||||
sstorquery="GET http://$host/client/?command=addSecondaryStorage&zoneid=$zoneid&url=nfs://172.1.25.32/export/share/ HTTP/1.0\n\n"
|
||||
echo -e $sstorquery | nc -v -w 6000 $host 8096
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
#!/bin/bash
|
||||
|
||||
a=$1 #CIDR - 16bytes
|
||||
b=$2 #CIDR - 8 bytes
|
||||
host=$3 #MSHOST
|
||||
zoneid=$4
|
||||
|
||||
zone_query="GET http://$host/client/?command=createZone&name=SimulatorBasic&dns1=4.2.2.2&internaldns1=4.2.2.2&vlan=10-4000&guestcidraddress=10.1.1.0%2F24 HTTP/1.0\n\n"
|
||||
echo -e $zone_query | nc -v -w 120 $host 8096
|
||||
|
||||
let x=a
|
||||
let y=b
|
||||
for name in `seq $zone 100`
|
||||
do
|
||||
pod_query="GET http://$host/client/?command=createPod&zoneId=$zoneid&name=POD$name&cidr=172.$x.$y.0%2F24&startIp=172.$x.$y.2&endIp=172.$x.$y.252&gateway=172.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://$host/client/?command=createVlanIpRange&vlan=untagged&zoneid=$zoneid&podId=$name&forVirtualNetwork=false&gateway=172.$y.$x.1&netmask=255.255.255.0&startip=172.$y.$x.2&endip=172.$y.$x.252 HTTP/1.0\n\n"
|
||||
echo -e $pod_query | nc -v -w 20 $host 8096
|
||||
echo -e $vlan_query | nc -v -w 20 $host 8096
|
||||
|
||||
let x+=1
|
||||
let y+=1
|
||||
done
|
||||
|
||||
clusterid=1
|
||||
for podid in `seq $zone 100`
|
||||
do
|
||||
for i in `seq 1 3`
|
||||
do
|
||||
host_query="GET http://$host/client/?command=addHost&zoneId=$zoneid&podId=$podid&username=sim&password=sim&clustername=CLUSTER$clusterid&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -w 6000 $host 8096
|
||||
done
|
||||
let clusterid+=1
|
||||
done
|
||||
|
||||
sstorquery="GET http://$host/client/?command=addSecondaryStorage&zoneid=$zoneid&url=nfs://172.1.25.32/export/share/ HTTP/1.0\n\n"
|
||||
echo -e $sstorquery | nc -v -w 6000 $host 8096
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
start_router="GET http://10.91.30.226:8096/client/?command=startRouter&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $start_router | nc -v -q 60 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
test="GET http://10.91.30.226:8096/?command=listEvents&page=1 HTTP/1.0\n\n"
|
||||
echo -e $test | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
zoneid=$1
|
||||
templateId=$2
|
||||
serviceOfferingId=$3
|
||||
|
||||
for j in `seq 1 100`
|
||||
do
|
||||
let add=0
|
||||
for i in `seq 1 10`
|
||||
do
|
||||
let account=$(($i+$add))
|
||||
echo Account Name: , $account
|
||||
query="GET http://127.0.0.1/client/?command=deployVirtualMachine&zoneId=$1&hypervisor=Simulator&templateId=$2&serviceOfferingId=$3&account=DummyAccount$account&domainid=1 HTTP/1.0\n\n"
|
||||
echo -e $query | nc -v -q 20 127.0.0.1 8096
|
||||
done
|
||||
let add=add+10
|
||||
sleep 60s
|
||||
done
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
|
||||
name=$1
|
||||
|
||||
account_query="GET http://127.0.0.1/client/?command=createAccount&accounttype=1&email=simulator%40simulator.com&username=$name&firstname=first$name&lastname=last$name&password=5f4dcc3b5aa765d61d8327deb882cf99&account=$name&domainid=1 HTTP/1.1\n\n"
|
||||
|
||||
echo -e $account_query | nc -v -q 120 127.0.0.1 8096
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
spool_query="GET http://127.0.0.1/client/?command=createStoragePool&zoneId=1&podId=1&clusterid=1&name=SPOOL&url=nfs://10.91.25.6/export/share/1 HTTP/1.0\n\n"
|
||||
echo -e $spool_query | nc -v -q 60 127.0.0.1 8096
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
|
||||
name=$1
|
||||
|
||||
account_query="GET http://127.0.0.1/client/?command=createAccount&accounttype=0&email=simulator%40simulator.com&username=$name&firstname=first$name&lastname=last$name&password=5f4dcc3b5aa765d61d8327deb882cf99&account=$name&domainid=1 HTTP/1.1\n\n"
|
||||
|
||||
echo -e $account_query | nc -v -q 120 127.0.0.1 8096
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
delete="GET http://127.0.0.1/client/?command=deleteAccount&id=$x HTTP/1.0\n\n"
|
||||
|
||||
echo -e $delete | nc -v -q 60 127.0.0.1 8096
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
pod_query="GET http://10.91.30.219:8096/client/?command=deletePod&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.219 8096
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
delete_so="GET http://10.91.30.219:8096/client/?command=deleteServiceOffering&id=$x HTTP/1.0\n\n"
|
||||
|
||||
echo -e $delete_so | nc -v -q 20 10.91.30.219 8096
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
vlan_query="GET http://10.91.30.219:8096/client/?command=deleteVlanIpRange&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.219 8096
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
zoneid=$1
|
||||
templateId=$2
|
||||
serviceOfferingId=$3
|
||||
networkIds=$4
|
||||
|
||||
query="GET http://10.91.30.219/client/?command=deployVirtualMachine&zoneId=$1&hypervisor=Simulator&templateId=$2&serviceOfferingId=$3&networkIds=$4&account=admin&domainid=1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 20 10.91.30.219 8096
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
destroy="GET http://10.91.30.219:8096/client/?command=destroyVirtualMachine&id=$x HTTP/1.0\n\n"
|
||||
|
||||
echo -e $destroy | nc -v -q 60 10.91.30.219 8096
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.219:8096/client/?command=listCapacity&zoneId=$1&podid=$2&response=json HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 120 10.91.30.219 8096
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
test="GET http://10.91.30.219:8096/?command=listEvents HTTP/1.0\n\n"
|
||||
echo -e $test | nc -v -q 120 10.91.30.219 8096
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.219:8096/client/?command=listHosts&zoneId=$1&account=admin&domainid=1&page=$2 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 120 10.91.30.219 8096
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.219:8096/client/?command=listRouters&zoneId=$1&account=admin&domainid=1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 120 10.91.30.219 8096
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.219:8096/client/?command=listTemplates&templatefilter=featured&zoneid=$1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 120 10.91.30.219 8096
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.219:8096/client/?command=listVirtualMachines&zoneId=$1&account=admin&domainid=1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 120 10.91.30.219 8096
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
for x in `seq 3 2082`
|
||||
do
|
||||
start_vm="GET http://127.0.0.1:8096/client/?command=startVirtualMachine&id=$x HTTP/1.0\n\n"
|
||||
echo -e $start_vm | nc -v -q 60 127.0.0.1 8096
|
||||
done
|
||||
|
||||
sleep 60s
|
||||
|
||||
for x in `seq 3 1102`
|
||||
do
|
||||
stop_vm="GET http://127.0.0.1/client/?command=stopVirtualMachine&id=$x HTTP/1.0\n\n"
|
||||
echo -e $stop_vm | nc -v -q 60 127.0.0.1 8096
|
||||
done
|
||||
|
||||
sleep 60s
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
x=$1
|
||||
y=$2
|
||||
|
||||
for i in `seq $x $y`
|
||||
do
|
||||
stop_vm="GET http://127.0.0.1/client/?command=stopVirtualMachine&id=$i HTTP/1.0\n\n"
|
||||
echo -e $stop_vm | nc -v -q 60 127.0.0.1 8096
|
||||
done
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
x=$1
|
||||
y=$2
|
||||
|
||||
for i in `seq $x $y`
|
||||
do
|
||||
start_vm="GET http://127.0.0.1:8096/client/?command=startVirtualMachine&id=$i HTTP/1.0\n\n"
|
||||
echo -e $start_vm | nc -v -q 60 127.0.0.1 8096
|
||||
done
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#/bin/bash
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
name=$1
|
||||
while [ 1 ]
|
||||
do
|
||||
mysql -s -r -uroot -Dcloud -h10.1.1.215 -e"select count(id),now(),max(disconnected),mgmt_server_id,status from host group by mgmt_server_id,status;" >> $1
|
||||
sleep 5
|
||||
echo --------------------------------------------------------------------------------------------------------------------- >> $1
|
||||
done
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
#setup for Guava hosts in the simulator
|
||||
|
||||
#1. 1 host per cluster
|
||||
#2. 100 clusters in a pod
|
||||
|
||||
zone_query="GET http://10.91.30.219/client/?command=createZone&networktype=Advanced&securitygroupenabled=false&name=Go&dns1=4.2.2.2&internaldns1=4.2.2.2&vlan=500-1000&guestcidraddress=10.1.1.0%2F24 HTTP/1.0\n\n"
|
||||
echo -e $zone_query | nc -v -q 120 10.91.30.219 8096
|
||||
|
||||
pod_query="GET http://10.91.30.219/client/?command=createPod&zoneId=1&name=Guava&netmask=255.255.0.0&startIp=172.1.2.2&endIp=172.1.255.252&gateway=172.1.2.1 HTTP/1.0\n\n"
|
||||
echo -e $pod_query | nc -v -q 120 10.91.30.219 8096
|
||||
|
||||
vlan_query="GET http://10.91.30.219/client/?command=createVlanIpRange&forVirtualNetwork=true&zoneId=1&vlan=untagged&gateway=172.2.1.1&netmask=255.255.0.0&startip=172.2.1.2&endip=172.2.255.254 HTTP/1.0\n\n"
|
||||
echo -e $vlan_query | nc -v -q 120 10.91.30.219 8096
|
||||
|
||||
for name in `seq 1 100`
|
||||
do
|
||||
cluster_query="GET http://10.91.30.219/client/?command=addCluster&hypervisor=Simulator&clustertype=CloudManaged&zoneId=1&podId=1&clustername=CS$name HTTP/1.0\n\n"
|
||||
echo -e $cluster_query | nc -v -q 120 10.91.30.219 8096
|
||||
|
||||
host_query="GET http://10.91.30.219/client/api?_=1302625706202&command=addHost&zoneId=1&podId=1&clusterid=$name&hypervisor=Simulator&clustertype=CloudManaged&hosttags=&username=sim&password=sim&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -q 60 10.91.30.219 8096
|
||||
|
||||
spool_query="GET http://10.91.30.219/client/?command=createStoragePool&zoneId=1&podId=1&clusterid=$name&name=SPOOL$name&url=nfs://172.1.25.$name/export/share/$name HTTP/1.0\n\n"
|
||||
echo -e $spool_query | nc -v -q 60 10.91.30.219 8096
|
||||
done
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
y=$2
|
||||
name=$3
|
||||
|
||||
pod_query="GET http://10.91.30.219:8096/client/?command=createPod&zoneId=1&name=SSP$name&cidr=182.$x.$y.0%2F24&startIp=182.$x.$y.2&endIp=182.$x.$y.252&gateway=182.$x.$y.1
|
||||
HTTP/1.0\n\n"
|
||||
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.219 8096
|
||||
|
||||
#vlan_query="GET http://10.91.30.219/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$name&forVirtualNetwork=false&gateway=172.$y.$x.1&netmask=255.255.255.0&startip=172.$y.$x.2&endip=172.$y.$x.252 HTTP/1.0\n\n"
|
||||
|
||||
#echo -e $vlan_query | nc -v -q 20 10.91.30.219 8096
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
name=$1
|
||||
|
||||
host_query="GET http://10.91.30.219:8096/client/?command=addHost&zoneId=1&podId=$((name+250))&username=sim&password=sim&clustername=simulator-$name&hosttags=RP$name&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -q 60 10.91.30.219 8096
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
workers=$1
|
||||
x=$2 #CIDR - 16bytes
|
||||
y=$3 #CIDR - 8 bytes
|
||||
|
||||
for name in `seq 1 $workers`
|
||||
do
|
||||
pod_query="GET http://10.91.30.219:8096/client/?command=createPod&zoneId=1&name=RP$name&cidr=182.$x.$y.0%2F24&startIp=182.$x.$y.2&endIp=182.$x.$y.252&gateway=182.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://10.91.30.219:8096/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$((name+250))&forVirtualNetwork=false&gateway=182.$y.$x.1&netmask=255.255.255.0&startip=182.$y.$x.2&endip=182.$y.$x.252 HTTP/1.0\n\n"
|
||||
so_query="GET http://10.91.30.219:8096/client/?command=createServiceOffering&name=RP$name&displayText=RP$name&storageType=local&cpuNumber=1&cpuSpeed=1000&memory=512&offerha=false&usevirtualnetwork=false&hosttags=RP$name HTTP/1.0\n\n"
|
||||
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.219 8096
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.219 8096
|
||||
echo -e $so_query | nc -v -q 20 10.91.30.219 8096
|
||||
|
||||
let x+=1
|
||||
let y+=1
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
so_query="GET http://10.91.30.219:8096/client/?command=createServiceOffering&name=SO$x&displayText=SO$x&storageType=local&cpuNumber=1&cpuSpeed=1000&memory=512&offerha=false&usevirtualnetwork=false&hosttags=SP$x HTTP/1.0\n\n"
|
||||
|
||||
echo -e $so_query | nc -v -q 20 10.91.30.219 8096
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
y=$2
|
||||
name=$3
|
||||
|
||||
vlan_query="GET http://10.91.30.219/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$name&forVirtualNetwork=false&gateway=172.$x.$y.1&netmask=255.255.255.0&startip=172.$x.$y.2&endip=172.$x.$y.252 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.219 8096
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
start_router="GET http://10.91.30.219:8096/client/?command=startRouter&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $start_router | nc -v -q 60 10.91.30.219 8096
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
start_vm="GET http://10.91.30.219:8096/client/?command=startVirtualMachine&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $start_vm | nc -v -q 60 10.91.30.219 8096
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
stop_vm="GET http://127.0.0.1/client/?command=stopVirtualMachine&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $stop_vm | nc -v -q 60 127.0.0.1 8096
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
zoneid=1
|
||||
templateid=3
|
||||
account="u"
|
||||
x=$1
|
||||
y=$2
|
||||
p=$3
|
||||
q=$4
|
||||
|
||||
for i in `seq 1 3`
|
||||
do
|
||||
serviceOfferingId=10
|
||||
query="GET http://127.0.0.1/client/?command=deployVirtualMachine&zoneId=$zoneid&hypervisor=Simulator&templateId=$templateid&serviceOfferingId=$serviceOfferingId&account=$account&domainid=1 HTTP/1.0\n\n"
|
||||
echo -e $query | nc -v -q 20 127.0.0.1 8096
|
||||
done
|
||||
|
||||
sleep 15s
|
||||
|
||||
for x in `seq $x $y`
|
||||
do
|
||||
destroy="GET http://127.0.0.1:8096/client/?command=destroyVirtualMachine&id=$x HTTP/1.0\n\n"
|
||||
echo -e $destroy | nc -v -q 60 127.0.0.1 8096
|
||||
done
|
||||
|
||||
sleep 240s
|
||||
|
||||
for i in `seq 1 30`
|
||||
do
|
||||
serviceOfferingId=9
|
||||
query="GET http://127.0.0.1/client/?command=deployVirtualMachine&zoneId=$zoneid&hypervisor=Simulator&templateId=$templateid&serviceOfferingId=$serviceOfferingId&account=$account&domainid=1 HTTP/1.0\n\n"
|
||||
echo -e $query | nc -v -q 20 127.0.0.1 8096
|
||||
done
|
||||
|
||||
sleep 150s
|
||||
|
||||
for x in `seq $p $q`
|
||||
do
|
||||
destroy="GET http://127.0.0.1:8096/client/?command=destroyVirtualMachine&id=$x HTTP/1.0\n\n"
|
||||
echo -e $destroy | nc -v -q 60 127.0.0.1 8096
|
||||
done
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
java -cp cloud-utils.jar;agent-simulator.jar;log4j-1.2.15.jar;apache-log4j-extras-1.0.jar;ws-commons-util-1.0.2.jar;xmlrpc-client-3.1.3.jar;cloud-agent.jar;cloud-core.jar;xmlrpc-common-3.1.3.jar;javaee-api-5.0-1.jar;gson-1.3.jar;commons-httpclient-3.1.jar;commons-logging-1.1.1.jar;commons-codec-1.3.jar;commons-collections-3.2.1.jar;commons-pool-1.4.jar;.\;.\conf com.cloud.agent.AgentSimulator %*
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
pod_query="GET http://10.91.30.226:8096/client/?command=deletePod&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
delete_so="GET http://10.91.30.226:8096/client/?command=deleteServiceOffering&id=$x HTTP/1.0\n\n"
|
||||
|
||||
echo -e $delete_so | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
vlan_query="GET http://10.91.30.226:8096/client/?command=deleteVlanIpRange&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
zoneid=$1
|
||||
templateId=$2
|
||||
serviceOfferingId=$3
|
||||
|
||||
query="GET http://10.91.30.226:8096/client/?command=deployVirtualMachine&zoneId=$1&templateId=$2&serviceOfferingId=$3&account=admin&domainid=1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 20 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
destroy="GET http://10.91.30.226:8096/client/?command=destroyVirtualMachine&id=$x HTTP/1.0\n\n"
|
||||
|
||||
echo -e $destroy | nc -v -q 60 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.226:8096/client/?command=listCapacity&zoneId=$1&podid=$2&response=json HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 120 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
test="GET http://10.91.30.226:8096/?command=listEvents&page=1 HTTP/1.0\n\n"
|
||||
echo -e $test | nc -v -q 120 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.226:8096/client/?command=listHosts&zoneId=$1&account=admin&domainid=1&page=$2 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 120 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.226:8096/client/?command=listRouters&zoneId=$1&account=admin&domainid=1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 120 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.226:8096/client/?command=listTemplates&templatefilter=featured&zoneid=$1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 120 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
query="GET http://10.91.30.226:8096/client/?command=listVirtualMachines&zoneId=$1&account=admin&domainid=1 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $query | nc -v -q 120 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#/bin/bash
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
name=$1
|
||||
while [ 1 ]
|
||||
do
|
||||
mysql -s -r -uroot -Dcloud -h10.1.1.215 -e"select count(id),now(),max(disconnected),mgmt_server_id,status from host group by mgmt_server_id,status;" >> $1
|
||||
sleep 5
|
||||
echo --------------------------------------------------------------------------------------------------------------------- >> $1
|
||||
done
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
#setup for zynga hosts in the simulator
|
||||
|
||||
#1. Approximately 10 hosts per pod.
|
||||
#2. Only 3 host tags.
|
||||
#3. With in each pod, the host tags are the same.
|
||||
#4. The ratio of hosts for the three tags should be 5/2/6
|
||||
|
||||
a=$1 #CIDR - 16bytes
|
||||
b=$2 #CIDR - 8 bytes
|
||||
|
||||
zone_query="GET http://10.91.30.219/client/?command=createZone&name=Zynga&dns1=4.2.2.2&internaldns1=4.2.2.2&vlan=10-4000&guestcidraddress=10.1.1.0%2F24 HTTP/1.0\n\n"
|
||||
echo -e $zone_query | nc -v -q 120 10.91.30.219 8096
|
||||
|
||||
# Pod Ratio: 38:15:47 @ 10 hosts per pod
|
||||
let x=a
|
||||
let y=b
|
||||
for name in `seq 1 152`
|
||||
do
|
||||
pod_query="GET http://10.91.30.219:8096/client/?command=createPod&zoneId=1&name=POD$name&cidr=172.$x.$y.0%2F24&startIp=172.$x.$y.2&endIp=172.$x.$y.252&gateway=172.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://10.91.30.219:8096/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$name&forVirtualNetwork=false&gateway=172.$y.$x.1&netmask=255.255.255.0&startip=172.$y.$x.2&endip=172.$y.$x.252 HTTP/1.0\n\n"
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.219 8096
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.219 8096
|
||||
|
||||
for cluster in `seq 1 10`
|
||||
do
|
||||
host_query="GET http://10.91.30.219:8096/client/?command=addHost&zoneId=1&podId=$name&username=sim&password=sim&clustername=simulator-POD$name-CLUSTER$cluster&hosttags=TAG1&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -q 6000 10.91.30.219 8096
|
||||
done
|
||||
|
||||
let x+=1
|
||||
let y+=1
|
||||
done
|
||||
|
||||
#reset for tag2
|
||||
let x=a
|
||||
let y=b
|
||||
for name in `seq 153 212`
|
||||
do
|
||||
pod_query="GET http://10.91.30.219:8096/client/?command=createPod&zoneId=1&name=POD$name&cidr=182.$x.$y.0%2F24&startIp=182.$x.$y.2&endIp=182.$x.$y.252&gateway=182.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://10.91.30.219:8096/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$name&forVirtualNetwork=false&gateway=182.$y.$x.1&netmask=255.255.255.0&startip=182.$y.$x.2&endip=182.$y.$x.252 HTTP/1.0\n\n"
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.219 8096
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.219 8096
|
||||
|
||||
for cluster in `seq 1 10`
|
||||
do
|
||||
host_query="GET http://10.91.30.219:8096/client/?command=addHost&zoneId=1&podId=$name&username=sim&password=sim&clustername=simulator-POD$name-CLUSTER$cluster&hosttags=TAG2&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -q 6000 10.91.30.219 8096
|
||||
done
|
||||
|
||||
let x+=1
|
||||
let y+=1
|
||||
done
|
||||
|
||||
#reset for TAG3
|
||||
let x=a
|
||||
let y=b
|
||||
for name in `seq 213 400`
|
||||
do
|
||||
pod_query="GET http://10.91.30.219:8096/client/?command=createPod&zoneId=1&name=POD$name&cidr=192.$x.$y.0%2F24&startIp=192.$x.$y.2&endIp=192.$x.$y.252&gateway=192.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://10.91.30.219:8096/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$name&forVirtualNetwork=false&gateway=192.$y.$x.1&netmask=255.255.255.0&startip=192.$y.$x.2&endip=192.$y.$x.252 HTTP/1.0\n\n"
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.219 8096
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.219 8096
|
||||
|
||||
for cluster in `seq 1 10`
|
||||
do
|
||||
host_query="GET http://10.91.30.219:8096/client/?command=addHost&zoneId=1&podId=$name&username=sim&password=sim&clustername=simulator-POD$name-CLUSTER$cluster&hosttags=TAG3&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -q 6000 10.91.30.219 8096
|
||||
done
|
||||
|
||||
let x+=1
|
||||
let y+=1
|
||||
done
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
y=$2
|
||||
name=$3
|
||||
|
||||
pod_query="GET http://10.91.30.226:8096/client/?command=createPod&zoneId=1&name=SSP$name&cidr=182.$x.$y.0%2F24&startIp=182.$x.$y.2&endIp=182.$x.$y.252&gateway=182.$x.$y.1
|
||||
HTTP/1.0\n\n"
|
||||
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
#vlan_query="GET http://10.91.30.226/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$name&forVirtualNetwork=false&gateway=172.$y.$x.1&netmask=255.255.255.0&startip=172.$y.$x.2&endip=172.$y.$x.252 HTTP/1.0\n\n"
|
||||
|
||||
#echo -e $vlan_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
name=$1
|
||||
|
||||
host_query="GET http://10.91.30.226:8096/client/?command=addHost&zoneId=1&podId=$((name+250))&username=sim&password=sim&clustername=simulator-$name&hosttags=RP$name&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -q 60 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
workers=$1
|
||||
x=$2 #CIDR - 16bytes
|
||||
y=$3 #CIDR - 8 bytes
|
||||
|
||||
for name in `seq 1 $workers`
|
||||
do
|
||||
pod_query="GET http://10.91.30.226:8096/client/?command=createPod&zoneId=1&name=RP$name&cidr=182.$x.$y.0%2F24&startIp=182.$x.$y.2&endIp=182.$x.$y.252&gateway=182.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://10.91.30.226:8096/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$((name+250))&forVirtualNetwork=false&gateway=182.$y.$x.1&netmask=255.255.255.0&startip=182.$y.$x.2&endip=182.$y.$x.252 HTTP/1.0\n\n"
|
||||
so_query="GET http://10.91.30.226:8096/client/?command=createServiceOffering&name=RP$name&displayText=RP$name&storageType=local&cpuNumber=1&cpuSpeed=1000&memory=512&offerha=false&usevirtualnetwork=false&hosttags=RP$name HTTP/1.0\n\n"
|
||||
|
||||
echo -e $pod_query | nc -v -q 20 10.91.30.226 8096
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.226 8096
|
||||
echo -e $so_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
||||
let x+=1
|
||||
let y+=1
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
so_query="GET http://10.91.30.226:8096/client/?command=createServiceOffering&name=SO$x&displayText=SO$x&storageType=local&cpuNumber=1&cpuSpeed=1000&memory=512&offerha=false&usevirtualnetwork=false&hosttags=SP$x HTTP/1.0\n\n"
|
||||
|
||||
echo -e $so_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
y=$2
|
||||
name=$3
|
||||
|
||||
vlan_query="GET http://10.91.30.226/client/?command=createVlanIpRange&vlan=untagged&zoneid=1&podId=$name&forVirtualNetwork=false&gateway=172.$x.$y.1&netmask=255.255.255.0&startip=172.$x.$y.2&endip=172.$x.$y.252 HTTP/1.0\n\n"
|
||||
|
||||
echo -e $vlan_query | nc -v -q 20 10.91.30.226 8096
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
start_router="GET http://10.91.30.226:8096/client/?command=startRouter&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $start_router | nc -v -q 60 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
x=$1
|
||||
|
||||
start_vm="GET http://10.91.30.226:8096/client/?command=startVirtualMachine&id=$x HTTP/1.0\n\n"
|
||||
|
||||
|
||||
echo -e $start_vm | nc -v -q 60 10.91.30.226 8096
|
||||
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
|
||||
#setup for zynga hosts in the simulator
|
||||
|
||||
#1. Approximately 10 hosts per pod.
|
||||
#2. Only 3 host tags.
|
||||
#3. With in each pod, the host tags are the same.
|
||||
#4. The ratio of hosts for the three tags should be 5/2/6
|
||||
|
||||
a=$1 #CIDR - 16bytes
|
||||
b=$2 #CIDR - 8 bytes
|
||||
host=$3 #MSHOST
|
||||
|
||||
zone_query="GET http://$host/client/?command=createZone&name=Zynga&dns1=4.2.2.2&internaldns1=4.2.2.2&vlan=10-4000&guestcidraddress=10.1.1.0%2F24 HTTP/1.0\n\n"
|
||||
echo -e $zone_query | nc -v -w 120 $host 8096
|
||||
|
||||
# Pod Ratio: 38:15:47
|
||||
let x=a
|
||||
let y=b
|
||||
for name in `seq 1 152`
|
||||
do
|
||||
pod_query="GET http://$host/client/?command=createPod&zoneId=2&name=POD$name&cidr=172.$x.$y.0%2F24&startIp=172.$x.$y.2&endIp=172.$x.$y.252&gateway=172.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://$host/client/?command=createVlanIpRange&vlan=untagged&zoneid=2&podId=$name&forVirtualNetwork=false&gateway=172.$y.$x.1&netmask=255.255.255.0&startip=172.$y.$x.2&endip=172.$y.$x.252 HTTP/1.0\n\n"
|
||||
echo -e $pod_query | nc -v -w 20 $host 8096
|
||||
echo -e $vlan_query | nc -v -w 20 $host 8096
|
||||
|
||||
let x+=1
|
||||
let y+=1
|
||||
done
|
||||
|
||||
|
||||
let x=a
|
||||
let y=b
|
||||
for name in `seq 153 212`
|
||||
do
|
||||
pod_query="GET http://$host/client/?command=createPod&zoneId=2&name=POD$name&cidr=182.$x.$y.0%2F24&startIp=182.$x.$y.2&endIp=182.$x.$y.252&gateway=182.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://$host/client/?command=createVlanIpRange&vlan=untagged&zoneid=2&podId=$name&forVirtualNetwork=false&gateway=182.$y.$x.1&netmask=255.255.255.0&startip=182.$y.$x.2&endip=182.$y.$x.252 HTTP/1.0\n\n"
|
||||
echo -e $pod_query | nc -v -w 20 $host 8096
|
||||
echo -e $vlan_query | nc -v -w 20 $host 8096
|
||||
|
||||
let x+=1
|
||||
let y+=1
|
||||
done
|
||||
|
||||
let x=a
|
||||
let y=b
|
||||
for name in `seq 213 400`
|
||||
do
|
||||
pod_query="GET http://$host/client/?command=createPod&zoneId=2&name=POD$name&cidr=192.$x.$y.0%2F24&startIp=192.$x.$y.2&endIp=192.$x.$y.252&gateway=192.$x.$y.1 HTTP/1.0\n\n"
|
||||
vlan_query="GET http://$host/client/?command=createVlanIpRange&vlan=untagged&zoneid=2&podId=$name&forVirtualNetwork=false&gateway=192.$y.$x.1&netmask=255.255.255.0&startip=192.$y.$x.2&endip=192.$y.$x.252 HTTP/1.0\n\n"
|
||||
echo -e $pod_query | nc -v -w 20 $host 8096
|
||||
echo -e $vlan_query | nc -v -w 20 $host 8096
|
||||
|
||||
let x+=1
|
||||
let y+=1
|
||||
done
|
||||
|
||||
#add clusters
|
||||
for name in `seq 1 400`
|
||||
do
|
||||
for cluster in `seq 1 10`
|
||||
do
|
||||
cluster_query="GET http://$host/client/?command=addCluster&hypervisor=Simulator&clustertype=CloudManaged&zoneId=2&podId=$name&clustername=POD$name-CLUSTER$cluster HTTP/1.0\n\n"
|
||||
echo -e $cluster_query | nc -v -w 120 $host 8096
|
||||
done
|
||||
done
|
||||
|
||||
# @ 10 hosts per pod @ 10 clusters per pod
|
||||
clusterid=133
|
||||
#TAG1
|
||||
for podid in `seq 133 152`
|
||||
do
|
||||
for i in `seq 1 10`
|
||||
do
|
||||
host_query="GET http://$host/client/?command=addHost&zoneId=2&podId=$podid&username=sim&password=sim&clustername=CLUSTER$clusterid&hosttags=TAG1&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -w 6000 $host 8096
|
||||
done
|
||||
let clusterid+=1
|
||||
done
|
||||
|
||||
#TAG2
|
||||
for podid in `seq 153 212`
|
||||
do
|
||||
for i in `seq 1 10`
|
||||
do
|
||||
host_query="GET http://$host/client/?command=addHost&zoneId=2&podId=$podid&username=sim&password=sim&clustername=CLUSTER$clusterid&hosttags=TAG2&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -w 6000 $host 8096
|
||||
done
|
||||
let clusterid+=1
|
||||
done
|
||||
|
||||
#TAG3
|
||||
for podid in `seq 213 400`
|
||||
do
|
||||
for i in `seq 1 10`
|
||||
do
|
||||
host_query="GET http://$host/client/?command=addHost&zoneId=2&podId=$podid&username=sim&password=sim&cluster=CLUSTER$clusterid&hosttags=TAG3&url=http%3A%2F%2Fsim HTTP/1.0\n\n"
|
||||
echo -e $host_query | nc -v -w 6000 $host 8096
|
||||
done
|
||||
let clusterid+=1
|
||||
done
|
||||
|
|
@ -0,0 +1,208 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
'''
|
||||
############################################################
|
||||
# zucchini uses local storage, before setting up make sure
|
||||
# * xen.public.network.device is set
|
||||
# * use.local.storage and systemvm.use.local.storage are true
|
||||
# * optionally turn off stats collectors
|
||||
# * expunge.delay and expunge.interval are 60s
|
||||
# * ping.interval is around 3m
|
||||
# * turn off dns updates to entire zone, network.dns.basiczone.update=pod
|
||||
# * capacity.skipcounting.hours=0
|
||||
# * direct.agent.load.size=1000
|
||||
# * security groups are enabled
|
||||
#
|
||||
# This script will only setup an approximate number of hosts. To achieve the ratio
|
||||
# of 5:2:6 hosts the total number of hosts is brought close to a number divisible
|
||||
# by 13. So if 4000 hosts are added, you might see only 3900 come up
|
||||
#
|
||||
# 10 hosts per pod @ 1 host per cluster in a single zone
|
||||
#
|
||||
# Each pod has a /25, so 128 addresses. I think we reserved 5 IP addresses for system VMs in each pod.
|
||||
# Then we had something like 60 addresses for hosts and 60 addresses for VMs.
|
||||
|
||||
#Environment
|
||||
#1. Approximately 10 hosts per pod.
|
||||
#2. Only 3 host tags.
|
||||
#3. With in each pod, the host tags are the same. Homogenous Pods
|
||||
#4. The ratio of hosts for the three tags should be 5/2/6
|
||||
#5. In simulator.properties, workers=1
|
||||
############################################################
|
||||
'''
|
||||
|
||||
from optparse import OptionParser
|
||||
from configGenerator import *
|
||||
import random
|
||||
|
||||
def getGlobalSettings():
|
||||
global_settings = {'expunge.delay': '60',
|
||||
'expunge.interval': '60',
|
||||
'expunge.workers': '3',
|
||||
'workers': '10',
|
||||
'network.dns.basiczone.updates':'pod',
|
||||
'use.user.concentrated.pod.allocation':'false',
|
||||
'vm.allocation.algorithm':'firstfit',
|
||||
'capacity.check.period':'0',
|
||||
'host.stats.interval':'-1',
|
||||
'vm.stats.interval':'-1',
|
||||
'storage.stats.interval':'-1',
|
||||
'router.stats.interval':'-1',
|
||||
'vm.op.wait.interval':'5',
|
||||
'xen.public.network.device':'10.10.10.10', #only a dummy for the simulator
|
||||
'guest.domain.suffix':'zcloud.simulator',
|
||||
'instance.name':'ZIM',
|
||||
'direct.agent.load.size':'1000',
|
||||
'default.page.size':'10000',
|
||||
'linkLocalIp.nums':'4',
|
||||
'systemvm.use.local.storage':'true',
|
||||
'use.local.storage':'true',
|
||||
'check.pod.cidrs':'false',
|
||||
}
|
||||
for k,v in global_settings.iteritems():
|
||||
cfg=configuration()
|
||||
cfg.name=k
|
||||
cfg.value=v
|
||||
yield cfg
|
||||
|
||||
def podIpRangeGenerator():
|
||||
x=1
|
||||
y=2
|
||||
while 1:
|
||||
if y == 256:
|
||||
x=x+1
|
||||
if x == 256:
|
||||
break
|
||||
y=1
|
||||
y=y+1
|
||||
#pod mangement network
|
||||
yield ('172.'+str(x)+'.'+str(y)+'.129',
|
||||
'172.'+str(x)+'.'+str(y)+'.130',
|
||||
'172.'+str(x)+'.'+str(y)+'.189')
|
||||
|
||||
|
||||
def vlanIpRangeGenerator():
|
||||
x=1
|
||||
y=2
|
||||
while 1:
|
||||
if y == 256:
|
||||
x=x+1
|
||||
if x==256:
|
||||
break
|
||||
y=1
|
||||
y=y+1
|
||||
#vlan ip range
|
||||
yield ('172.'+str(x)+'.'+str(y)+'.129',
|
||||
'172.'+str(x)+'.'+str(y)+'.190',
|
||||
'172.'+str(x)+'.'+str(y)+'.249')
|
||||
|
||||
|
||||
def describeZyngaResources(numberOfAgents=1300, dbnode='localhost', mshost='localhost', randomize=False):
|
||||
zs=cloudstackConfiguration()
|
||||
numberofpods=numberOfAgents/10
|
||||
tagOneHosts = numberOfAgents*5/13
|
||||
tagTwoHosts = numberOfAgents*2/13
|
||||
tagThreeHosts = numberOfAgents-tagOneHosts-tagTwoHosts
|
||||
|
||||
clustersPerPod=10
|
||||
hostsPerPod=10
|
||||
|
||||
z = zone()
|
||||
z.dns1 = '4.2.2.2'
|
||||
z.dns2 = '192.168.110.254'
|
||||
z.internaldns1 = '10.91.28.6'
|
||||
z.internaldns2 = '192.168.110.254'
|
||||
z.name = 'Zynga'
|
||||
z.networktype = 'Basic'
|
||||
|
||||
hosttags=['TAG1' for x in range(tagOneHosts)] + ['TAG2' for x in range(tagTwoHosts)] + ['TAG3' for x in range(tagThreeHosts)]
|
||||
if randomize:
|
||||
random.shuffle(hosttags) #randomize the host distribution
|
||||
curhost=0
|
||||
curpod=0
|
||||
for podRange,vlanRange in zip(podIpRangeGenerator(), vlanIpRangeGenerator()):
|
||||
p = pod()
|
||||
curpod=curpod+1
|
||||
p.name = 'POD'+str(curpod)
|
||||
p.gateway=podRange[0]
|
||||
p.startip=podRange[1]
|
||||
p.endip=podRange[2]
|
||||
p.netmask='255.255.255.128'
|
||||
|
||||
v = iprange()
|
||||
v.gateway=vlanRange[0]
|
||||
v.startip=vlanRange[1]
|
||||
v.endip=vlanRange[2]
|
||||
v.netmask="255.255.255.128"
|
||||
p.guestIpRanges.append(v)
|
||||
|
||||
for i in range(1,clustersPerPod+1):
|
||||
c = cluster()
|
||||
c.clustername = 'POD'+str(curpod)+'-CLUSTER'+str(i)
|
||||
c.hypervisor = 'Simulator'
|
||||
c.clustertype = 'CloudManaged'
|
||||
|
||||
try:
|
||||
h = host()
|
||||
h.username = 'root'
|
||||
h.password = 'password'
|
||||
h.url = "http://sim/%d/cpucore=4&cpuspeed=8000&memory=%d&localstorage=%d"%(i,8*1024*1024*1024,1*1024*1024*1024*1024)
|
||||
h.hosttags = hosttags.pop()
|
||||
c.hosts.append(h)
|
||||
curhost=curhost+1
|
||||
p.clusters.append(c)
|
||||
except IndexError:
|
||||
break
|
||||
#end clusters
|
||||
z.pods.append(p)
|
||||
if curpod == numberofpods or curhost == numberOfAgents:
|
||||
break
|
||||
#end pods
|
||||
secondary = secondaryStorage()
|
||||
secondary.url = 'nfs://172.16.25.32/secondary/path'
|
||||
z.secondaryStorages.append(secondary)
|
||||
zs.zones.append(z)
|
||||
|
||||
'''Add mgt server'''
|
||||
mgt = managementServer()
|
||||
mgt.mgtSvrIp = mshost #could be the LB balancing the cluster of management server as well
|
||||
zs.mgtSvr.append(mgt)
|
||||
|
||||
'''Add a database'''
|
||||
db = dbServer()
|
||||
db.dbSvr = opts.dbnode
|
||||
zs.dbSvr = db
|
||||
|
||||
'''Add some configuration'''
|
||||
[zs.globalConfig.append(cfg) for cfg in getGlobalSettings()]
|
||||
|
||||
''''add loggers'''
|
||||
testClientLogger = logger()
|
||||
testClientLogger.name = "TestClient"
|
||||
testClientLogger.file = "/var/log/testclient.log"
|
||||
|
||||
testCaseLogger = logger()
|
||||
testCaseLogger.name = "TestCase"
|
||||
testCaseLogger.file = "/var/log/testcase.log"
|
||||
|
||||
zs.logger.append(testClientLogger)
|
||||
zs.logger.append(testCaseLogger)
|
||||
return zs
|
||||
|
||||
if __name__=="__main__":
|
||||
parser = OptionParser()
|
||||
# parser.add_option('-h','--host',dest='host',help='location of management server(s) or load-balancer')
|
||||
parser.add_option('-n', '--number-of-agents', action='store', dest='agents', help='number of agents in the deployment')
|
||||
parser.add_option('-g', '--enable-security-groups', dest='sgenabled', help='specify if security groups are to be enabled', default=False, action='store_true')
|
||||
parser.add_option('-o', '--output', action='store', default='./zucchiniCfg', dest='output', help='the path where the json config file generated')
|
||||
parser.add_option('-d', '--dbnode', dest='dbnode', help='hostname/ip of the database node', action='store')
|
||||
parser.add_option('-m', '--mshost', dest='mshost', help='hostname/ip of management server', action='store')
|
||||
parser.add_option('-r', '--randomize', dest='randomize', help='randomize the distribution of tags (hetergenous clusters)', action='store_true', default=False)
|
||||
|
||||
(opts, args) = parser.parse_args()
|
||||
mandatories = ['mshost', 'dbnode', 'agents']
|
||||
for m in mandatories:
|
||||
if not opts.__dict__[m]:
|
||||
print "mandatory option missing"
|
||||
cfg = describeZyngaResources(int(opts.agents), opts.dbnode, opts.mshost, opts.randomize)
|
||||
generate_setup_config(cfg, opts.output)
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
#!/usr/bin/env python
|
||||
'''
|
||||
Deploy Virtual Machine tests
|
||||
'''
|
||||
import unittest
|
||||
import random
|
||||
from cloudstackAPI import *
|
||||
|
||||
class Provision(unittest.case.TestCase):
|
||||
'''
|
||||
This should test basic provisioning of virtual machines
|
||||
1. Deploy a no-frills VM
|
||||
2. Deploy with tags - hosttags
|
||||
3. Deploy with/without security groups
|
||||
'''
|
||||
|
||||
api = self.testClient.getApiClient()
|
||||
solist = {}
|
||||
|
||||
def setUp(self):
|
||||
'''setup service offerings with tags'''
|
||||
for tag in ['TAG1', 'TAG2', 'TAG3']:
|
||||
csocmd = createServiceOffering.createServiceOfferingCmd()
|
||||
csocmd.cpunumber = 1
|
||||
csocmd.cpuspeed = 2048
|
||||
csocmd.displayText = tag
|
||||
csocmd.memory = 7168
|
||||
csocmd.name = tag
|
||||
csocmd.hosttags = tag
|
||||
csocmd.storagetype = 'local'
|
||||
csoresponse = self.api.createServiceOffering(csocmd)
|
||||
self.debug("Created Service Offering: %s", tag)
|
||||
solist[tag]=csoresponse.id
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
''' Any cleanup post tests '''
|
||||
|
||||
def test_DeployVMWithHostTags(self):
|
||||
'''
|
||||
Deploy 3 virtual machines one with each hosttag
|
||||
'''
|
||||
for k,v in solist:
|
||||
deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd()
|
||||
deployVmCmd.zoneid = 1
|
||||
deployVmCmd.hypervisor='Simulator'
|
||||
deployVmCmd.serviceofferingid=v
|
||||
deployVmCmd.account='admin'
|
||||
deployVmCmd.domainid=1
|
||||
deployVmCmd.templateid=2
|
||||
deployVmResponse = self.api.deployVirtualMachine(deployVmCmd)
|
||||
self.debug("Deployed VM :%d in job: %d",deployVmResponse.id, deployVmResponse.jobid)
|
||||
|
||||
|
||||
def deployCmd(self, tag):
|
||||
deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd()
|
||||
deployVmCmd.zoneid = 1
|
||||
deployVmCmd.hypervisor='Simulator'
|
||||
deployVmCmd.serviceofferingid=solist[tag]
|
||||
deployVmCmd.account='admin'
|
||||
deployVmCmd.domainid=1
|
||||
deployVmCmd.templateid=2
|
||||
return deployVmCmd
|
||||
|
||||
def deployN(self,nargs=300,batchsize=0):
|
||||
'''
|
||||
Deploy Nargs number of VMs concurrently in batches of size {batchsize}.
|
||||
When batchsize is 0 all Vms are deployed in one batch
|
||||
VMs will be deployed in 5:2:6 ratio
|
||||
'''
|
||||
tag1=nargs*5/13
|
||||
tag2=nargs*2/13
|
||||
tag3=nargs-tag1-tag2
|
||||
|
||||
cmds = []
|
||||
[cmds.append(deployCmd('TAG1')) for i in range(tag1)]
|
||||
[cmds.append(deployCmd('TAG2')) for i in range(tag2)]
|
||||
[cmds.append(deployCmd('TAG3')) for i in range(tag3)]
|
||||
random.shuffle(cmds) #with mix-and-match of Tags
|
||||
|
||||
if batchsize == 0:
|
||||
self.testClient.submitCmdsAndWait(cmds)
|
||||
else:
|
||||
while len(z) > 0:
|
||||
try:
|
||||
newbatch = [cmds.pop() for b in range(batchsize)] #pop batchsize items
|
||||
self.testClient.submitCmdsAndWait(newbatch)
|
||||
except IndexError:
|
||||
break
|
||||
|
||||
def test_bulkDeploy(self):
|
||||
deployN(130,0)
|
||||
deployN(nargs=3000,batchsize=100)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
|
||||
public class MetricsCollector {
|
||||
private static final Logger s_logger = Logger.getLogger(MetricsCollector.class);
|
||||
|
||||
private final Set<String> vmNames = new HashSet<String>();
|
||||
private final Set<String> newVMnames = new HashSet<String>();
|
||||
private final Map<String, MockVmMetrics> metricsMap = new HashMap<String, MockVmMetrics>();
|
||||
|
||||
private final transient ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("Metrics"));
|
||||
|
||||
private Set<String> _currentVms;
|
||||
|
||||
public MetricsCollector(Set<String> currentVms) {
|
||||
_currentVms = currentVms;
|
||||
getAllVMNames();
|
||||
}
|
||||
|
||||
public MetricsCollector() {
|
||||
|
||||
}
|
||||
|
||||
public synchronized void getAllVMNames() {
|
||||
Set<String> currentVMs = _currentVms;
|
||||
|
||||
newVMnames.clear();
|
||||
newVMnames.addAll(currentVMs);
|
||||
newVMnames.removeAll(vmNames); //leave only new vms
|
||||
|
||||
vmNames.removeAll(currentVMs); //old vms - current vms --> leave non-running vms;
|
||||
for (String vm: vmNames) {
|
||||
removeVM(vm);
|
||||
}
|
||||
|
||||
vmNames.clear();
|
||||
vmNames.addAll(currentVMs);
|
||||
}
|
||||
|
||||
public synchronized void submitMetricsJobs() {
|
||||
s_logger.debug("Submit Metric Jobs called");
|
||||
|
||||
for (String vm : newVMnames) {
|
||||
MockVmMetrics task = new MockVmMetrics(vm);
|
||||
if (!metricsMap.containsKey(vm)) {
|
||||
metricsMap.put(vm, task);
|
||||
ScheduledFuture<?> sf = executor.scheduleWithFixedDelay(task, 2, 600, TimeUnit.SECONDS);
|
||||
task.setFuture(sf);
|
||||
}
|
||||
}
|
||||
newVMnames.clear();
|
||||
}
|
||||
|
||||
public synchronized void addVM(String vmName) {
|
||||
newVMnames.add(vmName);
|
||||
s_logger.debug("Added vm name= " + vmName);
|
||||
}
|
||||
|
||||
public synchronized void removeVM(String vmName) {
|
||||
newVMnames.remove(vmName);
|
||||
vmNames.remove(vmName);
|
||||
MockVmMetrics task = metricsMap.get(vmName);
|
||||
if (task != null) {
|
||||
task.stop();
|
||||
boolean r1= task.getFuture().cancel(false);
|
||||
metricsMap.remove(vmName);
|
||||
s_logger.debug("removeVM: cancel returned " + r1 + " for VM " + vmName);
|
||||
} else {
|
||||
s_logger.warn("removeVM called for nonexistent VM " + vmName);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Set<String> getVMNames() {
|
||||
return vmNames;
|
||||
}
|
||||
|
||||
public synchronized Map<String, MockVmMetrics> getMetricsMap() {
|
||||
return metricsMap;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class MockVmMetrics implements Runnable {
|
||||
private static final Logger s_logger = Logger.getLogger(MockVmMetrics.class);
|
||||
|
||||
private String vmName;
|
||||
|
||||
//the maximum number of network interfaces to a VM (should be 1)
|
||||
public final int MAX_INTERFACES=1;
|
||||
|
||||
//the maximum number of disks to a VM
|
||||
public final int MAX_DISKS=8;
|
||||
|
||||
//the last calculated traffic speed (transmit) per interface
|
||||
private Map<String, Double> netTxKBps = new HashMap<String, Double>();
|
||||
|
||||
//the last calculated traffic speed (receive) per interface
|
||||
private Map<String, Double> netRxKBps = new HashMap<String, Double>();
|
||||
|
||||
//the last calculated disk write speed per disk (Bytes Per Second)
|
||||
private Map<String, Double> diskWriteKBytesPerSec = new HashMap<String, Double>();
|
||||
|
||||
//the last calculated disk read speed per disk (Bytes Per Second)
|
||||
private Map<String, Double> diskReadKBytesPerSec = new HashMap<String, Double>();
|
||||
|
||||
//Total Bytes Transmitted on network interfaces
|
||||
private Map<String, Long> netTxTotalBytes = new HashMap<String, Long>();
|
||||
|
||||
//Total Bytes Received on network interfaces
|
||||
private Map<String, Long> netRxTotalBytes = new HashMap<String, Long>();
|
||||
|
||||
//Total Bytes read per disk
|
||||
private Map<String, Long> diskReadTotalBytes = new HashMap<String, Long>();
|
||||
|
||||
//Total Bytes written per disk
|
||||
private Map<String, Long> diskWriteTotalBytes = new HashMap<String, Long>();
|
||||
|
||||
//CPU time in seconds
|
||||
private Double cpuSeconds = new Double(0.0);
|
||||
|
||||
//CPU percentage
|
||||
private Float cpuPercent = new Float(0.0);
|
||||
|
||||
private Map<String, String> diskMap = new HashMap<String, String>();
|
||||
|
||||
private Map<String, String> vifMap = new HashMap<String, String>();
|
||||
|
||||
private Map<String, Long> diskStatTimestamp = new HashMap<String, Long>();
|
||||
private Map<String, Long> netStatTimestamp = new HashMap<String, Long>();
|
||||
|
||||
private long cpuStatTimestamp = 0L;
|
||||
|
||||
private ScheduledFuture<?> future;
|
||||
private boolean stopped = false;
|
||||
private Random randSeed = new Random();
|
||||
|
||||
public MockVmMetrics(String vmName) {
|
||||
this.vmName = vmName;
|
||||
vifMap.put("eth0", "eth0");
|
||||
vifMap.put("eth1", "eth1");
|
||||
vifMap.put("eth2", "eth2");
|
||||
|
||||
Long networkStart = 0L;
|
||||
netTxTotalBytes.put("eth0", networkStart);
|
||||
netRxTotalBytes.put("eth0", networkStart);
|
||||
|
||||
netTxTotalBytes.put("eth1", networkStart);
|
||||
netRxTotalBytes.put("eth1", networkStart);
|
||||
|
||||
netTxTotalBytes.put("eth2", networkStart);
|
||||
netRxTotalBytes.put("eth2", networkStart);
|
||||
}
|
||||
|
||||
private int getIncrementor() {
|
||||
return randSeed.nextInt(100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Generating MockVM metrics");
|
||||
}
|
||||
for (Map.Entry<String, Long> entry : netRxTotalBytes.entrySet()) {
|
||||
entry.setValue(entry.getValue() + getIncrementor());
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Long> entry : netTxTotalBytes.entrySet()) {
|
||||
entry.setValue(entry.getValue() + getIncrementor());
|
||||
}
|
||||
}
|
||||
|
||||
public String getVmName() {
|
||||
return vmName;
|
||||
}
|
||||
|
||||
public Map<String, Double> getNetTxKBps() {
|
||||
return netTxKBps;
|
||||
}
|
||||
|
||||
public Map<String, Double> getNetRxKBps() {
|
||||
return netRxKBps;
|
||||
}
|
||||
|
||||
public Map<String, Double> getDiskWriteBytesPerSec() {
|
||||
return diskWriteKBytesPerSec;
|
||||
}
|
||||
|
||||
public Map<String, Double> getDiskReadBytesPerSec() {
|
||||
return diskReadKBytesPerSec;
|
||||
}
|
||||
|
||||
public Map<String, Long> getNetTxTotalBytes() {
|
||||
return netTxTotalBytes;
|
||||
}
|
||||
|
||||
public Map<String, Long> getNetRxTotalBytes() {
|
||||
return netRxTotalBytes;
|
||||
}
|
||||
|
||||
public Map<String, Long> getDiskReadTotalBytes() {
|
||||
return diskReadTotalBytes;
|
||||
}
|
||||
|
||||
public Map<String, Long> getDiskWriteTotalBytes() {
|
||||
return diskWriteTotalBytes;
|
||||
}
|
||||
|
||||
public Double getNetTxKBps(String intf) {
|
||||
return netTxKBps.get(intf);
|
||||
}
|
||||
|
||||
public Double getNetRxKBps(String intf) {
|
||||
return netRxKBps.get(intf);
|
||||
}
|
||||
|
||||
public Double getDiskWriteKBytesPerSec(String disk) {
|
||||
return diskWriteKBytesPerSec.get(disk);
|
||||
}
|
||||
|
||||
public Double getDiskReadKBytesPerSec(String disk) {
|
||||
return diskReadKBytesPerSec.get(disk);
|
||||
}
|
||||
|
||||
public Long getNetTxTotalBytes(String intf) {
|
||||
return netTxTotalBytes.get(intf);
|
||||
}
|
||||
|
||||
public Long getNetRxTotalBytes(String intf) {
|
||||
return netRxTotalBytes.get(intf);
|
||||
}
|
||||
|
||||
public Long getDiskReadTotalBytes(String disk) {
|
||||
return diskReadTotalBytes.get(disk);
|
||||
}
|
||||
|
||||
public Long getDiskWriteTotalBytes(String disk) {
|
||||
return diskWriteTotalBytes.get(disk);
|
||||
}
|
||||
|
||||
public Double getCpuSeconds() {
|
||||
return cpuSeconds;
|
||||
}
|
||||
|
||||
public Map<String, String> getDiskMap() {
|
||||
return diskMap;
|
||||
}
|
||||
|
||||
public Float getCpuPercent() {
|
||||
return cpuPercent;
|
||||
}
|
||||
|
||||
public void setFuture(ScheduledFuture<?> sf) {
|
||||
this.future = sf;
|
||||
}
|
||||
|
||||
public ScheduledFuture<?> getFuture() {
|
||||
return future;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.stopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent;
|
||||
|
||||
import java.util.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class MultiCaster implements Runnable {
|
||||
private static final Logger s_logger = Logger.getLogger(MultiCaster.class);
|
||||
|
||||
public final int MAX_PACKET_SIZE = 8096;
|
||||
|
||||
private List<MultiCasterListener> listeners;
|
||||
private DatagramSocket socket;
|
||||
private byte[] recvBuffer;
|
||||
|
||||
private Thread driver;
|
||||
private volatile boolean stopRequested = false;
|
||||
|
||||
public MultiCaster() {
|
||||
listeners = new ArrayList<MultiCasterListener>();
|
||||
recvBuffer = new byte[MAX_PACKET_SIZE];
|
||||
}
|
||||
|
||||
public void addListener(MultiCasterListener listener) {
|
||||
synchronized(listeners) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeListener(MultiCasterListener listener) {
|
||||
synchronized(listeners) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void cast(byte[] buf, int off, int len,
|
||||
InetAddress toAddress, int nToPort) throws IOException {
|
||||
|
||||
if(socket == null)
|
||||
throw new IOException("multi caster is not started");
|
||||
|
||||
if(len >= MAX_PACKET_SIZE)
|
||||
throw new IOException("packet size exceeds limit of " + MAX_PACKET_SIZE);
|
||||
|
||||
DatagramPacket packet = new DatagramPacket(buf, off,
|
||||
len, toAddress, nToPort);
|
||||
|
||||
socket.send(packet);
|
||||
}
|
||||
|
||||
public void start(String strOutboundAddress,
|
||||
String strClusterAddress, int nPort) throws SocketException {
|
||||
assert(socket == null);
|
||||
|
||||
InetAddress addr = null;
|
||||
try {
|
||||
addr = InetAddress.getByName(strClusterAddress);
|
||||
} catch(IOException e) {
|
||||
s_logger.error("Unexpected exception " , e);
|
||||
}
|
||||
|
||||
if(addr != null && addr.isMulticastAddress()) {
|
||||
try {
|
||||
socket = new MulticastSocket(nPort);
|
||||
socket.setReuseAddress(true);
|
||||
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("Join multicast group : " + addr);
|
||||
|
||||
((MulticastSocket)socket).joinGroup(addr);
|
||||
((MulticastSocket)socket).setTimeToLive(1);
|
||||
|
||||
if(strOutboundAddress != null) {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("set outgoing interface to : " + strOutboundAddress);
|
||||
|
||||
InetAddress ia = InetAddress.getByName(strOutboundAddress);
|
||||
NetworkInterface ni = NetworkInterface.getByInetAddress(ia);
|
||||
((MulticastSocket)socket).setNetworkInterface(ni);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
s_logger.error("Unexpected exception " , e);
|
||||
}
|
||||
} else {
|
||||
socket = new DatagramSocket(nPort);
|
||||
socket.setReuseAddress(true);
|
||||
}
|
||||
|
||||
driver = new Thread(this, "Multi-caster");
|
||||
driver.setDaemon(true);
|
||||
driver.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if(socket != null) {
|
||||
stopRequested = true;
|
||||
|
||||
socket.close();
|
||||
if(driver != null) {
|
||||
try {
|
||||
driver.join();
|
||||
} catch(InterruptedException e) {
|
||||
}
|
||||
driver = null;
|
||||
}
|
||||
}
|
||||
|
||||
socket = null;
|
||||
stopRequested = false;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while(!stopRequested) {
|
||||
try {
|
||||
DatagramPacket packet = new DatagramPacket(recvBuffer, recvBuffer.length);
|
||||
socket.receive(packet);
|
||||
|
||||
for(Object listener : listeners.toArray()) {
|
||||
((MultiCasterListener)listener).onMultiCasting(packet.getData(),
|
||||
packet.getOffset(), packet.getLength(), packet.getAddress());
|
||||
}
|
||||
} catch(IOException e) {
|
||||
} catch(Throwable e) {
|
||||
s_logger.error("Unhandled exception : ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent;
|
||||
import java.net.*;
|
||||
|
||||
public interface MultiCasterListener {
|
||||
public void onMultiCasting(byte[] data, int off, int len, InetAddress addrFrom);
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SimulatorCmd implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String testCase = "DEFAULT";
|
||||
|
||||
public SimulatorCmd(String testCase) {
|
||||
this.testCase = testCase;
|
||||
}
|
||||
|
||||
public String getTestCase() {
|
||||
return testCase;
|
||||
}
|
||||
|
||||
public void setTestCase(String testCase) {
|
||||
this.testCase = testCase;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent;
|
||||
|
||||
public class SimulatorMigrateVmCmd extends SimulatorCmd {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String destIp;
|
||||
|
||||
private String vmName;
|
||||
private long ramSize;
|
||||
private int cpuCount;
|
||||
private int utilization;
|
||||
|
||||
public SimulatorMigrateVmCmd(String testCase) {
|
||||
super(testCase);
|
||||
}
|
||||
|
||||
public String getDestIp() {
|
||||
return destIp;
|
||||
}
|
||||
|
||||
public void setDestIp(String destIp) {
|
||||
this.destIp = destIp;
|
||||
}
|
||||
|
||||
public String getVmName() {
|
||||
return vmName;
|
||||
}
|
||||
|
||||
public void setVmName(String vmName) {
|
||||
this.vmName = vmName;
|
||||
}
|
||||
|
||||
public long getRamSize() {
|
||||
return ramSize;
|
||||
}
|
||||
|
||||
public void setRamSize(long ramSize) {
|
||||
this.ramSize = ramSize;
|
||||
}
|
||||
|
||||
public int getCpuCount() {
|
||||
return cpuCount;
|
||||
}
|
||||
|
||||
public void setCpuCount(int cpuCount) {
|
||||
this.cpuCount = cpuCount;
|
||||
}
|
||||
|
||||
public int getUtilization() {
|
||||
return utilization;
|
||||
}
|
||||
|
||||
public void setUtilization(int utilization) {
|
||||
this.utilization = utilization;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("SimulatorMigrateVmCmd {").append("vm: ").append(getVmName());
|
||||
sb.append(", destIp: ").append(getDestIp()).append(", ramSize: ").append(getRamSize());
|
||||
sb.append(", cpuCount: ").append(getCpuCount()).append(", utilization: ").append(getUtilization());
|
||||
sb.append("}");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.cloud.agent.manager;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.CheckHealthAnswer;
|
||||
import com.cloud.agent.api.CheckHealthCommand;
|
||||
import com.cloud.agent.api.GetHostStatsAnswer;
|
||||
import com.cloud.agent.api.GetHostStatsCommand;
|
||||
import com.cloud.agent.api.HostStatsEntry;
|
||||
import com.cloud.agent.api.MaintainCommand;
|
||||
import com.cloud.agent.api.PingTestCommand;
|
||||
import com.cloud.agent.api.PrepareForMigrationAnswer;
|
||||
import com.cloud.agent.api.PrepareForMigrationCommand;
|
||||
import com.cloud.agent.api.ReadyAnswer;
|
||||
import com.cloud.agent.api.ReadyCommand;
|
||||
import com.cloud.agent.api.SecurityIngressRulesCmd;
|
||||
import com.cloud.agent.api.ShutdownCommand;
|
||||
import com.cloud.resource.AgentResourceBase;
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.utils.component.Manager;
|
||||
|
||||
public interface MockAgentManager extends Manager {
|
||||
public static final long DEFAULT_HOST_MEM_SIZE = 8 * 1024 * 1024 * 1024L; // 8G, unit of
|
||||
// Mbytes
|
||||
public static final int DEFAULT_HOST_CPU_CORES = 4; // 2 dual core CPUs (2 x
|
||||
// 2)
|
||||
public static final int DEFAULT_HOST_SPEED_MHZ = 8000; // 1 GHz CPUs
|
||||
boolean configure(String name, Map<String, Object> params) throws ConfigurationException;
|
||||
|
||||
Map<AgentResourceBase, Map<String, String>> createServerResources(Map<String, Object> params);
|
||||
|
||||
boolean handleSystemVMStart(long vmId, String privateIpAddress, String privateMacAddress, String privateNetMask, long dcId, long podId, String name, String vmType, String url);
|
||||
|
||||
boolean handleSystemVMStop(long vmId);
|
||||
|
||||
GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd);
|
||||
Answer checkHealth(CheckHealthCommand cmd);
|
||||
Answer pingTest(PingTestCommand cmd);
|
||||
|
||||
Answer PrepareForMigration(PrepareForMigrationCommand cmd);
|
||||
|
||||
MockHost getHost(String guid);
|
||||
|
||||
Answer MaintainCommand(MaintainCommand cmd);
|
||||
}
|
||||
|
|
@ -0,0 +1,353 @@
|
|||
package com.cloud.agent.manager;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.CheckHealthCommand;
|
||||
import com.cloud.agent.api.GetHostStatsAnswer;
|
||||
import com.cloud.agent.api.GetHostStatsCommand;
|
||||
import com.cloud.agent.api.HostStatsEntry;
|
||||
import com.cloud.agent.api.PingTestCommand;
|
||||
import com.cloud.agent.api.PrepareForMigrationAnswer;
|
||||
import com.cloud.agent.api.PrepareForMigrationCommand;
|
||||
import com.cloud.agent.api.SecurityIngressRulesCmd;
|
||||
import com.cloud.agent.api.ShutdownCommand;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.resource.AgentResourceBase;
|
||||
import com.cloud.resource.AgentRoutingResource;
|
||||
import com.cloud.resource.AgentStorageResource;
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.simulator.MockHostVO;
|
||||
import com.cloud.simulator.MockVMVO;
|
||||
import com.cloud.simulator.dao.MockHostDao;
|
||||
import com.cloud.simulator.dao.MockVMDao;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
@Local(value = { MockAgentManager.class })
|
||||
public class MockAgentManagerImpl implements MockAgentManager {
|
||||
private static final Logger s_logger = Logger.getLogger(MockAgentManagerImpl.class);
|
||||
@Inject HostPodDao _podDao = null;
|
||||
@Inject MockHostDao _mockHostDao = null;
|
||||
@Inject MockVMDao _mockVmDao = null;
|
||||
@Inject SimulatorManager _simulatorMgr = null;
|
||||
@Inject AgentManager _agentMgr = null;
|
||||
@Inject MockStorageManager _storageMgr = null;
|
||||
private SecureRandom random;
|
||||
private Map<String, AgentResourceBase> _resources = new ConcurrentHashMap<String, AgentResourceBase>();
|
||||
private ThreadPoolExecutor _executor;
|
||||
|
||||
private Pair<String, Long> getPodCidr(long podId, long dcId) {
|
||||
try {
|
||||
|
||||
HashMap<Long, List<Object>> podMap = _podDao
|
||||
.getCurrentPodCidrSubnets(dcId, 0);
|
||||
List<Object> cidrPair = podMap.get(podId);
|
||||
String cidrAddress = (String) cidrPair.get(0);
|
||||
Long cidrSize = (Long)cidrPair.get(1);
|
||||
return new Pair<String, Long>(cidrAddress, cidrSize);
|
||||
} catch (PatternSyntaxException e) {
|
||||
s_logger.error("Exception while splitting pod cidr");
|
||||
return null;
|
||||
} catch(IndexOutOfBoundsException e) {
|
||||
s_logger.error("Invalid pod cidr. Please check");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getIpAddress(long instanceId, long dcId, long podId) {
|
||||
Pair<String, Long> cidr = this.getPodCidr(podId, dcId);
|
||||
return NetUtils.long2Ip(NetUtils.ip2Long(cidr.first()) + instanceId);
|
||||
}
|
||||
|
||||
private String getMacAddress(long dcId, long podId, long clusterId, int instanceId) {
|
||||
return NetUtils.long2Mac((dcId << 40 + podId << 32 + clusterId << 24 + instanceId));
|
||||
}
|
||||
public synchronized int getNextAgentId(long cidrSize) {
|
||||
return random.nextInt((int)cidrSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public Map<AgentResourceBase, Map<String, String>> createServerResources(
|
||||
Map<String, Object> params) {
|
||||
|
||||
Map<String, String> args = new HashMap<String, String>();
|
||||
Map<AgentResourceBase, Map<String,String>> newResources = new HashMap<AgentResourceBase, Map<String,String>>();
|
||||
AgentResourceBase agentResource;
|
||||
long cpuCore = Long.parseLong((String)params.get("cpucore"));
|
||||
long cpuSpeed = Long.parseLong((String)params.get("cpuspeed"));
|
||||
long memory = Long.parseLong((String)params.get("memory"));
|
||||
long localStorageSize = Long.parseLong((String)params.get("localstorage"));
|
||||
synchronized (this) {
|
||||
long dataCenterId = Long.parseLong((String)params.get("zone"));
|
||||
long podId = Long.parseLong((String)params.get("pod"));
|
||||
long clusterId = Long.parseLong((String)params.get("cluster"));
|
||||
long cidrSize = getPodCidr(podId, dataCenterId).second();
|
||||
|
||||
int agentId = getNextAgentId(cidrSize);
|
||||
String ipAddress = getIpAddress(agentId, dataCenterId, podId);
|
||||
String macAddress = getMacAddress(dataCenterId, podId, clusterId, agentId);
|
||||
MockHostVO mockHost = new MockHostVO();
|
||||
mockHost.setDataCenterId(dataCenterId);
|
||||
mockHost.setPodId(podId);
|
||||
mockHost.setClusterId(clusterId);
|
||||
mockHost.setCapabilities("hvm");
|
||||
mockHost.setCpuCount(cpuCore);
|
||||
mockHost.setCpuSpeed(cpuSpeed);
|
||||
mockHost.setMemorySize(memory);
|
||||
String guid = UUID.randomUUID().toString();
|
||||
mockHost.setGuid(guid);
|
||||
mockHost.setName("SimulatedAgent." + guid);
|
||||
mockHost.setPrivateIpAddress(ipAddress);
|
||||
mockHost.setPublicIpAddress(ipAddress);
|
||||
mockHost.setStorageIpAddress(ipAddress);
|
||||
mockHost.setPrivateMacAddress(macAddress);
|
||||
mockHost.setPublicMacAddress(macAddress);
|
||||
mockHost.setStorageMacAddress(macAddress);
|
||||
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
|
||||
mockHost.setResource("com.cloud.agent.AgentRoutingResource");
|
||||
mockHost = _mockHostDao.persist(mockHost);
|
||||
|
||||
_storageMgr.getLocalStorage(guid, localStorageSize);
|
||||
|
||||
agentResource = new AgentRoutingResource();
|
||||
if (agentResource != null) {
|
||||
try {
|
||||
params.put("guid", mockHost.getGuid());
|
||||
agentResource.start();
|
||||
agentResource.configure(mockHost.getName(),
|
||||
params);
|
||||
|
||||
newResources.put(agentResource, args);
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger
|
||||
.error("error while configuring server resource"
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return newResources;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
try {
|
||||
random = SecureRandom.getInstance("SHA1PRNG");
|
||||
_executor = new ThreadPoolExecutor(1, 5, 1, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("Simulator-Agent-Mgr"));
|
||||
//ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
||||
//_simulatorMgr = (SimulatorManager) locator.getComponent(SimulatorManager.Name);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
s_logger.debug("Failed to initialize random:" + e.toString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSystemVMStart(long vmId, String privateIpAddress, String privateMacAddress, String privateNetMask, long dcId, long podId, String name, String vmType, String url) {
|
||||
_executor.execute(new SystemVMHandler(vmId, privateIpAddress, privateMacAddress, privateNetMask, dcId, podId, name, vmType, _simulatorMgr, url));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSystemVMStop(long vmId) {
|
||||
_executor.execute(new SystemVMHandler(vmId));
|
||||
return true;
|
||||
}
|
||||
|
||||
private class SystemVMHandler implements Runnable {
|
||||
private long vmId;
|
||||
private String privateIpAddress;
|
||||
private String privateMacAddress;
|
||||
private String privateNetMask;
|
||||
private long dcId;
|
||||
private long podId;
|
||||
private String guid;
|
||||
private String name;
|
||||
private String vmType;
|
||||
private SimulatorManager mgr;
|
||||
private String mode;
|
||||
private String url;
|
||||
public SystemVMHandler(long vmId, String privateIpAddress, String privateMacAddress, String privateNetMask, long dcId, long podId, String name, String vmType,
|
||||
SimulatorManager mgr, String url) {
|
||||
this.vmId = vmId;
|
||||
this.privateIpAddress = privateIpAddress;
|
||||
this.privateMacAddress = privateMacAddress;
|
||||
this.privateNetMask = privateNetMask;
|
||||
this.dcId = dcId;
|
||||
this.guid = "SystemVM-" + UUID.randomUUID().toString();
|
||||
this.name = name;
|
||||
this.vmType = vmType;
|
||||
this.mgr = mgr;
|
||||
this.mode = "Start";
|
||||
this.url = url;
|
||||
this.podId = podId;
|
||||
}
|
||||
|
||||
public SystemVMHandler(long vmId) {
|
||||
this.vmId = vmId;
|
||||
this.mode = "Stop";
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public void run() {
|
||||
if (this.mode.equalsIgnoreCase("Stop")) {
|
||||
MockHost host = _mockHostDao.findByVmId(this.vmId);
|
||||
if (host != null) {
|
||||
String guid = host.getGuid();
|
||||
if (guid != null) {
|
||||
AgentResourceBase res = _resources.get(guid);
|
||||
if (res != null) {
|
||||
res.stop();
|
||||
_resources.remove(guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String resource = null;
|
||||
if (vmType.equalsIgnoreCase("secstorage")) {
|
||||
resource = "com.cloud.agent.AgentStorageResource";
|
||||
}
|
||||
MockHostVO mockHost = new MockHostVO();
|
||||
mockHost.setDataCenterId(this.dcId);
|
||||
mockHost.setPodId(this.podId);
|
||||
mockHost.setCpuCount(DEFAULT_HOST_CPU_CORES);
|
||||
mockHost.setCpuSpeed(DEFAULT_HOST_SPEED_MHZ);
|
||||
mockHost.setMemorySize(DEFAULT_HOST_MEM_SIZE);
|
||||
mockHost.setGuid(this.guid);
|
||||
mockHost.setName(name);
|
||||
mockHost.setPrivateIpAddress(this.privateIpAddress);
|
||||
mockHost.setPublicIpAddress(this.privateIpAddress);
|
||||
mockHost.setStorageIpAddress(this.privateIpAddress);
|
||||
mockHost.setPrivateMacAddress(this.privateMacAddress);
|
||||
mockHost.setPublicMacAddress(this.privateMacAddress);
|
||||
mockHost.setStorageMacAddress(this.privateMacAddress);
|
||||
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
|
||||
mockHost.setResource(resource);
|
||||
mockHost.setVmId(vmId);
|
||||
mockHost = _mockHostDao.persist(mockHost);
|
||||
|
||||
if (vmType.equalsIgnoreCase("secstorage")) {
|
||||
AgentStorageResource storageResource = new AgentStorageResource();
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("guid", this.guid);
|
||||
storageResource.configure("secondaryStorage", params);
|
||||
storageResource.start();
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.debug("Failed to load secondary storage resource: " + e.toString());
|
||||
return;
|
||||
}
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
|
||||
_agentMgr.addHost(this.dcId, storageResource, Type.SecondaryStorageVM, details);
|
||||
_resources.put(this.guid, storageResource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockHost getHost(String guid) {
|
||||
return _mockHostDao.findByGuid(guid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) {
|
||||
String hostGuid = cmd.getHostGuid();
|
||||
MockHost host = _mockHostDao.findByGuid(hostGuid);
|
||||
if (host == null) {
|
||||
return null;
|
||||
}
|
||||
List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId());
|
||||
double usedMem = 0.0;
|
||||
double usedCpu = 0.0;
|
||||
for (MockVMVO vm : vms) {
|
||||
usedMem += vm.getMemory();
|
||||
usedCpu += vm.getCpu();
|
||||
}
|
||||
|
||||
HostStatsEntry hostStats = new HostStatsEntry();
|
||||
hostStats.setTotalMemoryKBs(host.getMemorySize());
|
||||
hostStats.setFreeMemoryKBs(host.getMemorySize() - usedMem);
|
||||
hostStats.setNetworkReadKBs(32768);
|
||||
hostStats.setNetworkWriteKBs(16384);
|
||||
hostStats.setCpuUtilization(usedCpu/(host.getCpuCount() * host.getCpuSpeed()));
|
||||
hostStats.setEntityType("simulator-host");
|
||||
hostStats.setHostId(cmd.getHostId());
|
||||
return new GetHostStatsAnswer(cmd, hostStats);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Answer checkHealth(CheckHealthCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Answer pingTest(PingTestCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PrepareForMigrationAnswer PrepareForMigration(PrepareForMigrationCommand cmd) {
|
||||
return new PrepareForMigrationAnswer(cmd);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Answer MaintainCommand(com.cloud.agent.api.MaintainCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent.manager;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.AttachIsoCommand;
|
||||
import com.cloud.agent.api.AttachVolumeAnswer;
|
||||
import com.cloud.agent.api.AttachVolumeCommand;
|
||||
import com.cloud.agent.api.BackupSnapshotAnswer;
|
||||
import com.cloud.agent.api.BackupSnapshotCommand;
|
||||
import com.cloud.agent.api.ComputeChecksumCommand;
|
||||
import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
|
||||
import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
|
||||
import com.cloud.agent.api.CreateStoragePoolCommand;
|
||||
import com.cloud.agent.api.CreateVolumeFromSnapshotAnswer;
|
||||
import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
|
||||
import com.cloud.agent.api.DeleteSnapshotBackupAnswer;
|
||||
import com.cloud.agent.api.DeleteSnapshotBackupCommand;
|
||||
import com.cloud.agent.api.DeleteStoragePoolCommand;
|
||||
import com.cloud.agent.api.GetStorageStatsAnswer;
|
||||
import com.cloud.agent.api.GetStorageStatsCommand;
|
||||
import com.cloud.agent.api.ManageSnapshotAnswer;
|
||||
import com.cloud.agent.api.ManageSnapshotCommand;
|
||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
|
||||
import com.cloud.agent.api.SecStorageSetupCommand;
|
||||
import com.cloud.agent.api.SecStorageVMSetupCommand;
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
import com.cloud.agent.api.storage.CreateAnswer;
|
||||
import com.cloud.agent.api.storage.CreateCommand;
|
||||
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
|
||||
import com.cloud.agent.api.storage.CreatePrivateTemplateCommand;
|
||||
import com.cloud.agent.api.storage.DeleteTemplateCommand;
|
||||
import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.storage.DownloadCommand;
|
||||
import com.cloud.agent.api.storage.DownloadProgressCommand;
|
||||
import com.cloud.agent.api.storage.ListTemplateCommand;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
||||
import com.cloud.utils.component.Manager;
|
||||
|
||||
public interface MockStorageManager extends Manager {
|
||||
public static final long DEFAULT_HOST_STORAGE_SIZE = 1 * 1024 * 1024 * 1024 * 1024L; //1T
|
||||
public static final long DEFAULT_TEMPLATE_SIZE = 1 * 1000 * 1000 * 1000L; //1G
|
||||
|
||||
public PrimaryStorageDownloadAnswer primaryStorageDownload(PrimaryStorageDownloadCommand cmd);
|
||||
|
||||
public CreateAnswer createVolume(CreateCommand cmd);
|
||||
public AttachVolumeAnswer AttachVolume(AttachVolumeCommand cmd);
|
||||
public Answer AttachIso(AttachIsoCommand cmd);
|
||||
|
||||
public Answer DeleteStoragePool(DeleteStoragePoolCommand cmd);
|
||||
public Answer ModifyStoragePool(ModifyStoragePoolCommand cmd);
|
||||
public Answer CreateStoragePool(CreateStoragePoolCommand cmd);
|
||||
|
||||
public Answer SecStorageSetup(SecStorageSetupCommand cmd);
|
||||
public Answer ListTemplates(ListTemplateCommand cmd);
|
||||
public Answer Destroy(DestroyCommand cmd);
|
||||
public Answer Download(DownloadCommand cmd);
|
||||
public Answer DownloadProcess(DownloadProgressCommand cmd);
|
||||
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd);
|
||||
public Answer ManageSnapshot(ManageSnapshotCommand cmd);
|
||||
public Answer BackupSnapshot(BackupSnapshotCommand cmd);
|
||||
public Answer DeleteSnapshotBackup(DeleteSnapshotBackupCommand cmd);
|
||||
public Answer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd);
|
||||
public Answer DeleteTemplate(DeleteTemplateCommand cmd);
|
||||
public Answer SecStorageVMSetup(SecStorageVMSetupCommand cmd);
|
||||
|
||||
public void preinstallTemplates(String url, long zoneId);
|
||||
|
||||
StoragePoolInfo getLocalStorage(String hostGuid);
|
||||
|
||||
public Answer CreatePrivateTemplateFromSnapshot(CreatePrivateTemplateFromSnapshotCommand cmd);
|
||||
|
||||
public Answer ComputeChecksum(ComputeChecksumCommand cmd);
|
||||
|
||||
public Answer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd);
|
||||
|
||||
StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize);
|
||||
}
|
||||
|
|
@ -0,0 +1,658 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent.manager;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.AttachIsoCommand;
|
||||
import com.cloud.agent.api.AttachVolumeAnswer;
|
||||
import com.cloud.agent.api.AttachVolumeCommand;
|
||||
import com.cloud.agent.api.BackupSnapshotAnswer;
|
||||
import com.cloud.agent.api.BackupSnapshotCommand;
|
||||
import com.cloud.agent.api.ComputeChecksumCommand;
|
||||
import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
|
||||
import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
|
||||
import com.cloud.agent.api.CreateStoragePoolCommand;
|
||||
import com.cloud.agent.api.CreateVolumeFromSnapshotAnswer;
|
||||
import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
|
||||
import com.cloud.agent.api.DeleteSnapshotBackupCommand;
|
||||
import com.cloud.agent.api.DeleteStoragePoolCommand;
|
||||
import com.cloud.agent.api.GetStorageStatsAnswer;
|
||||
import com.cloud.agent.api.GetStorageStatsCommand;
|
||||
import com.cloud.agent.api.ManageSnapshotAnswer;
|
||||
import com.cloud.agent.api.ManageSnapshotCommand;
|
||||
import com.cloud.agent.api.ModifyStoragePoolAnswer;
|
||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
|
||||
import com.cloud.agent.api.SecStorageSetupAnswer;
|
||||
import com.cloud.agent.api.SecStorageSetupCommand;
|
||||
import com.cloud.agent.api.SecStorageVMSetupCommand;
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
import com.cloud.agent.api.storage.CreateAnswer;
|
||||
import com.cloud.agent.api.storage.CreateCommand;
|
||||
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
|
||||
import com.cloud.agent.api.storage.DeleteTemplateCommand;
|
||||
import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.storage.DownloadAnswer;
|
||||
import com.cloud.agent.api.storage.DownloadCommand;
|
||||
import com.cloud.agent.api.storage.DownloadProgressCommand;
|
||||
import com.cloud.agent.api.storage.ListTemplateAnswer;
|
||||
import com.cloud.agent.api.storage.ListTemplateCommand;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
||||
import com.cloud.agent.api.to.StorageFilerTO;
|
||||
import com.cloud.agent.api.to.VolumeTO;
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.simulator.MockSecStorageVO;
|
||||
import com.cloud.simulator.MockStoragePoolVO;
|
||||
import com.cloud.simulator.MockVMVO;
|
||||
import com.cloud.simulator.MockVolumeVO;
|
||||
import com.cloud.simulator.MockVolumeVO.MockVolumeType;
|
||||
import com.cloud.simulator.dao.MockHostDao;
|
||||
import com.cloud.simulator.dao.MockSecStorageDao;
|
||||
import com.cloud.simulator.dao.MockStoragePoolDao;
|
||||
import com.cloud.simulator.dao.MockVMDao;
|
||||
import com.cloud.simulator.dao.MockVolumeDao;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.template.TemplateInfo;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.vm.DiskProfile;
|
||||
|
||||
|
||||
@Local(value = { MockStorageManager.class })
|
||||
public class MockStorageManagerImpl implements MockStorageManager {
|
||||
private static final Logger s_logger = Logger.getLogger(MockStorageManagerImpl.class);
|
||||
@Inject MockStoragePoolDao _mockStoragePoolDao = null;
|
||||
@Inject MockSecStorageDao _mockSecStorageDao = null;
|
||||
@Inject MockVolumeDao _mockVolumeDao = null;
|
||||
@Inject MockVMDao _mockVMDao = null;
|
||||
@Inject MockHostDao _mockHostDao = null;
|
||||
|
||||
private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
|
||||
|
||||
String volumePath = path.replaceAll(ssUrl, "");
|
||||
|
||||
MockSecStorageVO secStorage = _mockSecStorageDao.findByUrl(ssUrl);
|
||||
if (secStorage == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
volumePath = secStorage.getMountPoint() + volumePath;
|
||||
volumePath = volumePath.replaceAll("//", "/");
|
||||
|
||||
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(volumePath);
|
||||
if (volume == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return volume;
|
||||
}
|
||||
@Override
|
||||
public PrimaryStorageDownloadAnswer primaryStorageDownload(PrimaryStorageDownloadCommand cmd) {
|
||||
MockVolumeVO template = findVolumeFromSecondary(cmd.getUrl(),cmd.getSecondaryStorageUrl(), MockVolumeType.TEMPLATE);
|
||||
if (template == null) {
|
||||
return new PrimaryStorageDownloadAnswer("Can't find primary storage");
|
||||
}
|
||||
|
||||
MockStoragePoolVO primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPoolUuid());
|
||||
if (primaryStorage == null) {
|
||||
return new PrimaryStorageDownloadAnswer("Can't find primary storage");
|
||||
}
|
||||
|
||||
String volumeName = UUID.randomUUID().toString();
|
||||
MockVolumeVO newVolume = new MockVolumeVO();
|
||||
newVolume.setName(volumeName);
|
||||
newVolume.setPath(primaryStorage.getMountPoint() + volumeName);
|
||||
newVolume.setPoolId(primaryStorage.getId());
|
||||
newVolume.setSize(template.getSize());
|
||||
newVolume.setType(MockVolumeType.VOLUME);
|
||||
_mockVolumeDao.persist(newVolume);
|
||||
|
||||
|
||||
return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreateAnswer createVolume(CreateCommand cmd) {
|
||||
StorageFilerTO sf = cmd.getPool();
|
||||
DiskProfile dskch = cmd.getDiskCharacteristics();
|
||||
MockStoragePoolVO storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
|
||||
if (storagePool == null) {
|
||||
return new CreateAnswer(cmd, "Failed to find storage pool: " + sf.getUuid());
|
||||
}
|
||||
|
||||
String volumeName = UUID.randomUUID().toString();
|
||||
MockVolumeVO volume = new MockVolumeVO();
|
||||
volume.setPoolId(storagePool.getId());
|
||||
volume.setName(volumeName);
|
||||
volume.setPath(storagePool.getMountPoint() + volumeName);
|
||||
volume.setSize(dskch.getSize());
|
||||
volume.setType(MockVolumeType.VOLUME);
|
||||
volume = _mockVolumeDao.persist(volume);
|
||||
|
||||
VolumeTO volumeTo = new VolumeTO(cmd.getVolumeId(), dskch.getType(), sf.getType(), sf.getUuid(),
|
||||
volume.getName(), storagePool.getMountPoint(), volume.getPath(), volume.getSize(), null);
|
||||
|
||||
return new CreateAnswer(cmd, volumeTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttachVolumeAnswer AttachVolume(AttachVolumeCommand cmd) {
|
||||
String poolid = cmd.getPoolUuid();
|
||||
String volumeName = cmd.getVolumeName();
|
||||
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
|
||||
if (volume == null) {
|
||||
return new AttachVolumeAnswer(cmd, "Can't find volume:" + volumeName + "on pool:" + poolid);
|
||||
}
|
||||
|
||||
String vmName = cmd.getVmName();
|
||||
MockVMVO vm = _mockVMDao.findByVmName(vmName);
|
||||
if (vm == null) {
|
||||
return new AttachVolumeAnswer(cmd, "can't vm :" + vmName);
|
||||
}
|
||||
|
||||
return new AttachVolumeAnswer(cmd, cmd.getDeviceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer AttachIso(AttachIsoCommand cmd) {
|
||||
MockVolumeVO iso = findVolumeFromSecondary(cmd.getIsoPath(), cmd.getStoreUrl(), MockVolumeType.ISO);
|
||||
if (iso == null) {
|
||||
return new Answer(cmd, false, "Failed to find the iso: " + cmd.getIsoPath() + "on secondary storage " + cmd.getStoreUrl());
|
||||
}
|
||||
|
||||
String vmName = cmd.getVmName();
|
||||
MockVMVO vm = _mockVMDao.findByVmName(vmName);
|
||||
if (vm == null) {
|
||||
return new Answer(cmd, false, "can't vm :" + vmName);
|
||||
}
|
||||
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer DeleteStoragePool(DeleteStoragePoolCommand cmd) {
|
||||
MockStoragePoolVO storage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
|
||||
if (storage == null) {
|
||||
return new Answer(cmd, false, "can't find storage pool:" + cmd.getPool().getUuid());
|
||||
}
|
||||
_mockStoragePoolDao.remove(storage.getId());
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModifyStoragePoolAnswer ModifyStoragePool(ModifyStoragePoolCommand cmd) {
|
||||
StorageFilerTO sf = cmd.getPool();
|
||||
MockStoragePoolVO storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
|
||||
if (storagePool == null) {
|
||||
storagePool = new MockStoragePoolVO();
|
||||
storagePool.setUuid(sf.getUuid());
|
||||
storagePool.setMountPoint("/mnt/" + sf.getUuid() + File.separator);
|
||||
|
||||
Long size = DEFAULT_HOST_STORAGE_SIZE;
|
||||
String path = sf.getPath();
|
||||
int index = path.lastIndexOf("/");
|
||||
if (index != -1) {
|
||||
path = path.substring(index+1);
|
||||
if (path != null) {
|
||||
String values[] = path.split("=");
|
||||
if (values.length > 1 && values[0].equalsIgnoreCase("size")) {
|
||||
size = Long.parseLong(values[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
storagePool.setCapacity(size);
|
||||
|
||||
storagePool.setStorageType(sf.getType());
|
||||
storagePool = _mockStoragePoolDao.persist(storagePool);
|
||||
}
|
||||
|
||||
return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateInfo>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer CreateStoragePool(CreateStoragePoolCommand cmd) {
|
||||
StorageFilerTO sf = cmd.getPool();
|
||||
MockStoragePoolVO storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
|
||||
if (storagePool == null) {
|
||||
storagePool = new MockStoragePoolVO();
|
||||
storagePool.setUuid(sf.getUuid());
|
||||
storagePool.setMountPoint("/mnt/" + sf.getUuid() + File.separator);
|
||||
|
||||
Long size = DEFAULT_HOST_STORAGE_SIZE;
|
||||
String path = sf.getPath();
|
||||
int index = path.lastIndexOf("/");
|
||||
if (index != -1) {
|
||||
path = path.substring(index+1);
|
||||
if (path != null) {
|
||||
String values[] = path.split("=");
|
||||
if (values.length > 1 && values[0].equalsIgnoreCase("size")) {
|
||||
size = Long.parseLong(values[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
storagePool.setCapacity(size);
|
||||
|
||||
storagePool.setStorageType(sf.getType());
|
||||
storagePool = _mockStoragePoolDao.persist(storagePool);
|
||||
}
|
||||
|
||||
return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateInfo>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer SecStorageSetup(SecStorageSetupCommand cmd) {
|
||||
MockSecStorageVO storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
|
||||
if (storage == null) {
|
||||
return new Answer(cmd, false, "can't find the storage");
|
||||
}
|
||||
return new SecStorageSetupAnswer(storage.getMountPoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer ListTemplates(ListTemplateCommand cmd) {
|
||||
MockSecStorageVO storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
|
||||
if (storage == null) {
|
||||
return new Answer(cmd, false, "Failed to get secondary storage");
|
||||
}
|
||||
|
||||
List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.TEMPLATE);
|
||||
Map<String, TemplateInfo> templateInfos = new HashMap<String, TemplateInfo>();
|
||||
for (MockVolumeVO template : templates) {
|
||||
templateInfos.put(template.getName(), new TemplateInfo(template.getName(), template.getPath().replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
|
||||
}
|
||||
|
||||
return new ListTemplateAnswer(cmd.getSecUrl(), templateInfos);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer Destroy(DestroyCommand cmd) {
|
||||
|
||||
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolume().getPath());
|
||||
if (volume != null) {
|
||||
_mockVolumeDao.remove(volume.getId());
|
||||
}
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DownloadAnswer Download(DownloadCommand cmd) {
|
||||
MockSecStorageVO ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
|
||||
if (ssvo == null) {
|
||||
return new DownloadAnswer("can't find secondary storage", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
|
||||
}
|
||||
|
||||
MockVolumeVO volume = new MockVolumeVO();
|
||||
volume.setPoolId(ssvo.getId());
|
||||
volume.setName(cmd.getName());
|
||||
volume.setPath(ssvo.getMountPoint() + cmd.getName());
|
||||
volume.setSize(0);
|
||||
volume.setType(MockVolumeType.TEMPLATE);
|
||||
volume.setStatus(Status.DOWNLOAD_IN_PROGRESS);
|
||||
volume = _mockVolumeDao.persist(volume);
|
||||
|
||||
return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS, cmd.getName(), cmd.getName(), volume.getSize(), volume.getSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DownloadAnswer DownloadProcess(DownloadProgressCommand cmd) {
|
||||
String volumeId = cmd.getJobId();
|
||||
MockVolumeVO volume = _mockVolumeDao.findById(Long.parseLong(volumeId));
|
||||
if (volume == null) {
|
||||
return new DownloadAnswer("Can't find the downloading volume", Status.ABANDONED);
|
||||
}
|
||||
|
||||
long size = Math.min(volume.getSize() + DEFAULT_TEMPLATE_SIZE/5, DEFAULT_TEMPLATE_SIZE);
|
||||
volume.setSize(size);
|
||||
|
||||
double volumeSize = volume.getSize();
|
||||
double pct = volumeSize/DEFAULT_TEMPLATE_SIZE;
|
||||
if (pct >= 1.0) {
|
||||
volume.setStatus(Status.DOWNLOADED);
|
||||
_mockVolumeDao.update(volume.getId(), volume);
|
||||
return new DownloadAnswer(cmd.getJobId(), 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, volume.getPath(), volume.getName());
|
||||
} else {
|
||||
_mockVolumeDao.update(volume.getId(), volume);
|
||||
return new DownloadAnswer(cmd.getJobId(), (int)(pct*100.0) , cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS, volume.getPath(), volume.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
|
||||
String uuid = cmd.getStorageId();
|
||||
if (uuid == null) {
|
||||
String secUrl = cmd.getSecUrl();
|
||||
MockSecStorageVO secondary = _mockSecStorageDao.findByUrl(secUrl);
|
||||
if (secondary == null) {
|
||||
return new GetStorageStatsAnswer(cmd, "Can't find the secondary storage:" + secUrl);
|
||||
}
|
||||
Long totalUsed = _mockVolumeDao.findTotalStorageId(secondary.getId());
|
||||
return new GetStorageStatsAnswer(cmd, secondary.getCapacity(), totalUsed);
|
||||
} else {
|
||||
MockStoragePoolVO pool = _mockStoragePoolDao.findByUuid(uuid);
|
||||
if (pool == null) {
|
||||
return new GetStorageStatsAnswer(cmd, "Can't find the pool");
|
||||
}
|
||||
Long totalUsed = _mockVolumeDao.findTotalStorageId(pool.getId());
|
||||
if (totalUsed == null) {
|
||||
totalUsed = 0L;
|
||||
}
|
||||
return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManageSnapshotAnswer ManageSnapshot(ManageSnapshotCommand cmd) {
|
||||
String volPath = cmd.getVolumePath();
|
||||
|
||||
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(volPath);
|
||||
if (volume == null) {
|
||||
return new ManageSnapshotAnswer(cmd, false, "Can't find the volume");
|
||||
}
|
||||
MockStoragePoolVO storagePool = _mockStoragePoolDao.findById(volume.getPoolId());
|
||||
if (storagePool == null) {
|
||||
return new ManageSnapshotAnswer(cmd, false, "Can't find the storage pooll");
|
||||
}
|
||||
|
||||
String mountPoint = storagePool.getMountPoint();
|
||||
MockVolumeVO snapshot = new MockVolumeVO();
|
||||
|
||||
snapshot.setName(cmd.getSnapshotName());
|
||||
snapshot.setPath(mountPoint + cmd.getSnapshotName());
|
||||
snapshot.setSize(volume.getSize());
|
||||
snapshot.setPoolId(storagePool.getId());
|
||||
snapshot.setType(MockVolumeType.SNAPSHOT);
|
||||
snapshot.setStatus(Status.DOWNLOADED);
|
||||
|
||||
snapshot = _mockVolumeDao.persist(snapshot);
|
||||
|
||||
return new ManageSnapshotAnswer(cmd, snapshot.getId(), snapshot.getPath(), true, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BackupSnapshotAnswer BackupSnapshot(BackupSnapshotCommand cmd) {
|
||||
String snapshotPath = cmd.getSnapshotUuid();
|
||||
MockVolumeVO snapshot = _mockVolumeDao.findByStoragePathAndType(snapshotPath);
|
||||
if (snapshot == null) {
|
||||
return new BackupSnapshotAnswer(cmd, false, "can't find snapshot" + snapshotPath, null, true);
|
||||
}
|
||||
|
||||
String secStorageUrl = cmd.getSecondaryStoragePoolURL();
|
||||
MockSecStorageVO secStorage = _mockSecStorageDao.findByUrl(secStorageUrl);
|
||||
if (secStorage == null) {
|
||||
return new BackupSnapshotAnswer(cmd, false, "can't find sec storage" + snapshotPath, null, true);
|
||||
}
|
||||
MockVolumeVO newsnapshot = new MockVolumeVO();
|
||||
String name = UUID.randomUUID().toString();
|
||||
newsnapshot.setName(name);
|
||||
newsnapshot.setPath(secStorage.getMountPoint() + name);
|
||||
newsnapshot.setPoolId(secStorage.getId());
|
||||
newsnapshot.setSize(snapshot.getSize());
|
||||
newsnapshot.setStatus(Status.DOWNLOADED);
|
||||
newsnapshot.setType(MockVolumeType.SNAPSHOT);
|
||||
newsnapshot = _mockVolumeDao.persist(newsnapshot);
|
||||
|
||||
return new BackupSnapshotAnswer(cmd, true, null, newsnapshot.getName(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer DeleteSnapshotBackup(DeleteSnapshotBackupCommand cmd) {
|
||||
|
||||
MockVolumeVO backSnapshot = _mockVolumeDao.findByName(cmd.getSnapshotUuid());
|
||||
if (backSnapshot == null) {
|
||||
return new Answer(cmd, false, "can't find the backupsnapshot: " + cmd.getSnapshotUuid());
|
||||
}
|
||||
|
||||
_mockVolumeDao.remove(backSnapshot.getId());
|
||||
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
|
||||
MockVolumeVO backSnapshot = _mockVolumeDao.findByName(cmd.getSnapshotUuid());
|
||||
if (backSnapshot == null) {
|
||||
return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the backupsnapshot: " + cmd.getSnapshotUuid(), null);
|
||||
}
|
||||
|
||||
MockStoragePoolVO primary = _mockStoragePoolDao.findByUuid(cmd.getPrimaryStoragePoolNameLabel());
|
||||
if (primary == null) {
|
||||
return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the primary storage: " + cmd.getPrimaryStoragePoolNameLabel(), null);
|
||||
}
|
||||
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
MockVolumeVO volume = new MockVolumeVO();
|
||||
|
||||
volume.setName(uuid);
|
||||
volume.setPath(primary.getMountPoint() + uuid);
|
||||
volume.setPoolId(primary.getId());
|
||||
volume.setSize(backSnapshot.getSize());
|
||||
volume.setStatus(Status.DOWNLOADED);
|
||||
volume.setType(MockVolumeType.VOLUME);
|
||||
_mockVolumeDao.persist(volume);
|
||||
|
||||
return new CreateVolumeFromSnapshotAnswer(cmd, true, null, volume.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer DeleteTemplate(DeleteTemplateCommand cmd) {
|
||||
MockVolumeVO template = _mockVolumeDao.findByStoragePathAndType(cmd.getTemplatePath());
|
||||
if (template == null) {
|
||||
return new Answer(cmd, false, "can't find template:" + cmd.getTemplatePath());
|
||||
}
|
||||
|
||||
_mockVolumeDao.remove(template.getId());
|
||||
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer SecStorageVMSetup(SecStorageVMSetupCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preinstallTemplates(String url, long zoneId) {
|
||||
MockSecStorageVO storage = _mockSecStorageDao.findByUrl(url);
|
||||
if (storage == null) {
|
||||
storage = new MockSecStorageVO();
|
||||
URI uri;
|
||||
try {
|
||||
uri = new URI(url);
|
||||
} catch (URISyntaxException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
String nfsHost = uri.getHost();
|
||||
String nfsPath = uri.getPath();
|
||||
String path = nfsHost + ":" + nfsPath;
|
||||
String dir = "/mnt/" + UUID.nameUUIDFromBytes(path.getBytes()).toString() + File.separator;
|
||||
|
||||
storage.setUrl(url);
|
||||
storage.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
|
||||
|
||||
storage.setMountPoint(dir);
|
||||
|
||||
storage = _mockSecStorageDao.persist(storage);
|
||||
|
||||
//preinstall default templates into secondary storage
|
||||
long defaultTemplateSize = 2 * 1024 * 1024 * 1024L;
|
||||
MockVolumeVO template = new MockVolumeVO();
|
||||
template.setName("simulator-domR");
|
||||
template.setPath(storage.getMountPoint() + "template/tmpl/1/9/" + UUID.randomUUID().toString());
|
||||
template.setPoolId(storage.getId());
|
||||
template.setSize(defaultTemplateSize);
|
||||
template.setType(MockVolumeType.TEMPLATE);
|
||||
template.setStatus(Status.DOWNLOADED);
|
||||
_mockVolumeDao.persist(template);
|
||||
|
||||
template = new MockVolumeVO();
|
||||
template.setName("simulator-Centos");
|
||||
template.setPath(storage.getMountPoint() + "template/tmpl/1/10/" + UUID.randomUUID().toString());
|
||||
template.setPoolId(storage.getId());
|
||||
template.setSize(defaultTemplateSize);
|
||||
template.setType(MockVolumeType.TEMPLATE);
|
||||
_mockVolumeDao.persist(template);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoragePoolInfo getLocalStorage(String hostGuid) {
|
||||
MockHost host = _mockHostDao.findByGuid(hostGuid);
|
||||
|
||||
MockStoragePoolVO storagePool = _mockStoragePoolDao.findByHost(hostGuid);
|
||||
if (storagePool == null) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
storagePool = new MockStoragePoolVO();
|
||||
storagePool.setUuid(uuid);
|
||||
storagePool.setMountPoint("/mnt/" + uuid + File.separator);
|
||||
storagePool.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
|
||||
storagePool.setHostGuid(hostGuid);
|
||||
storagePool.setStorageType(StoragePoolType.Filesystem);
|
||||
storagePool = _mockStoragePoolDao.persist(storagePool);
|
||||
}
|
||||
|
||||
|
||||
return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize) {
|
||||
MockHost host = _mockHostDao.findByGuid(hostGuid);
|
||||
if (storageSize == null) {
|
||||
storageSize = DEFAULT_HOST_STORAGE_SIZE;
|
||||
}
|
||||
MockStoragePoolVO storagePool = _mockStoragePoolDao.findByHost(hostGuid);
|
||||
if (storagePool == null) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
storagePool = new MockStoragePoolVO();
|
||||
storagePool.setUuid(uuid);
|
||||
storagePool.setMountPoint("/mnt/" + uuid + File.separator);
|
||||
storagePool.setCapacity(storageSize);
|
||||
storagePool.setHostGuid(hostGuid);
|
||||
storagePool.setStorageType(StoragePoolType.Filesystem);
|
||||
storagePool = _mockStoragePoolDao.persist(storagePool);
|
||||
}
|
||||
|
||||
|
||||
return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromSnapshot(CreatePrivateTemplateFromSnapshotCommand cmd) {
|
||||
String snapshotUUId = cmd.getSnapshotUuid();
|
||||
MockVolumeVO snapshot = _mockVolumeDao.findByName(snapshotUUId);
|
||||
if (snapshot == null) {
|
||||
snapshotUUId = cmd.getSnapshotName();
|
||||
snapshot = _mockVolumeDao.findByName(snapshotUUId);
|
||||
if (snapshot == null) {
|
||||
return new CreatePrivateTemplateAnswer(cmd, false, "can't find snapshot:" + snapshotUUId);
|
||||
}
|
||||
}
|
||||
|
||||
MockSecStorageVO sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStoragePoolURL());
|
||||
if (sec == null) {
|
||||
return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
|
||||
}
|
||||
|
||||
MockVolumeVO template = new MockVolumeVO();
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
template.setName(uuid);
|
||||
template.setPath(sec.getMountPoint() + uuid);
|
||||
template.setPoolId(sec.getId());
|
||||
template.setSize(snapshot.getSize());
|
||||
template.setStatus(Status.DOWNLOADED);
|
||||
template.setType(MockVolumeType.TEMPLATE);
|
||||
template = _mockVolumeDao.persist(template);
|
||||
|
||||
return new CreatePrivateTemplateAnswer(cmd, true, "", template.getName(), template.getSize(), template.getSize(), template.getName(), ImageFormat.QCOW2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer ComputeChecksum(ComputeChecksumCommand cmd) {
|
||||
MockVolumeVO volume = _mockVolumeDao.findByName(cmd.getTemplatePath());
|
||||
if (volume == null) {
|
||||
return new Answer(cmd, false, "cant' find volume:" + cmd.getTemplatePath());
|
||||
}
|
||||
String md5 = null;
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("md5");
|
||||
md5 = String.format("%032x", new BigInteger(1, md.digest(cmd.getTemplatePath().getBytes())));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
s_logger.debug("failed to gernerate md5:" + e.toString());
|
||||
}
|
||||
|
||||
return new Answer(cmd, true, md5);
|
||||
}
|
||||
@Override
|
||||
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd) {
|
||||
MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
|
||||
if (volume == null) {
|
||||
return new CreatePrivateTemplateAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath());
|
||||
}
|
||||
|
||||
MockSecStorageVO sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStoragePoolURL());
|
||||
if (sec == null) {
|
||||
return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
|
||||
}
|
||||
|
||||
MockVolumeVO template = new MockVolumeVO();
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
template.setName(uuid);
|
||||
template.setPath(sec.getMountPoint() + uuid);
|
||||
template.setPoolId(sec.getId());
|
||||
template.setSize(volume.getSize());
|
||||
template.setStatus(Status.DOWNLOADED);
|
||||
template.setType(MockVolumeType.TEMPLATE);
|
||||
template = _mockVolumeDao.persist(template);
|
||||
|
||||
return new CreatePrivateTemplateAnswer(cmd, true, "", template.getName(), template.getSize(), template.getSize(), template.getName(), ImageFormat.QCOW2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent.manager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.CheckVirtualMachineCommand;
|
||||
import com.cloud.agent.api.CleanupNetworkRulesCmd;
|
||||
import com.cloud.agent.api.GetVmStatsCommand;
|
||||
import com.cloud.agent.api.GetVncPortCommand;
|
||||
import com.cloud.agent.api.MigrateAnswer;
|
||||
import com.cloud.agent.api.MigrateCommand;
|
||||
import com.cloud.agent.api.NetworkUsageAnswer;
|
||||
import com.cloud.agent.api.NetworkUsageCommand;
|
||||
import com.cloud.agent.api.RebootCommand;
|
||||
import com.cloud.agent.api.SecurityIngressRulesCmd;
|
||||
import com.cloud.agent.api.StartCommand;
|
||||
import com.cloud.agent.api.StopCommand;
|
||||
import com.cloud.agent.api.VmStatsEntry;
|
||||
import com.cloud.agent.api.check.CheckSshAnswer;
|
||||
import com.cloud.agent.api.check.CheckSshCommand;
|
||||
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
|
||||
import com.cloud.agent.api.routing.SavePasswordCommand;
|
||||
import com.cloud.agent.api.routing.SetPortForwardingRulesAnswer;
|
||||
import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
|
||||
import com.cloud.agent.api.routing.SetStaticNatRulesAnswer;
|
||||
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
|
||||
import com.cloud.agent.api.routing.VmDataCommand;
|
||||
import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.to.NicTO;
|
||||
import com.cloud.simulator.MockVm;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
public interface MockVmManager extends Manager {
|
||||
public Answer stopVM(StopCommand cmd);
|
||||
public Answer rebootVM(RebootCommand cmd);
|
||||
|
||||
public boolean migrate(String vmName, String params);
|
||||
|
||||
public Answer checkVmState(CheckVirtualMachineCommand cmd, String hostGuid);
|
||||
public Map<String, State> getVmStates(String hostGuid);
|
||||
public Answer getVncPort(GetVncPortCommand cmd);
|
||||
|
||||
Answer startVM(StartCommand cmd, String hostGuid);
|
||||
|
||||
Answer getVmStats(GetVmStatsCommand cmd);
|
||||
public CheckSshAnswer checkSshCommand(CheckSshCommand cmd);
|
||||
|
||||
Answer SetStaticNatRules(SetStaticNatRulesCommand cmd);
|
||||
|
||||
Answer SetPortForwardingRules(SetPortForwardingRulesCommand cmd);
|
||||
|
||||
Answer getNetworkUsage(NetworkUsageCommand cmd);
|
||||
|
||||
Answer Migrate(MigrateCommand cmd, String hostGuid);
|
||||
|
||||
Answer IpAssoc(IpAssocCommand cmd);
|
||||
|
||||
Answer LoadBalancerConfig(LoadBalancerConfigCommand cmd);
|
||||
|
||||
Answer AddDhcpEntry(DhcpEntryCommand cmd);
|
||||
|
||||
Answer setVmData(VmDataCommand cmd);
|
||||
Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, String hostGuid);
|
||||
|
||||
Answer CheckConsoleProxyLoad(CheckConsoleProxyLoadCommand cmd);
|
||||
Answer WatchConsoleProxyLoad(WatchConsoleProxyLoadCommand cmd);
|
||||
|
||||
Answer AddSecurityIngressRules(SecurityIngressRulesCmd cmd);
|
||||
Answer SavePassword(SavePasswordCommand cmd);
|
||||
HashMap<String, Pair<Long, Long>> syncNetworkGroups(String hostGuid);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,398 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent.manager;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.CheckVirtualMachineAnswer;
|
||||
import com.cloud.agent.api.CheckVirtualMachineCommand;
|
||||
import com.cloud.agent.api.CleanupNetworkRulesCmd;
|
||||
import com.cloud.agent.api.GetVmStatsAnswer;
|
||||
import com.cloud.agent.api.GetVmStatsCommand;
|
||||
import com.cloud.agent.api.GetVncPortAnswer;
|
||||
import com.cloud.agent.api.GetVncPortCommand;
|
||||
import com.cloud.agent.api.MigrateAnswer;
|
||||
import com.cloud.agent.api.MigrateCommand;
|
||||
import com.cloud.agent.api.NetworkUsageAnswer;
|
||||
import com.cloud.agent.api.NetworkUsageCommand;
|
||||
import com.cloud.agent.api.RebootCommand;
|
||||
import com.cloud.agent.api.SecurityIngressRuleAnswer;
|
||||
import com.cloud.agent.api.SecurityIngressRulesCmd;
|
||||
import com.cloud.agent.api.StartAnswer;
|
||||
import com.cloud.agent.api.StartCommand;
|
||||
import com.cloud.agent.api.StopAnswer;
|
||||
import com.cloud.agent.api.StopCommand;
|
||||
import com.cloud.agent.api.VmStatsEntry;
|
||||
import com.cloud.agent.api.check.CheckSshAnswer;
|
||||
import com.cloud.agent.api.check.CheckSshCommand;
|
||||
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
|
||||
import com.cloud.agent.api.routing.SavePasswordCommand;
|
||||
import com.cloud.agent.api.routing.SetPortForwardingRulesAnswer;
|
||||
import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
|
||||
import com.cloud.agent.api.routing.SetStaticNatRulesAnswer;
|
||||
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
|
||||
import com.cloud.agent.api.routing.VmDataCommand;
|
||||
import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.to.NicTO;
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.simulator.MockHostVO;
|
||||
import com.cloud.simulator.MockSecurityRulesVO;
|
||||
import com.cloud.simulator.MockVMVO;
|
||||
import com.cloud.simulator.MockVm;
|
||||
import com.cloud.simulator.dao.MockHostDao;
|
||||
import com.cloud.simulator.dao.MockSecurityRulesDao;
|
||||
import com.cloud.simulator.dao.MockVMDao;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Inject;
|
||||
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
@Local(value = { MockVmManager.class })
|
||||
public class MockVmManagerImpl implements MockVmManager {
|
||||
private static final Logger s_logger = Logger.getLogger(MockVmManagerImpl.class);
|
||||
|
||||
@Inject MockVMDao _mockVmDao = null;
|
||||
@Inject MockAgentManager _mockAgentMgr = null;
|
||||
@Inject MockHostDao _mockHostDao = null;
|
||||
@Inject MockSecurityRulesDao _mockSecurityDao = null;
|
||||
|
||||
public MockVmManagerImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public String startVM(String vmName, NicTO[] nics,
|
||||
int cpuHz, long ramSize,
|
||||
String bootArgs, String hostGuid) {
|
||||
|
||||
MockHost host = _mockHostDao.findByGuid(hostGuid);
|
||||
if (host == null) {
|
||||
return "can't find host";
|
||||
}
|
||||
|
||||
MockVm vm = _mockVmDao.findByVmName(vmName);
|
||||
if(vm == null) {
|
||||
int vncPort = 0;
|
||||
if(vncPort < 0)
|
||||
return "Unable to allocate VNC port";
|
||||
vm = new MockVMVO();
|
||||
vm.setCpu(cpuHz);
|
||||
vm.setMemory(ramSize);
|
||||
vm.setState(State.Running);
|
||||
vm.setName(vmName);
|
||||
vm.setVncPort(vncPort);
|
||||
vm.setHostId(host.getId());
|
||||
vm = _mockVmDao.persist((MockVMVO)vm);
|
||||
} else {
|
||||
if(vm.getState() == State.Stopped) {
|
||||
vm.setState(State.Running);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO)vm);
|
||||
}
|
||||
}
|
||||
|
||||
if (vm.getState() == State.Running && vmName.startsWith("s-")) {
|
||||
String prvIp = null;
|
||||
String prvMac = null;
|
||||
String prvNetMask = null;
|
||||
|
||||
for (NicTO nic : nics) {
|
||||
if (nic.getType() == TrafficType.Management) {
|
||||
prvIp = nic.getIp();
|
||||
prvMac = nic.getMac();
|
||||
prvNetMask = nic.getNetmask();
|
||||
}
|
||||
}
|
||||
long dcId = 0;
|
||||
long podId = 0;
|
||||
String name = null;
|
||||
String vmType = null;
|
||||
String url = null;
|
||||
String[] args = bootArgs.trim().split(" ");
|
||||
for (String arg : args) {
|
||||
String[] params = arg.split("=");
|
||||
if (params.length < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (params[0].equalsIgnoreCase("zone")) {
|
||||
dcId = Long.parseLong(params[1]);
|
||||
} else if (params[0].equalsIgnoreCase("name")) {
|
||||
name = params[1];
|
||||
} else if (params[0].equalsIgnoreCase("type")) {
|
||||
vmType = params[1];
|
||||
} else if (params[0].equalsIgnoreCase("url")) {
|
||||
url = params[1];
|
||||
} else if (params[0].equalsIgnoreCase("pod")) {
|
||||
podId = Long.parseLong(params[1]);
|
||||
}
|
||||
}
|
||||
|
||||
_mockAgentMgr.handleSystemVMStart(vm.getId(), prvIp, prvMac, prvNetMask, dcId, podId, name, vmType, url);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean rebootVM(String vmName) {
|
||||
MockVm vm = _mockVmDao.findByVmName(vmName);
|
||||
if(vm != null) {
|
||||
vm.setState(State.Running);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO)vm);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean migrate(String vmName, String params) {
|
||||
MockVm vm = _mockVmDao.findByVmName(vmName);
|
||||
if(vm != null) {
|
||||
vm.setState(State.Stopped);
|
||||
_mockVmDao.remove(vm.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, State> getVmStates(String hostGuid) {
|
||||
Map<String, State> states = new HashMap<String, State>();
|
||||
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
|
||||
if (vms.isEmpty()) {
|
||||
return states;
|
||||
}
|
||||
|
||||
for(MockVm vm : vms) {
|
||||
states.put(vm.getName(), vm.getState());
|
||||
}
|
||||
|
||||
return states;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer getVmStats(GetVmStatsCommand cmd) {
|
||||
HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
|
||||
List<String> vmNames = cmd.getVmNames();
|
||||
for (String vmName : vmNames) {
|
||||
VmStatsEntry entry = new VmStatsEntry(0, 0, 0, 0, "vm");
|
||||
entry.setNetworkReadKBs(32768); // default values 256 KBps
|
||||
entry.setNetworkWriteKBs(16384);
|
||||
entry.setCPUUtilization(10);
|
||||
entry.setNumCPUs(1);
|
||||
vmStatsNameMap.put(vmName, entry);
|
||||
}
|
||||
return new GetVmStatsAnswer(cmd, vmStatsNameMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckVirtualMachineAnswer checkVmState(CheckVirtualMachineCommand cmd, String hostGuid) {
|
||||
MockVMVO vm = _mockVmDao.findByVmNameAndHost(cmd.getVmName(), hostGuid);
|
||||
if (vm == null) {
|
||||
return new CheckVirtualMachineAnswer(cmd, "can't find vm:" + cmd.getVmName());
|
||||
}
|
||||
|
||||
return new CheckVirtualMachineAnswer(cmd, vm.getState(), vm.getVncPort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer startVM(StartCommand cmd, String hostGuid) {
|
||||
VirtualMachineTO vm = cmd.getVirtualMachine();
|
||||
String result = startVM(vm.getName(), vm.getNics(), vm.getCpus()* vm.getSpeed(), vm.getMaxRam(), vm.getBootArgs(), hostGuid);
|
||||
if (result != null) {
|
||||
return new StartAnswer(cmd, result);
|
||||
} else {
|
||||
return new StartAnswer(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckSshAnswer checkSshCommand(CheckSshCommand cmd) {
|
||||
return new CheckSshAnswer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer SetStaticNatRules(SetStaticNatRulesCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer SetPortForwardingRules(SetPortForwardingRulesCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkUsageAnswer getNetworkUsage(NetworkUsageCommand cmd) {
|
||||
return new NetworkUsageAnswer(cmd, null, 100L, 100L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MigrateAnswer Migrate(MigrateCommand cmd, String hostGuid) {
|
||||
String vmName = cmd.getVmName();
|
||||
String destGuid = cmd.getHostGuid();
|
||||
MockVMVO vm = _mockVmDao.findByVmNameAndHost(vmName, hostGuid);
|
||||
if (vm == null) {
|
||||
return new MigrateAnswer(cmd, false, "can;t find vm:" + vmName + " on host:" + hostGuid, null);
|
||||
}
|
||||
|
||||
MockHost destHost = _mockHostDao.findByGuid(destGuid);
|
||||
if (destHost == null) {
|
||||
return new MigrateAnswer(cmd, false, "can;t find host:" + hostGuid, null);
|
||||
}
|
||||
vm.setHostId(destHost.getId());
|
||||
_mockVmDao.update(vm.getId(), vm);
|
||||
return new MigrateAnswer(cmd, true,null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer IpAssoc(IpAssocCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer LoadBalancerConfig(LoadBalancerConfigCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer AddDhcpEntry(DhcpEntryCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer setVmData(VmDataCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, String hostGuid) {
|
||||
List<MockSecurityRulesVO> rules = _mockSecurityDao.findByHost(hostGuid);
|
||||
for (MockSecurityRulesVO rule : rules) {
|
||||
MockVMVO vm = _mockVmDao.findByVmNameAndHost(rule.getVmName(), hostGuid);
|
||||
if (vm == null) {
|
||||
_mockSecurityDao.remove(rule.getId());
|
||||
}
|
||||
}
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer stopVM(StopCommand cmd) {
|
||||
String vmName = cmd.getVmName();
|
||||
MockVm vm = _mockVmDao.findByVmName(vmName);
|
||||
if(vm != null) {
|
||||
vm.setState(State.Stopped);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO)vm);
|
||||
}
|
||||
|
||||
if (vmName.startsWith("s-")) {
|
||||
_mockAgentMgr.handleSystemVMStop(vm.getId());
|
||||
}
|
||||
|
||||
return new StopAnswer(cmd, null, new Integer(0), new Long(100), new Long(200));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer rebootVM(RebootCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer getVncPort(GetVncPortCommand cmd) {
|
||||
return new GetVncPortAnswer(cmd, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer CheckConsoleProxyLoad(CheckConsoleProxyLoadCommand cmd) {
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer WatchConsoleProxyLoad(WatchConsoleProxyLoadCommand cmd) {
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecurityIngressRuleAnswer AddSecurityIngressRules(SecurityIngressRulesCmd cmd) {
|
||||
MockVMVO vm = _mockVmDao.findByVmName(cmd.getVmName());
|
||||
if (vm == null) {
|
||||
return new SecurityIngressRuleAnswer(cmd, false, "cant' find the vm: " + cmd.getVmName());
|
||||
}
|
||||
|
||||
MockSecurityRulesVO rules = _mockSecurityDao.findByVmId(cmd.getVmId());
|
||||
if (rules == null) {
|
||||
rules = new MockSecurityRulesVO();
|
||||
rules.setRuleSet(cmd.stringifyRules());
|
||||
rules.setSeqNum(cmd.getSeqNum());
|
||||
rules.setSignature(cmd.getSignature());
|
||||
rules.setVmId(vm.getId());
|
||||
rules.setHostId(vm.getHostId());
|
||||
|
||||
_mockSecurityDao.persist(rules);
|
||||
} else {
|
||||
rules.setSeqNum(cmd.getSeqNum());
|
||||
rules.setSignature(cmd.getSignature());
|
||||
rules.setRuleSet(cmd.stringifyRules());
|
||||
rules.setVmId(cmd.getVmId());
|
||||
rules.setHostId(vm.getHostId());
|
||||
_mockSecurityDao.update(rules.getId(), rules);
|
||||
}
|
||||
|
||||
return new SecurityIngressRuleAnswer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer SavePassword(SavePasswordCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Pair<Long, Long>> syncNetworkGroups(String hostGuid) {
|
||||
HashMap<String, Pair<Long, Long>> maps = new HashMap<String, Pair<Long, Long>>();
|
||||
List<MockSecurityRulesVO> rules = _mockSecurityDao.findByHost(hostGuid);
|
||||
for (MockSecurityRulesVO rule : rules) {
|
||||
maps.put(rule.getVmName(), new Pair<Long, Long>(rule.getVmId(), rule.getSeqNum()));
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.agent.manager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
|
||||
import com.cloud.resource.AgentResourceBase;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Manager;
|
||||
|
||||
public interface SimulatorManager extends Manager {
|
||||
public static final String Name = "simulator manager";
|
||||
|
||||
public enum AgentType {
|
||||
Computing(0), // not used anymore
|
||||
Routing(1),
|
||||
Storage(2);
|
||||
|
||||
int value;
|
||||
|
||||
AgentType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int value() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
MockVmManager getVmMgr();
|
||||
|
||||
MockStorageManager getStorageMgr();
|
||||
|
||||
MockAgentManager getAgentMgr();
|
||||
|
||||
Answer simulate(Command cmd, String hostGuid);
|
||||
StoragePoolInfo getLocalStorage(String hostGuid);
|
||||
|
||||
boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command, String values);
|
||||
public HashMap<String, Pair<Long, Long>> syncNetworkGroups(String hostGuid);
|
||||
}
|
||||
|
|
@ -0,0 +1,275 @@
|
|||
package com.cloud.agent.manager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.AttachIsoCommand;
|
||||
import com.cloud.agent.api.AttachVolumeCommand;
|
||||
import com.cloud.agent.api.BackupSnapshotCommand;
|
||||
import com.cloud.agent.api.CheckHealthCommand;
|
||||
import com.cloud.agent.api.CleanupNetworkRulesCmd;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.ComputeChecksumCommand;
|
||||
import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
|
||||
import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
|
||||
import com.cloud.agent.api.CreateStoragePoolCommand;
|
||||
import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
|
||||
import com.cloud.agent.api.DeleteSnapshotBackupCommand;
|
||||
import com.cloud.agent.api.DeleteStoragePoolCommand;
|
||||
import com.cloud.agent.api.GetHostStatsCommand;
|
||||
import com.cloud.agent.api.GetStorageStatsCommand;
|
||||
import com.cloud.agent.api.GetVmStatsCommand;
|
||||
import com.cloud.agent.api.GetVncPortCommand;
|
||||
import com.cloud.agent.api.MaintainCommand;
|
||||
import com.cloud.agent.api.ManageSnapshotCommand;
|
||||
import com.cloud.agent.api.MigrateCommand;
|
||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
|
||||
import com.cloud.agent.api.NetworkUsageCommand;
|
||||
import com.cloud.agent.api.PingTestCommand;
|
||||
import com.cloud.agent.api.RebootCommand;
|
||||
import com.cloud.agent.api.SecStorageSetupCommand;
|
||||
import com.cloud.agent.api.SecStorageVMSetupCommand;
|
||||
import com.cloud.agent.api.SecurityIngressRulesCmd;
|
||||
import com.cloud.agent.api.StartCommand;
|
||||
import com.cloud.agent.api.StopCommand;
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
import com.cloud.agent.api.check.CheckSshCommand;
|
||||
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
|
||||
import com.cloud.agent.api.routing.SavePasswordCommand;
|
||||
import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
|
||||
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
|
||||
import com.cloud.agent.api.routing.VmDataCommand;
|
||||
import com.cloud.agent.api.storage.CreateCommand;
|
||||
import com.cloud.agent.api.storage.DeleteTemplateCommand;
|
||||
import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.storage.DownloadCommand;
|
||||
import com.cloud.agent.api.storage.DownloadProgressCommand;
|
||||
import com.cloud.agent.api.storage.ListTemplateCommand;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
||||
import com.cloud.resource.AgentResourceBase;
|
||||
import com.cloud.simulator.MockConfigurationVO;
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.simulator.MockHostVO;
|
||||
import com.cloud.simulator.dao.MockConfigurationDao;
|
||||
import com.cloud.simulator.dao.MockHostDao;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.db.ConnectionConcierge;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
@Local(value = { SimulatorManager.class })
|
||||
public class SimulatorManagerImpl implements SimulatorManager {
|
||||
private static final Logger s_logger = Logger.getLogger(SimulatorManagerImpl.class);
|
||||
@Inject
|
||||
MockVmManager _mockVmMgr = null;
|
||||
@Inject
|
||||
MockStorageManager _mockStorageMgr = null;
|
||||
@Inject
|
||||
MockAgentManager _mockAgentMgr = null;
|
||||
@Inject
|
||||
MockConfigurationDao _mockConfigDao = null;
|
||||
@Inject
|
||||
MockHostDao _mockHost = null;
|
||||
private ConnectionConcierge _concierge;
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
try {
|
||||
Connection conn = Transaction.getStandaloneConnectionWithException();
|
||||
conn.setAutoCommit(true);
|
||||
_concierge = new ConnectionConcierge("AgentMonitor", conn, false);
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to get a db connection", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockVmManager getVmMgr() {
|
||||
return _mockVmMgr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockStorageManager getStorageMgr() {
|
||||
return _mockStorageMgr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockAgentManager getAgentMgr() {
|
||||
return _mockAgentMgr;
|
||||
}
|
||||
|
||||
@DB
|
||||
@Override
|
||||
public Answer simulate(Command cmd, String hostGuid) {
|
||||
MockHost host = _mockHost.findByGuid(hostGuid);
|
||||
MockConfigurationVO config = _mockConfigDao.findByCommand(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), cmd.toString());
|
||||
if (config == null) {
|
||||
config = _mockConfigDao.findByGlobal(cmd.toString());
|
||||
}
|
||||
|
||||
if (config != null) {
|
||||
Map<String, String> configParameters = config.getParameters();
|
||||
if (configParameters.get("enabled").equalsIgnoreCase("false")) {
|
||||
return new Answer(cmd, false, "cmd is disabled");
|
||||
}
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.transitToUserManagedConnection(_concierge.conn());
|
||||
|
||||
try {
|
||||
if (cmd instanceof GetHostStatsCommand) {
|
||||
return _mockAgentMgr.getHostStatistic((GetHostStatsCommand)cmd);
|
||||
} else if (cmd instanceof CheckHealthCommand) {
|
||||
return _mockAgentMgr.checkHealth((CheckHealthCommand)cmd);
|
||||
} else if (cmd instanceof PingTestCommand) {
|
||||
return _mockAgentMgr.pingTest((PingTestCommand)cmd);
|
||||
} else if (cmd instanceof MigrateCommand) {
|
||||
return _mockVmMgr.Migrate((MigrateCommand)cmd, hostGuid);
|
||||
} else if (cmd instanceof StartCommand) {
|
||||
return _mockVmMgr.startVM((StartCommand)cmd, hostGuid);
|
||||
} else if (cmd instanceof CheckSshCommand) {
|
||||
return _mockVmMgr.checkSshCommand((CheckSshCommand)cmd);
|
||||
} else if (cmd instanceof SetStaticNatRulesCommand) {
|
||||
return _mockVmMgr.SetStaticNatRules((SetStaticNatRulesCommand)cmd);
|
||||
} else if (cmd instanceof SetPortForwardingRulesCommand) {
|
||||
return _mockVmMgr.SetPortForwardingRules((SetPortForwardingRulesCommand)cmd);
|
||||
} else if (cmd instanceof NetworkUsageCommand) {
|
||||
return _mockVmMgr.getNetworkUsage((NetworkUsageCommand)cmd);
|
||||
} else if (cmd instanceof IpAssocCommand) {
|
||||
return _mockVmMgr.IpAssoc((IpAssocCommand)cmd);
|
||||
} else if (cmd instanceof LoadBalancerConfigCommand) {
|
||||
return _mockVmMgr.LoadBalancerConfig((LoadBalancerConfigCommand)cmd);
|
||||
} else if (cmd instanceof DhcpEntryCommand) {
|
||||
return _mockVmMgr.AddDhcpEntry((DhcpEntryCommand)cmd);
|
||||
} else if (cmd instanceof VmDataCommand) {
|
||||
return _mockVmMgr.setVmData((VmDataCommand)cmd);
|
||||
} else if (cmd instanceof CleanupNetworkRulesCmd) {
|
||||
return _mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd)cmd, hostGuid);
|
||||
} else if (cmd instanceof StopCommand) {
|
||||
return _mockVmMgr.stopVM((StopCommand)cmd);
|
||||
} else if (cmd instanceof RebootCommand) {
|
||||
return _mockVmMgr.rebootVM((RebootCommand)cmd);
|
||||
} else if (cmd instanceof GetVncPortCommand) {
|
||||
return _mockVmMgr.getVncPort((GetVncPortCommand)cmd);
|
||||
} else if (cmd instanceof CheckConsoleProxyLoadCommand) {
|
||||
return _mockVmMgr.CheckConsoleProxyLoad((CheckConsoleProxyLoadCommand)cmd);
|
||||
} else if (cmd instanceof WatchConsoleProxyLoadCommand) {
|
||||
return _mockVmMgr.WatchConsoleProxyLoad((WatchConsoleProxyLoadCommand)cmd);
|
||||
} else if (cmd instanceof SecurityIngressRulesCmd) {
|
||||
return _mockVmMgr.AddSecurityIngressRules((SecurityIngressRulesCmd)cmd);
|
||||
} else if (cmd instanceof SavePasswordCommand) {
|
||||
return _mockVmMgr.SavePassword((SavePasswordCommand)cmd);
|
||||
} else if (cmd instanceof PrimaryStorageDownloadCommand) {
|
||||
return _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand)cmd);
|
||||
} else if (cmd instanceof CreateCommand) {
|
||||
return _mockStorageMgr.createVolume((CreateCommand)cmd);
|
||||
} else if (cmd instanceof AttachVolumeCommand) {
|
||||
return _mockStorageMgr.AttachVolume((AttachVolumeCommand)cmd);
|
||||
} else if (cmd instanceof AttachIsoCommand) {
|
||||
return _mockStorageMgr.AttachIso((AttachIsoCommand)cmd);
|
||||
} else if (cmd instanceof DeleteStoragePoolCommand) {
|
||||
return _mockStorageMgr.DeleteStoragePool((DeleteStoragePoolCommand)cmd);
|
||||
} else if (cmd instanceof ModifyStoragePoolCommand) {
|
||||
return _mockStorageMgr.ModifyStoragePool((ModifyStoragePoolCommand)cmd);
|
||||
} else if (cmd instanceof CreateStoragePoolCommand) {
|
||||
return _mockStorageMgr.CreateStoragePool((CreateStoragePoolCommand)cmd);
|
||||
} else if (cmd instanceof SecStorageSetupCommand) {
|
||||
return _mockStorageMgr.SecStorageSetup((SecStorageSetupCommand)cmd);
|
||||
} else if (cmd instanceof ListTemplateCommand) {
|
||||
return _mockStorageMgr.ListTemplates((ListTemplateCommand)cmd);
|
||||
} else if (cmd instanceof DestroyCommand) {
|
||||
return _mockStorageMgr.Destroy((DestroyCommand)cmd);
|
||||
} else if (cmd instanceof DownloadProgressCommand) {
|
||||
return _mockStorageMgr.DownloadProcess((DownloadProgressCommand)cmd);
|
||||
} else if (cmd instanceof DownloadCommand) {
|
||||
return _mockStorageMgr.Download((DownloadCommand)cmd);
|
||||
} else if (cmd instanceof GetStorageStatsCommand) {
|
||||
return _mockStorageMgr.GetStorageStats((GetStorageStatsCommand)cmd);
|
||||
} else if (cmd instanceof ManageSnapshotCommand) {
|
||||
return _mockStorageMgr.ManageSnapshot((ManageSnapshotCommand)cmd);
|
||||
} else if (cmd instanceof BackupSnapshotCommand) {
|
||||
return _mockStorageMgr.BackupSnapshot((BackupSnapshotCommand)cmd);
|
||||
} else if (cmd instanceof DeleteSnapshotBackupCommand) {
|
||||
return _mockStorageMgr.DeleteSnapshotBackup((DeleteSnapshotBackupCommand)cmd);
|
||||
} else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
|
||||
return _mockStorageMgr.CreateVolumeFromSnapshot((CreateVolumeFromSnapshotCommand)cmd);
|
||||
} else if (cmd instanceof DeleteTemplateCommand) {
|
||||
return _mockStorageMgr.DeleteTemplate((DeleteTemplateCommand)cmd);
|
||||
} else if (cmd instanceof SecStorageVMSetupCommand) {
|
||||
return _mockStorageMgr.SecStorageVMSetup((SecStorageVMSetupCommand)cmd);
|
||||
} else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
|
||||
return _mockStorageMgr.CreatePrivateTemplateFromSnapshot((CreatePrivateTemplateFromSnapshotCommand)cmd);
|
||||
} else if (cmd instanceof ComputeChecksumCommand) {
|
||||
return _mockStorageMgr.ComputeChecksum((ComputeChecksumCommand)cmd);
|
||||
} else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
|
||||
return _mockStorageMgr.CreatePrivateTemplateFromVolume((CreatePrivateTemplateFromVolumeCommand)cmd);
|
||||
} else if (cmd instanceof MaintainCommand) {
|
||||
return _mockAgentMgr.MaintainCommand((MaintainCommand)cmd);
|
||||
} else if (cmd instanceof GetVmStatsCommand) {
|
||||
return _mockVmMgr.getVmStats((GetVmStatsCommand)cmd);
|
||||
} else {
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
s_logger.debug("Failed execute cmd: " + e.toString());
|
||||
txn.rollback();
|
||||
return new Answer(cmd, false, e.toString());
|
||||
} finally {
|
||||
txn.transitToAutoManagedConnection(Transaction.CLOUD_DB);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoragePoolInfo getLocalStorage(String hostGuid) {
|
||||
return _mockStorageMgr.getLocalStorage(hostGuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command, String values) {
|
||||
MockConfigurationVO config = new MockConfigurationVO();
|
||||
config.setClusterId(clusterId);
|
||||
config.setDataCenterId(zoneId);
|
||||
config.setPodId(podId);
|
||||
config.setHostId(hostId);
|
||||
config.setName(command);
|
||||
config.setValues(values);
|
||||
_mockConfigDao.persist(config);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Pair<Long, Long>> syncNetworkGroups(String hostGuid) {
|
||||
return _mockVmMgr.syncNetworkGroups(hostGuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.cloud.api.commands;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.manager.SimulatorManager;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.BaseResponse;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.server.ManagementService;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
|
||||
public class ConfigureSimulatorCmd extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ConfigureSimulatorCmd.class.getName());
|
||||
private static final String s_name = "configuresimulatorresponse";
|
||||
|
||||
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="configure range: in a zone")
|
||||
private Long zoneId;
|
||||
|
||||
@Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, description="configure range: in a pod")
|
||||
private Long podId;
|
||||
|
||||
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, description="configure range: in a cluster")
|
||||
private Long clusterId;
|
||||
|
||||
@Parameter(name=ApiConstants.HOST_ID, type=CommandType.LONG, description="configure range: in a host")
|
||||
private Long hostId;
|
||||
|
||||
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="which command needs to be configured")
|
||||
private String command;
|
||||
|
||||
@Parameter(name=ApiConstants.VALUE, type=CommandType.STRING, required=true, description="configuration options for this command, which is seperated by ;")
|
||||
private String values;
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
|
||||
SimulatorManager _simMgr = locator.getManager(SimulatorManager.class);
|
||||
boolean result = _simMgr.configureSimulator(zoneId, podId, clusterId, hostId, command, values);
|
||||
if (!result) {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure simulator");
|
||||
}
|
||||
|
||||
BaseResponse response = new BaseResponse();
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.cloud.configuration;
|
||||
|
||||
import com.cloud.agent.manager.MockAgentManagerImpl;
|
||||
import com.cloud.agent.manager.MockStorageManagerImpl;
|
||||
import com.cloud.agent.manager.MockVmManagerImpl;
|
||||
import com.cloud.agent.manager.SimulatorManagerImpl;
|
||||
import com.cloud.network.NetworkUsageManagerImpl;
|
||||
|
||||
import com.cloud.simulator.dao.MockConfigurationDaoImpl;
|
||||
import com.cloud.simulator.dao.MockHostDaoImpl;
|
||||
import com.cloud.simulator.dao.MockSecStorageDaoImpl;
|
||||
import com.cloud.simulator.dao.MockSecurityRulesDaoImpl;
|
||||
import com.cloud.simulator.dao.MockStoragePoolDaoImpl;
|
||||
import com.cloud.simulator.dao.MockVMDaoImpl;
|
||||
import com.cloud.simulator.dao.MockVolumeDaoImpl;
|
||||
|
||||
public class SimulatorComponentLibrary extends PremiumComponentLibrary {
|
||||
@Override
|
||||
protected void populateManagers() {
|
||||
addManager("VM Manager", MockVmManagerImpl.class);
|
||||
addManager("agent manager", MockAgentManagerImpl.class);
|
||||
addManager("storage manager", MockStorageManagerImpl.class);
|
||||
addManager("SimulatorManager", SimulatorManagerImpl.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateDaos() {
|
||||
addDao("mock Host", MockHostDaoImpl.class);
|
||||
addDao("mock secondary storage", MockSecStorageDaoImpl.class);
|
||||
addDao("mock storage pool", MockStoragePoolDaoImpl.class);
|
||||
addDao("mock vm", MockVMDaoImpl.class);
|
||||
addDao("mock volume", MockVolumeDaoImpl.class);
|
||||
addDao("mock config", MockConfigurationDaoImpl.class);
|
||||
addDao("mock security rules", MockSecurityRulesDaoImpl.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,278 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.IAgentControl;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.PingCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.manager.MockAgentManager;
|
||||
import com.cloud.agent.manager.MockStorageManager;
|
||||
import com.cloud.agent.manager.MockStorageManagerImpl;
|
||||
import com.cloud.agent.manager.MockVmManager;
|
||||
import com.cloud.agent.manager.SimulatorManager;
|
||||
import com.cloud.agent.manager.SimulatorManager.AgentType;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.net.MacAddress;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
public class AgentResourceBase implements ServerResource {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(AgentResourceBase.class);
|
||||
|
||||
protected String _name;
|
||||
private List<String> _warnings = new LinkedList<String>();
|
||||
private List<String> _errors = new LinkedList<String>();
|
||||
|
||||
private transient IAgentControl _agentControl;
|
||||
|
||||
protected long _instanceId;
|
||||
|
||||
private Type _type;
|
||||
|
||||
private transient ComponentLocator _locator = null;
|
||||
protected transient SimulatorManager _simMgr;
|
||||
protected MockHost agentHost = null;
|
||||
protected boolean stopped = false;
|
||||
protected String hostGuid = null;
|
||||
|
||||
|
||||
public AgentResourceBase(long instanceId, AgentType agentType, SimulatorManager simMgr, String hostGuid) {
|
||||
_instanceId = instanceId;
|
||||
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.info("New Routing host instantiated with guid:" + hostGuid);
|
||||
}
|
||||
|
||||
if (agentType == AgentType.Routing) {
|
||||
_type = Host.Type.Routing;
|
||||
} else {
|
||||
_type = Host.Type.Storage;
|
||||
}
|
||||
|
||||
this.hostGuid = hostGuid;
|
||||
}
|
||||
|
||||
protected MockVmManager getVmMgr() {
|
||||
return _simMgr.getVmMgr();
|
||||
}
|
||||
|
||||
protected MockStorageManager getStorageMgr() {
|
||||
return _simMgr.getStorageMgr();
|
||||
}
|
||||
|
||||
protected MockAgentManager getAgentMgr() {
|
||||
return _simMgr.getAgentMgr();
|
||||
}
|
||||
|
||||
protected long getInstanceId() {
|
||||
return _instanceId;
|
||||
}
|
||||
|
||||
public AgentResourceBase() {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Deserializing simulated agent on reconnect");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
_name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
hostGuid = (String)params.get("guid");
|
||||
_locator = ComponentLocator.getLocator("management-server");
|
||||
_simMgr = _locator.getManager(SimulatorManager.class);
|
||||
|
||||
agentHost = getAgentMgr().getHost(hostGuid);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void reconnect(MockHost host) {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Reconfiguring existing simulated host w/ name: " + host.getName() + " and guid: " + host.getGuid());
|
||||
}
|
||||
this.agentHost = host;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
this.stopped = true;
|
||||
}
|
||||
|
||||
protected void recordWarning(String msg, Throwable th) {
|
||||
String str = getLogStr(msg, th);
|
||||
synchronized (_warnings) {
|
||||
_warnings.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
protected void recordWarning(String msg) {
|
||||
recordWarning(msg, null);
|
||||
}
|
||||
|
||||
protected List<String> getWarnings() {
|
||||
synchronized (this) {
|
||||
List<String> results = _warnings;
|
||||
_warnings = new ArrayList<String>();
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
protected List<String> getErrors() {
|
||||
synchronized (this) {
|
||||
List<String> result = _errors;
|
||||
_errors = new ArrayList<String>();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
protected void recordError(String msg, Throwable th) {
|
||||
String str = getLogStr(msg, th);
|
||||
synchronized (_errors) {
|
||||
_errors.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
protected void recordError(String msg) {
|
||||
recordError(msg, null);
|
||||
}
|
||||
|
||||
protected Answer createErrorAnswer(Command cmd, String msg, Throwable th) {
|
||||
StringWriter writer = new StringWriter();
|
||||
if (msg != null) {
|
||||
writer.append(msg);
|
||||
}
|
||||
writer.append("===>Stack<===");
|
||||
th.printStackTrace(new PrintWriter(writer));
|
||||
return new Answer(cmd, false, writer.toString());
|
||||
}
|
||||
|
||||
protected String createErrorDetail(String msg, Throwable th) {
|
||||
StringWriter writer = new StringWriter();
|
||||
if (msg != null) {
|
||||
writer.append(msg);
|
||||
}
|
||||
writer.append("===>Stack<===");
|
||||
th.printStackTrace(new PrintWriter(writer));
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
protected String getLogStr(String msg, Throwable th) {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.append(new Date().toString()).append(": ").append(msg);
|
||||
if (th != null) {
|
||||
writer.append("\n Exception: ");
|
||||
th.printStackTrace(new PrintWriter(writer));
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
this.stopped = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAgentControl getAgentControl() {
|
||||
return _agentControl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAgentControl(IAgentControl agentControl) {
|
||||
_agentControl = agentControl;
|
||||
}
|
||||
|
||||
protected String findScript(String script) {
|
||||
s_logger.debug("Looking for " + script + " in the classpath");
|
||||
URL url = ClassLoader.getSystemResource(script);
|
||||
File file = null;
|
||||
if (url == null) {
|
||||
file = new File("./" + script);
|
||||
s_logger.debug("Looking for " + script + " in "
|
||||
+ file.getAbsolutePath());
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
file = new File(url.getFile());
|
||||
}
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
public void setType(Host.Type _type) {
|
||||
this._type = _type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public SimulatorManager getSimulatorManager() {
|
||||
return _simMgr;
|
||||
}
|
||||
|
||||
public void setSimulatorManager(SimulatorManager simMgr) {
|
||||
_simMgr = simMgr;
|
||||
}
|
||||
|
||||
public boolean isStopped() {
|
||||
return this.stopped;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,320 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.CheckVirtualMachineAnswer;
|
||||
import com.cloud.agent.api.CheckVirtualMachineCommand;
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
import com.cloud.agent.api.PingCommand;
|
||||
import com.cloud.agent.api.PingRoutingCommand;
|
||||
import com.cloud.agent.api.PingRoutingWithNwGroupsCommand;
|
||||
import com.cloud.agent.api.PrepareForMigrationCommand;
|
||||
import com.cloud.agent.api.ReadyAnswer;
|
||||
import com.cloud.agent.api.ReadyCommand;
|
||||
import com.cloud.agent.api.ShutdownCommand;
|
||||
import com.cloud.agent.api.StartAnswer;
|
||||
import com.cloud.agent.api.StartCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupRoutingCommand;
|
||||
import com.cloud.agent.api.StartupStorageCommand;
|
||||
import com.cloud.agent.api.StopAnswer;
|
||||
import com.cloud.agent.api.StopCommand;
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
import com.cloud.agent.manager.SimulatorManager;
|
||||
import com.cloud.agent.manager.SimulatorManager.AgentType;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Networks.RouterPrivateIpStrategy;
|
||||
import com.cloud.storage.Storage.StorageResourceType;
|
||||
import com.cloud.storage.template.TemplateInfo;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
public class AgentRoutingResource extends AgentStorageResource {
|
||||
private static final Logger s_logger = Logger.getLogger(AgentRoutingResource.class);
|
||||
|
||||
protected Map<String, State> _vms = new HashMap<String, State>(20);
|
||||
protected String _mountParent;
|
||||
|
||||
|
||||
public AgentRoutingResource(long instanceId, AgentType agentType, SimulatorManager simMgr, String hostGuid) {
|
||||
super(instanceId, agentType, simMgr, hostGuid);
|
||||
}
|
||||
|
||||
public AgentRoutingResource() {
|
||||
setType(Host.Type.Routing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
try {
|
||||
if (cmd instanceof StartCommand) {
|
||||
return execute((StartCommand) cmd);
|
||||
} else if (cmd instanceof StopCommand) {
|
||||
return execute((StopCommand) cmd);
|
||||
} else if (cmd instanceof PrepareForMigrationCommand) {
|
||||
return execute((PrepareForMigrationCommand) cmd);
|
||||
} else if (cmd instanceof CheckVirtualMachineCommand) {
|
||||
return execute((CheckVirtualMachineCommand) cmd);
|
||||
} else if (cmd instanceof ReadyCommand) {
|
||||
return new ReadyAnswer((ReadyCommand)cmd);
|
||||
} else if (cmd instanceof ShutdownCommand) {
|
||||
return execute((ShutdownCommand)cmd);
|
||||
} else {
|
||||
return _simMgr.simulate(cmd, hostGuid);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
return new Answer(cmd, false, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return Host.Type.Routing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
if (isStopped()) {
|
||||
return null;
|
||||
}
|
||||
final HashMap<String, State> newStates = sync();
|
||||
HashMap<String, Pair<Long, Long>> nwGrpStates = _simMgr.syncNetworkGroups(hostGuid);
|
||||
return new PingRoutingWithNwGroupsCommand(getType(), id, newStates, nwGrpStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
synchronized (_vms) {
|
||||
_vms.clear();
|
||||
}
|
||||
Map<String, State> changes = sync();
|
||||
List<Object> info = getHostInfo();
|
||||
|
||||
StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(2), (Long) info.get(4), (String) info.get(3), HypervisorType.Simulator,
|
||||
RouterPrivateIpStrategy.HostLocal);
|
||||
cmd.setStateChanges(changes);
|
||||
|
||||
Map<String, String> hostDetails = new HashMap<String, String>();
|
||||
hostDetails.put(RouterPrivateIpStrategy.class.getCanonicalName(), RouterPrivateIpStrategy.DcGlobal.toString());
|
||||
|
||||
cmd.setHostDetails(hostDetails);
|
||||
cmd.setAgentTag("agent-simulator");
|
||||
cmd.setPrivateIpAddress(agentHost.getPrivateIpAddress());
|
||||
cmd.setPrivateNetmask(agentHost.getPrivateNetMask());
|
||||
cmd.setPrivateMacAddress(agentHost.getPrivateMacAddress());
|
||||
cmd.setStorageIpAddress(agentHost.getStorageIpAddress());
|
||||
cmd.setStorageNetmask(agentHost.getStorageNetMask());
|
||||
cmd.setStorageMacAddress(agentHost.getStorageMacAddress());
|
||||
cmd.setStorageIpAddressDeux(agentHost.getStorageIpAddress());
|
||||
cmd.setStorageNetmaskDeux(agentHost.getStorageNetMask());
|
||||
cmd.setStorageMacAddressDeux(agentHost.getStorageIpAddress());
|
||||
|
||||
cmd.setName(agentHost.getName());
|
||||
cmd.setGuid(agentHost.getGuid());
|
||||
cmd.setVersion(agentHost.getVersion());
|
||||
cmd.setAgentTag("agent-simulator");
|
||||
cmd.setDataCenter(String.valueOf(agentHost.getDataCenterId()));
|
||||
cmd.setPod(String.valueOf(agentHost.getPodId()));
|
||||
cmd.setCluster(String.valueOf(agentHost.getClusterId()));
|
||||
|
||||
StartupStorageCommand ssCmd = initializeLocalSR();
|
||||
|
||||
return new StartupCommand[] { cmd, ssCmd };
|
||||
}
|
||||
|
||||
private StartupStorageCommand initializeLocalSR() {
|
||||
Map<String, TemplateInfo> tInfo = new HashMap<String, TemplateInfo>();
|
||||
|
||||
StoragePoolInfo poolInfo = _simMgr.getLocalStorage(hostGuid);
|
||||
|
||||
StartupStorageCommand cmd = new StartupStorageCommand(poolInfo.getHostPath(), poolInfo.getPoolType(), poolInfo.getCapacityBytes(), tInfo);
|
||||
|
||||
cmd.setPoolInfo(poolInfo);
|
||||
cmd.setGuid(agentHost.getGuid());
|
||||
cmd.setResourceType(StorageResourceType.STORAGE_POOL);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
protected synchronized Answer execute(StartCommand cmd)
|
||||
throws IllegalArgumentException {
|
||||
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
|
||||
String vmName = vmSpec.getName();
|
||||
|
||||
State state = State.Stopped;
|
||||
synchronized (_vms) {
|
||||
_vms.put(vmName, State.Starting);
|
||||
}
|
||||
|
||||
try {
|
||||
Answer result = _simMgr.simulate(cmd, hostGuid);
|
||||
if (!result.getResult()) {
|
||||
return new StartAnswer(cmd, result.getDetails());
|
||||
}
|
||||
|
||||
state = State.Running;
|
||||
|
||||
} finally {
|
||||
synchronized (_vms) {
|
||||
_vms.put(vmName, state);
|
||||
}
|
||||
}
|
||||
|
||||
return new StartAnswer(cmd);
|
||||
|
||||
}
|
||||
|
||||
protected synchronized StopAnswer execute(StopCommand cmd) {
|
||||
|
||||
StopAnswer answer = null;
|
||||
String vmName = cmd.getVmName();
|
||||
|
||||
State state = null;
|
||||
synchronized (_vms) {
|
||||
state = _vms.get(vmName);
|
||||
_vms.put(vmName, State.Stopping);
|
||||
}
|
||||
try {
|
||||
Answer result = _simMgr.simulate(cmd, hostGuid);
|
||||
|
||||
if (!result.getResult()) {
|
||||
return new StopAnswer(cmd, result.getDetails());
|
||||
}
|
||||
|
||||
answer = new StopAnswer(cmd, null, 0, new Long(100), new Long(200));
|
||||
|
||||
state = State.Stopped;
|
||||
|
||||
} finally {
|
||||
synchronized (_vms) {
|
||||
_vms.put(vmName, state);
|
||||
}
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
|
||||
protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) {
|
||||
final String vmName = cmd.getVmName();
|
||||
CheckVirtualMachineAnswer result = (CheckVirtualMachineAnswer)_simMgr.simulate(cmd, hostGuid);
|
||||
State state = result.getState();
|
||||
if (state == State.Running) {
|
||||
synchronized (_vms) {
|
||||
_vms.put(vmName, State.Running);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<Object> getHostInfo() {
|
||||
ArrayList<Object> info = new ArrayList<Object>();
|
||||
long speed = agentHost.getCpuSpeed();
|
||||
long cpus = agentHost.getCpuCount();
|
||||
long ram = agentHost.getMemorySize();
|
||||
long dom0Ram = agentHost.getMemorySize()/10;
|
||||
|
||||
info.add((int) cpus);
|
||||
info.add(speed);
|
||||
info.add(ram);
|
||||
info.add(agentHost.getCapabilities());
|
||||
info.add(dom0Ram);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
protected HashMap<String, State> sync() {
|
||||
Map<String, State> newStates;
|
||||
Map<String, State> oldStates = null;
|
||||
|
||||
HashMap<String, State> changes = new HashMap<String, State>();
|
||||
|
||||
synchronized (_vms) {
|
||||
newStates = getVmMgr().getVmStates(hostGuid);
|
||||
oldStates = new HashMap<String, State>(_vms.size());
|
||||
oldStates.putAll(_vms);
|
||||
|
||||
for (Map.Entry<String, State> entry : newStates.entrySet()) {
|
||||
String vm = entry.getKey();
|
||||
|
||||
State newState = entry.getValue();
|
||||
State oldState = oldStates.remove(vm);
|
||||
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("VM " + vm + ": has state " + newState + " and we have state " + (oldState != null ? oldState.toString() : "null"));
|
||||
}
|
||||
|
||||
if (oldState == null) {
|
||||
_vms.put(vm, newState);
|
||||
changes.put(vm, newState);
|
||||
} else if (oldState == State.Starting) {
|
||||
if (newState == State.Running) {
|
||||
_vms.put(vm, newState);
|
||||
} else if (newState == State.Stopped) {
|
||||
s_logger.debug("Ignoring vm " + vm + " because of a lag in starting the vm.");
|
||||
}
|
||||
} else if (oldState == State.Stopping) {
|
||||
if (newState == State.Stopped) {
|
||||
_vms.put(vm, newState);
|
||||
} else if (newState == State.Running) {
|
||||
s_logger.debug("Ignoring vm " + vm + " because of a lag in stopping the vm. ");
|
||||
}
|
||||
} else if (oldState != newState) {
|
||||
_vms.put(vm, newState);
|
||||
changes.put(vm, newState);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, State> entry : oldStates.entrySet()) {
|
||||
String vm = entry.getKey();
|
||||
State oldState = entry.getValue();
|
||||
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("VM " + vm + " is now missing from simulator agent so reporting stopped");
|
||||
}
|
||||
|
||||
if (oldState == State.Stopping) {
|
||||
s_logger.debug("Ignoring VM " + vm + " in transition state stopping.");
|
||||
_vms.remove(vm);
|
||||
} else if (oldState == State.Starting) {
|
||||
s_logger.debug("Ignoring VM " + vm + " in transition state starting.");
|
||||
} else if (oldState == State.Stopped) {
|
||||
_vms.remove(vm);
|
||||
} else {
|
||||
changes.put(entry.getKey(), State.Stopped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
private Answer execute(ShutdownCommand cmd) {
|
||||
this.stopped = true;
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
if (!super.configure(name, params)) {
|
||||
s_logger.warn("Base class was unable to configure");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
package com.cloud.resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
import com.cloud.agent.api.PingCommand;
|
||||
import com.cloud.agent.api.PingStorageCommand;
|
||||
import com.cloud.agent.api.ReadyAnswer;
|
||||
import com.cloud.agent.api.ReadyCommand;
|
||||
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupSecondaryStorageCommand;
|
||||
|
||||
import com.cloud.agent.api.storage.ssCommand;
|
||||
|
||||
import com.cloud.agent.manager.SimulatorManager;
|
||||
import com.cloud.agent.manager.SimulatorManager.AgentType;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Host.Type;
|
||||
|
||||
import com.cloud.storage.resource.SecondaryStorageResource;
|
||||
|
||||
import com.cloud.vm.SecondaryStorageVm;
|
||||
|
||||
|
||||
public class AgentStorageResource extends AgentResourceBase implements SecondaryStorageResource {
|
||||
private static final Logger s_logger = Logger.getLogger(AgentStorageResource.class);
|
||||
|
||||
final protected String _parent = "/mnt/SecStorage";
|
||||
protected String _role;
|
||||
|
||||
public AgentStorageResource(long instanceId, AgentType agentType, SimulatorManager simMgr, String hostGuid) {
|
||||
super(instanceId, agentType, simMgr, hostGuid);
|
||||
}
|
||||
|
||||
public AgentStorageResource() {
|
||||
setType(Host.Type.SecondaryStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
if (cmd instanceof ReadyCommand) {
|
||||
return new ReadyAnswer((ReadyCommand)cmd);
|
||||
} else {
|
||||
return _simMgr.simulate(cmd, hostGuid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
if (isStopped()) {
|
||||
return null;
|
||||
}
|
||||
return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
if(SecondaryStorageVm.Role.templateProcessor.toString().equals(_role))
|
||||
return Host.Type.SecondaryStorage;
|
||||
return Host.Type.SecondaryStorageCmdExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
StartupSecondaryStorageCommand cmd = new StartupSecondaryStorageCommand();
|
||||
|
||||
cmd.setPrivateIpAddress(agentHost.getPrivateIpAddress());
|
||||
cmd.setPrivateNetmask(agentHost.getPrivateNetMask());
|
||||
cmd.setPrivateMacAddress(agentHost.getPrivateMacAddress());
|
||||
cmd.setStorageIpAddress(agentHost.getStorageIpAddress());
|
||||
cmd.setStorageNetmask(agentHost.getStorageNetMask());
|
||||
cmd.setStorageMacAddress(agentHost.getStorageMacAddress());
|
||||
cmd.setPublicIpAddress(agentHost.getPublicIpAddress());
|
||||
|
||||
cmd.setName(agentHost.getName());
|
||||
cmd.setAgentTag("agent-simulator");
|
||||
cmd.setVersion(agentHost.getVersion());
|
||||
cmd.setDataCenter(String.valueOf(agentHost.getDataCenterId()));
|
||||
cmd.setPod(String.valueOf(agentHost.getPodId()));
|
||||
cmd.setGuid(agentHost.getGuid());
|
||||
return new StartupCommand[] { cmd };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
if (!super.configure(name, params)) {
|
||||
s_logger.warn("Base class was unable to configure");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRootDir(ssCommand cmd) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,293 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
|
||||
*/
|
||||
package com.cloud.resource;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.Listener;
|
||||
import com.cloud.agent.api.AgentControlAnswer;
|
||||
import com.cloud.agent.api.AgentControlCommand;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.manager.MockAgentManager;
|
||||
import com.cloud.agent.manager.MockStorageManager;
|
||||
import com.cloud.agent.manager.SimulatorManager;
|
||||
import com.cloud.agent.manager.SimulatorManagerImpl;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.exception.ConnectionException;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.resource.Discoverer;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VMTemplateZoneVO;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||
import com.cloud.storage.dao.VMTemplateZoneDao;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||
import com.cloud.utils.component.Inject;
|
||||
|
||||
/**
|
||||
* @author prasanna
|
||||
*
|
||||
*/
|
||||
@Local(value = Discoverer.class)
|
||||
public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, Listener {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(SimulatorDiscoverer.class);
|
||||
|
||||
@Inject HostDao _hostDao;
|
||||
@Inject VMTemplateDao _vmTemplateDao;
|
||||
@Inject VMTemplateHostDao _vmTemplateHostDao;
|
||||
@Inject VMTemplateZoneDao _vmTemplateZoneDao;
|
||||
@Inject ClusterDao _clusterDao;
|
||||
@Inject AgentManager _agentMgr = null;
|
||||
@Inject MockAgentManager _mockAgentMgr = null;
|
||||
@Inject MockStorageManager _mockStorageMgr = null;
|
||||
|
||||
/**
|
||||
* Finds ServerResources of an in-process simulator
|
||||
*
|
||||
* @see com.cloud.resource.Discoverer#find(long, java.lang.Long,
|
||||
* java.lang.Long, java.net.URI, java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Map<? extends ServerResource, Map<String, String>> find(long dcId,
|
||||
Long podId, Long clusterId, URI uri, String username,
|
||||
String password, List<String> hostTags) throws DiscoveryException {
|
||||
Map<AgentResourceBase, Map<String, String>> resources;
|
||||
|
||||
try {
|
||||
//http://sim/count=$count, it will add $count number of hosts into the cluster
|
||||
String scheme = uri.getScheme();
|
||||
String host = uri.getAuthority();
|
||||
String commands = URLDecoder.decode(uri.getPath());
|
||||
|
||||
long cpuSpeed = _mockAgentMgr.DEFAULT_HOST_SPEED_MHZ;
|
||||
long cpuCores = _mockAgentMgr.DEFAULT_HOST_CPU_CORES;
|
||||
long memory = _mockAgentMgr.DEFAULT_HOST_MEM_SIZE;
|
||||
long localstorageSize = _mockStorageMgr.DEFAULT_HOST_STORAGE_SIZE;
|
||||
if (scheme.equals("http")) {
|
||||
if (host == null || !host.equalsIgnoreCase("sim")) {
|
||||
String msg = "uri is not of simulator type so we're not taking care of the discovery for this: "
|
||||
+ uri;
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (commands != null) {
|
||||
int index = commands.lastIndexOf("/");
|
||||
if (index != -1) {
|
||||
commands = commands.substring(index+1);
|
||||
|
||||
String[] cmds = commands.split("&");
|
||||
for (String cmd : cmds) {
|
||||
String[] parameter = cmd.split("=");
|
||||
if (parameter[0].equalsIgnoreCase("cpuspeed") && parameter[1] != null) {
|
||||
cpuSpeed = Long.parseLong(parameter[1]);
|
||||
} else if (parameter[0].equalsIgnoreCase("cpucore") && parameter[1] != null) {
|
||||
cpuCores = Long.parseLong(parameter[1]);
|
||||
} else if (parameter[0].equalsIgnoreCase("memory") && parameter[1] != null) {
|
||||
memory = Long.parseLong(parameter[1]);
|
||||
} else if (parameter[0].equalsIgnoreCase("localstorage") && parameter[1] != null) {
|
||||
localstorageSize = Long.parseLong(parameter[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String msg = "uriString is not http so we're not taking care of the discovery for this: "
|
||||
+ uri;
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String cluster = null;
|
||||
if (clusterId == null) {
|
||||
String msg = "must specify cluster Id when adding host";
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
throw new RuntimeException(msg);
|
||||
} else {
|
||||
ClusterVO clu = _clusterDao.findById(clusterId);
|
||||
if (clu == null
|
||||
|| (clu.getHypervisorType() != HypervisorType.Simulator)) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("invalid cluster id or cluster is not for Simulator hypervisors");
|
||||
return null;
|
||||
}
|
||||
cluster = Long.toString(clusterId);
|
||||
if(clu.getGuid() == null) {
|
||||
clu.setGuid(UUID.randomUUID().toString());
|
||||
}
|
||||
_clusterDao.update(clusterId, clu);
|
||||
}
|
||||
|
||||
String pod;
|
||||
if (podId == null) {
|
||||
String msg = "must specify pod Id when adding host";
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
throw new RuntimeException(msg);
|
||||
} else {
|
||||
pod = Long.toString(podId);
|
||||
}
|
||||
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
details.put("username", username);
|
||||
params.put("username", username);
|
||||
details.put("password", password);
|
||||
params.put("password", password);
|
||||
params.put("zone", Long.toString(dcId));
|
||||
params.put("pod", pod);
|
||||
params.put("cluster", cluster);
|
||||
params.put("cpuspeed", Long.toString(cpuSpeed));
|
||||
params.put("cpucore", Long.toString(cpuCores));
|
||||
params.put("memory", Long.toString(memory));
|
||||
params.put("localstorage", Long.toString(localstorageSize));
|
||||
|
||||
resources = createAgentResources(params);
|
||||
return resources;
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("Exception when discovering simulator hosts: "
|
||||
+ ex.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<AgentResourceBase, Map<String, String>> createAgentResources(
|
||||
Map<String, Object> params) {
|
||||
try {
|
||||
s_logger.info("Creating Simulator Resources");
|
||||
return _mockAgentMgr.createServerResources(params);
|
||||
} catch (Exception ex) {
|
||||
s_logger.warn("Caught exception at agent resource creation: "
|
||||
+ ex.getMessage(), ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postDiscovery(List<HostVO> hosts, long msId) {
|
||||
|
||||
for (HostVO h : hosts) {
|
||||
associateTemplatesToZone(h.getId(), h.getDataCenterId());
|
||||
}
|
||||
}
|
||||
|
||||
private void associateTemplatesToZone(long hostId, long dcId){
|
||||
VMTemplateZoneVO tmpltZone;
|
||||
|
||||
List<VMTemplateVO> allTemplates = _vmTemplateDao.listAll();
|
||||
for (VMTemplateVO vt: allTemplates){
|
||||
if (vt.isCrossZones()) {
|
||||
tmpltZone = _vmTemplateZoneDao.findByZoneTemplate(dcId, vt.getId());
|
||||
if (tmpltZone == null) {
|
||||
VMTemplateZoneVO vmTemplateZone = new VMTemplateZoneVO(dcId, vt.getId(), new Date());
|
||||
_vmTemplateZoneDao.persist(vmTemplateZone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HypervisorType getHypervisorType() {
|
||||
return HypervisorType.Simulator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchHypervisor(String hypervisor) {
|
||||
return hypervisor.equalsIgnoreCase(HypervisorType.Simulator.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
_agentMgr.registerForHostEvents(this, true, false, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processCommands(long agentId, long seq, Command[] commands) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
|
||||
/*
|
||||
if(forRebalance)
|
||||
return;
|
||||
if ( Host.Type.SecondaryStorage == host.getType() ) {
|
||||
List<VMTemplateVO> tmplts = _vmTemplateDao.listAll();
|
||||
for( VMTemplateVO tmplt : tmplts ) {
|
||||
VMTemplateHostVO vmTemplateHost = _vmTemplateHostDao.findByHostTemplate(host.getId(), tmplt.getId());
|
||||
if (vmTemplateHost == null) {
|
||||
vmTemplateHost = new VMTemplateHostVO(host.getId(), tmplt.getId(), new Date(), 100,
|
||||
VMTemplateStorageResourceAssoc.Status.DOWNLOADED, null, null, null, null, tmplt.getUrl());
|
||||
_vmTemplateHostDao.persist(vmTemplateHost);
|
||||
} else {
|
||||
vmTemplateHost.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
vmTemplateHost.setDownloadPercent(100);
|
||||
_vmTemplateHostDao.update(vmTemplateHost.getId(), vmTemplateHost);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDisconnect(long agentId, Status state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecurring() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processTimeout(long agentId, long seq) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.cloud.resource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.agent.manager.MockStorageManager;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.storage.secondary.SecondaryStorageDiscoverer;
|
||||
import com.cloud.utils.component.Inject;
|
||||
@Local(value=Discoverer.class)
|
||||
public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer {
|
||||
@Inject
|
||||
MockStorageManager _mockStorageMgr = null;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
return super.configure(name, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postDiscovery(List<HostVO> hosts, long msId) {
|
||||
super.postDiscovery(hosts, msId);
|
||||
for (HostVO host: hosts) {
|
||||
_mockStorageMgr.preinstallTemplates(host.getStorageUrl(), host.getDataCenterId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.cloud.server;
|
||||
|
||||
import com.cloud.server.ManagementServerExtImpl;
|
||||
|
||||
public class ManagementServerSimulatorImpl extends ManagementServerExtImpl {
|
||||
@Override
|
||||
public String[] getApiConfig() {
|
||||
String[] apis = super.getApiConfig();
|
||||
String[] newapis = new String[apis.length + 1];
|
||||
for (int i = 0; i < apis.length; i++) {
|
||||
newapis[i] = apis[i];
|
||||
}
|
||||
|
||||
newapis[apis.length] = "commands-simulator.properties";
|
||||
return newapis;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package com.cloud.simulator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="mockconfiguration")
|
||||
public class MockConfigurationVO {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
private long id;
|
||||
|
||||
@Column(name="data_center_id", nullable=false)
|
||||
private Long dataCenterId;
|
||||
|
||||
@Column(name="pod_id")
|
||||
private Long podId;
|
||||
|
||||
@Column(name="cluster_id")
|
||||
private Long clusterId;
|
||||
|
||||
@Column(name="host_id")
|
||||
private Long hostId;
|
||||
|
||||
@Column(name="name")
|
||||
private String name;
|
||||
|
||||
@Column(name="values")
|
||||
private String values;
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Long getDataCenterId() {
|
||||
return this.dataCenterId;
|
||||
}
|
||||
|
||||
public void setDataCenterId(Long dcId) {
|
||||
this.dataCenterId = dcId;
|
||||
}
|
||||
|
||||
public Long getPodId() {
|
||||
return this.podId;
|
||||
}
|
||||
|
||||
public void setPodId(Long podId) {
|
||||
this.podId = podId;
|
||||
}
|
||||
|
||||
public Long getClusterId() {
|
||||
return this.clusterId;
|
||||
}
|
||||
|
||||
public void setClusterId(Long clusterId) {
|
||||
this.clusterId = clusterId;
|
||||
}
|
||||
|
||||
public Long getHostId() {
|
||||
return this.hostId;
|
||||
}
|
||||
|
||||
public void setHostId(Long hostId) {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValues() {
|
||||
return this.values;
|
||||
}
|
||||
|
||||
public Map<String, String> getParameters() {
|
||||
Map<String, String> maps = new HashMap<String, String>();
|
||||
if (this.values == null) {
|
||||
return maps;
|
||||
}
|
||||
|
||||
String[] vals = this.values.split(";");
|
||||
for (String val : vals) {
|
||||
String[] paras = val.split("=");
|
||||
maps.put(paras[0], paras[1]);
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
|
||||
public void setValues(String values) {
|
||||
this.values = values;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.cloud.simulator;
|
||||
|
||||
public interface MockHost {
|
||||
public long getCpuSpeed();
|
||||
public long getCpuCount();
|
||||
|
||||
|
||||
public long getMemorySize();
|
||||
|
||||
public String getCapabilities();
|
||||
|
||||
public long getId();
|
||||
|
||||
public String getName();
|
||||
|
||||
public String getGuid();
|
||||
|
||||
|
||||
public String getVersion();
|
||||
|
||||
public Long getDataCenterId();
|
||||
|
||||
public Long getPodId();
|
||||
|
||||
public Long getClusterId();
|
||||
|
||||
public String getPrivateIpAddress();
|
||||
|
||||
public String getPrivateNetMask();
|
||||
|
||||
public String getPrivateMacAddress();
|
||||
|
||||
|
||||
public String getPublicIpAddress();
|
||||
|
||||
public String getPublicNetMask();
|
||||
|
||||
public String getPublicMacAddress();
|
||||
|
||||
public String getStorageIpAddress();
|
||||
|
||||
public String getStorageNetMask();
|
||||
|
||||
public String getStorageMacAddress();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,264 @@
|
|||
package com.cloud.simulator;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="mockhost")
|
||||
|
||||
public class MockHostVO implements MockHost {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
private long id;
|
||||
|
||||
@Column(name="name", nullable=false)
|
||||
private String name = null;
|
||||
|
||||
@Column(name="private_ip_address", nullable=false)
|
||||
private String privateIpAddress;
|
||||
|
||||
@Column(name="private_mac_address", nullable=false)
|
||||
private String privateMacAddress;
|
||||
|
||||
@Column(name="private_netmask", nullable=false)
|
||||
private String privateNetmask;
|
||||
|
||||
@Column(name="public_netmask")
|
||||
private String publicNetmask;
|
||||
|
||||
@Column(name="public_ip_address")
|
||||
private String publicIpAddress;
|
||||
|
||||
@Column(name="public_mac_address")
|
||||
private String publicMacAddress;
|
||||
|
||||
@Column(name="storage_ip_address")
|
||||
private String storageIpAddress;
|
||||
|
||||
@Column(name="storage_mac_address")
|
||||
private String storageMacAddress;
|
||||
|
||||
@Column(name="storage_netmask")
|
||||
private String storageNetMask;
|
||||
|
||||
@Column(name="guid")
|
||||
private String guid;
|
||||
|
||||
@Column(name="version")
|
||||
private String version;
|
||||
|
||||
@Column(name="data_center_id", nullable=false)
|
||||
private long dataCenterId;
|
||||
|
||||
@Column(name="pod_id")
|
||||
private Long podId;
|
||||
|
||||
@Column(name="cluster_id")
|
||||
private Long clusterId;
|
||||
|
||||
@Column(name="speed")
|
||||
private long cpuSpeed;
|
||||
|
||||
@Column(name="cpus")
|
||||
private long cpuCount;
|
||||
|
||||
@Column(name="ram")
|
||||
private long memorySize;
|
||||
|
||||
@Column(name="capabilities")
|
||||
private String capabilities;
|
||||
|
||||
@Column(name="vm_id")
|
||||
private long vmId;
|
||||
|
||||
@Column(name="resource")
|
||||
private String resource;
|
||||
|
||||
|
||||
|
||||
public MockHostVO() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public long getVmId() {
|
||||
return vmId;
|
||||
}
|
||||
|
||||
public void setVmId(long vmId) {
|
||||
this.vmId = vmId;
|
||||
}
|
||||
|
||||
public String getResource() {
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
public void setResource(String resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public long getCpuSpeed() {
|
||||
return this.cpuSpeed;
|
||||
}
|
||||
|
||||
public void setCpuSpeed(long cpuSpeed) {
|
||||
this.cpuSpeed = cpuSpeed;
|
||||
}
|
||||
|
||||
public long getCpuCount() {
|
||||
return this.cpuCount;
|
||||
}
|
||||
|
||||
public void setCpuCount(long cpuCount) {
|
||||
this.cpuCount = cpuCount;
|
||||
}
|
||||
|
||||
public long getMemorySize() {
|
||||
return this.memorySize;
|
||||
}
|
||||
|
||||
public void setMemorySize(long memorySize) {
|
||||
this.memorySize = memorySize;
|
||||
}
|
||||
|
||||
public String getCapabilities() {
|
||||
return this.capabilities;
|
||||
}
|
||||
|
||||
public void setCapabilities(String capabilities) {
|
||||
this.capabilities = capabilities;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getGuid() {
|
||||
return this.guid;
|
||||
}
|
||||
|
||||
public void setGuid(String guid) {
|
||||
this.guid = guid;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Long getDataCenterId() {
|
||||
return this.dataCenterId;
|
||||
}
|
||||
|
||||
public void setDataCenterId(Long dataCenterId) {
|
||||
this.dataCenterId = dataCenterId;
|
||||
}
|
||||
|
||||
public Long getPodId() {
|
||||
return this.podId;
|
||||
}
|
||||
|
||||
public void setPodId(long podId) {
|
||||
this.podId = podId;
|
||||
}
|
||||
|
||||
public Long getClusterId() {
|
||||
return this.clusterId;
|
||||
}
|
||||
|
||||
public void setClusterId(Long clusterId) {
|
||||
this.clusterId = clusterId;
|
||||
}
|
||||
|
||||
public String getPrivateIpAddress() {
|
||||
return privateIpAddress;
|
||||
}
|
||||
|
||||
public void setPrivateIpAddress(String privateIpAddress) {
|
||||
this.privateIpAddress = privateIpAddress;
|
||||
}
|
||||
|
||||
public String getPrivateNetMask() {
|
||||
return this.privateNetmask;
|
||||
}
|
||||
|
||||
public void setPrivateNetMask(String privateNetmask) {
|
||||
this.privateNetmask = privateNetmask;
|
||||
}
|
||||
|
||||
public String getPrivateMacAddress() {
|
||||
return this.privateMacAddress;
|
||||
}
|
||||
|
||||
public void setPrivateMacAddress(String privateMacAddress) {
|
||||
this.privateMacAddress = privateMacAddress;
|
||||
}
|
||||
|
||||
public String getPublicIpAddress() {
|
||||
return this.publicIpAddress;
|
||||
}
|
||||
|
||||
public void setPublicIpAddress(String publicIpAddress) {
|
||||
this.publicIpAddress = publicIpAddress;
|
||||
}
|
||||
|
||||
public String getPublicNetMask() {
|
||||
return this.publicNetmask;
|
||||
}
|
||||
|
||||
public void setPublicNetMask(String publicNetMask) {
|
||||
this.publicNetmask = publicNetMask;
|
||||
}
|
||||
|
||||
public String getPublicMacAddress() {
|
||||
return this.publicMacAddress;
|
||||
}
|
||||
|
||||
public void setPublicMacAddress(String publicMacAddress) {
|
||||
this.publicMacAddress = publicMacAddress;
|
||||
}
|
||||
|
||||
public String getStorageIpAddress() {
|
||||
return this.storageIpAddress;
|
||||
}
|
||||
|
||||
public void setStorageIpAddress(String storageIpAddress) {
|
||||
this.storageIpAddress = storageIpAddress;
|
||||
}
|
||||
|
||||
public String getStorageNetMask() {
|
||||
return this.storageNetMask;
|
||||
}
|
||||
|
||||
public void setStorageNetMask(String storageNetMask) {
|
||||
this.storageNetMask = storageNetMask;
|
||||
}
|
||||
|
||||
public String getStorageMacAddress() {
|
||||
return this.storageMacAddress;
|
||||
}
|
||||
|
||||
public void setStorageMacAddress(String storageMacAddress) {
|
||||
this.storageMacAddress = storageMacAddress;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.cloud.simulator;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="mocksecstorage")
|
||||
|
||||
public class MockSecStorageVO {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
private long id;
|
||||
|
||||
@Column(name="url")
|
||||
private String url;
|
||||
|
||||
@Column(name="capacity")
|
||||
private long capacity;
|
||||
|
||||
@Column(name="mount_point")
|
||||
private String mountPoint;
|
||||
|
||||
|
||||
public MockSecStorageVO() {
|
||||
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getMountPoint() {
|
||||
return this.mountPoint;
|
||||
}
|
||||
|
||||
public void setMountPoint(String mountPoint) {
|
||||
this.mountPoint = mountPoint;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public long getCapacity() {
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
public void setCapacity(long capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package com.cloud.simulator;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(name="mocksecurityrules")
|
||||
public class MockSecurityRulesVO {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
private long id;
|
||||
|
||||
@Column(name="vmid")
|
||||
private Long vmId;
|
||||
|
||||
@Column(name="signature")
|
||||
private String signature;
|
||||
|
||||
@Column(name="seqnum")
|
||||
private Long seqnum;
|
||||
|
||||
@Column(name="ruleset")
|
||||
private String ruleset;
|
||||
|
||||
@Column(name="hostid")
|
||||
private Long hostId;
|
||||
|
||||
@Column(name="vmname")
|
||||
public String vmName;
|
||||
|
||||
public String getVmName() {
|
||||
return this.vmName;
|
||||
}
|
||||
|
||||
public void setVmName(String vmName) {
|
||||
this.vmName = vmName;
|
||||
}
|
||||
|
||||
public Long getHostId() {
|
||||
return this.hostId;
|
||||
}
|
||||
|
||||
public void setHostId(Long hostId) {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Long getVmId() {
|
||||
return this.vmId;
|
||||
}
|
||||
|
||||
public void setVmId(Long vmId) {
|
||||
this.vmId = vmId;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return this.signature;
|
||||
}
|
||||
|
||||
public void setSignature(String sig) {
|
||||
this.signature = sig;
|
||||
}
|
||||
|
||||
public Long getSeqNum() {
|
||||
return this.seqnum;
|
||||
}
|
||||
|
||||
public void setSeqNum(Long seqNum) {
|
||||
this.seqnum = seqNum;
|
||||
}
|
||||
|
||||
public String getRuleSet() {
|
||||
return this.ruleset;
|
||||
}
|
||||
|
||||
public void setRuleSet(String ruleset) {
|
||||
this.ruleset = ruleset;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue