1717 */
1818package com .cloud .agent .resource ;
1919
20+ import java .util .ArrayList ;
21+ import java .util .HashMap ;
22+ import java .util .List ;
2023import java .util .Map ;
24+ import java .util .UUID ;
2125
2226import javax .ejb .Local ;
2327
2428import com .cloud .agent .IAgentControl ;
2529import com .cloud .agent .api .Answer ;
30+ import com .cloud .agent .api .CheckNetworkAnswer ;
31+ import com .cloud .agent .api .CheckNetworkCommand ;
2632import com .cloud .agent .api .Command ;
2733import com .cloud .agent .api .PingCommand ;
2834import com .cloud .agent .api .StartupCommand ;
35+ import com .cloud .agent .api .StartupRoutingCommand ;
36+ import com .cloud .agent .api .StartupStorageCommand ;
37+ import com .cloud .agent .api .StoragePoolInfo ;
38+ import com .cloud .agent .api .StartupRoutingCommand .VmState ;
2939import com .cloud .host .Host ;
3040import com .cloud .host .Host .Type ;
41+ import com .cloud .hypervisor .Hypervisor .HypervisorType ;
42+ import com .cloud .network .Networks .RouterPrivateIpStrategy ;
3143import com .cloud .resource .ServerResource ;
44+ import com .cloud .storage .Storage ;
45+ import com .cloud .storage .Storage .StoragePoolType ;
3246
3347@ Local (value ={ServerResource .class })
3448public class DummyResource implements ServerResource {
3549 String _name ;
3650 Host .Type _type ;
3751 boolean _negative ;
3852 IAgentControl _agentControl ;
53+ private Map <String , Object > _params ;
3954
4055 @ Override
4156 public void disconnected () {
4257 }
4358
4459 @ Override
4560 public Answer executeRequest (Command cmd ) {
61+ if (cmd instanceof CheckNetworkCommand ) {
62+ return new CheckNetworkAnswer ((CheckNetworkCommand )cmd , true , null );
63+ }
4664 System .out .println ("Received Command: " + cmd .toString ());
4765 Answer answer = new Answer (cmd , !_negative , "response" );
4866 System .out .println ("Replying with: " + answer .toString ());
@@ -58,10 +76,98 @@ public PingCommand getCurrentStatus(long id) {
5876 public Type getType () {
5977 return _type ;
6078 }
79+
80+ protected String getConfiguredProperty (String key , String defaultValue ) {
81+ String val = (String )_params .get (key );
82+ return val ==null ?defaultValue :val ;
83+ }
84+
85+ protected Long getConfiguredProperty (String key , Long defaultValue ) {
86+ String val = (String )_params .get (key );
87+
88+ if (val != null ) {
89+ Long result = Long .parseLong (val );
90+ return result ;
91+ }
92+ return defaultValue ;
93+ }
94+
95+ protected List <Object > getHostInfo () {
96+ final ArrayList <Object > info = new ArrayList <Object >();
97+ long speed = getConfiguredProperty ("cpuspeed" , 4000L ) ;
98+ long cpus = getConfiguredProperty ("cpus" , 4L );
99+ long ram = getConfiguredProperty ("memory" , 16000L *1024L *1024L );
100+ long dom0ram = Math .min (ram /10 , 768 *1024 *1024L );
101+
102+
103+ String cap = getConfiguredProperty ("capabilities" , "hvm" );
104+ info .add ((int )cpus );
105+ info .add (speed );
106+ info .add (ram );
107+ info .add (cap );
108+ info .add (dom0ram );
109+ return info ;
110+
111+ }
112+
113+ protected void fillNetworkInformation (final StartupCommand cmd ) {
114+
115+ cmd .setPrivateIpAddress ((String )getConfiguredProperty ("private.ip.address" , "127.0.0.1" ));
116+ cmd .setPrivateMacAddress ((String )getConfiguredProperty ("private.mac.address" , "8A:D2:54:3F:7C:C3" ));
117+ cmd .setPrivateNetmask ((String )getConfiguredProperty ("private.ip.netmask" , "255.255.255.0" ));
118+
119+ cmd .setStorageIpAddress ((String )getConfiguredProperty ("private.ip.address" , "127.0.0.1" ));
120+ cmd .setStorageMacAddress ((String )getConfiguredProperty ("private.mac.address" , "8A:D2:54:3F:7C:C3" ));
121+ cmd .setStorageNetmask ((String )getConfiguredProperty ("private.ip.netmask" , "255.255.255.0" ));
122+ cmd .setGatewayIpAddress ((String )getConfiguredProperty ("gateway.ip.address" , "127.0.0.1" ));
123+
124+ }
125+
126+ private Map <String , String > getVersionStrings () {
127+ Map <String , String > result = new HashMap <String , String >();
128+ String hostOs = (String ) _params .get ("Host.OS" );
129+ String hostOsVer = (String ) _params .get ("Host.OS.Version" );
130+ String hostOsKernVer = (String ) _params .get ("Host.OS.Kernel.Version" );
131+ result .put ("Host.OS" , hostOs ==null ?"Fedora" :hostOs );
132+ result .put ("Host.OS.Version" , hostOsVer ==null ?"14" :hostOsVer );
133+ result .put ("Host.OS.Kernel.Version" , hostOsKernVer ==null ?"2.6.35.6-45.fc14.x86_64" :hostOsKernVer );
134+ return result ;
135+ }
136+
137+ protected StoragePoolInfo initializeLocalStorage () {
138+ String hostIp = (String )getConfiguredProperty ("private.ip.address" , "127.0.0.1" );
139+ String localStoragePath = (String )getConfiguredProperty ("local.storage.path" , "/mnt" );
140+ String lh = hostIp + localStoragePath ;
141+ String uuid = UUID .nameUUIDFromBytes (lh .getBytes ()).toString ();
142+
143+ String capacity = (String )getConfiguredProperty ("local.storage.capacity" , "1000000000" );
144+ String available = (String )getConfiguredProperty ("local.storage.avail" , "10000000" );
145+
146+ return new StoragePoolInfo (uuid , hostIp , localStoragePath ,
147+ localStoragePath , StoragePoolType .Filesystem ,
148+ Long .parseLong (capacity ), Long .parseLong (available ));
61149
150+ }
151+
62152 @ Override
63153 public StartupCommand [] initialize () {
64- return new StartupCommand [] {new StartupCommand (Host .Type .Storage )};
154+ Map <String , VmState > changes = null ;
155+
156+
157+ final List <Object > info = getHostInfo ();
158+
159+ final 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 .KVM , RouterPrivateIpStrategy .HostLocal , changes );
160+ fillNetworkInformation (cmd );
161+ cmd .getHostDetails ().putAll (getVersionStrings ());
162+ cmd .setCluster (getConfiguredProperty ("cluster" , "1" ));
163+ StoragePoolInfo pi = initializeLocalStorage ();
164+ StartupStorageCommand sscmd = new StartupStorageCommand ();
165+ sscmd .setPoolInfo (pi );
166+ sscmd .setGuid (pi .getUuid ());
167+ sscmd .setDataCenter ((String )_params .get ("zone" ));
168+ sscmd .setResourceType (Storage .StorageResourceType .STORAGE_POOL );
169+
170+ return new StartupCommand []{cmd , sscmd };
65171 }
66172
67173 @ Override
@@ -73,9 +179,13 @@ public boolean configure(String name, Map<String, Object> params) {
73179
74180 value = (String )params .get ("negative.reply" );
75181 _negative = Boolean .parseBoolean (value );
76-
182+ setParams ( params );
77183 return true ;
78184 }
185+
186+ public void setParams (Map <String , Object > _params ) {
187+ this ._params = _params ;
188+ }
79189
80190 @ Override
81191 public String getName () {
0 commit comments