5757import com .cloud .agent .api .RebootCommand ;
5858import com .cloud .agent .api .RevertToVMSnapshotAnswer ;
5959import com .cloud .agent .api .RevertToVMSnapshotCommand ;
60+ import com .cloud .agent .api .ScaleVmAnswer ;
6061import com .cloud .agent .api .ScaleVmCommand ;
6162import com .cloud .agent .api .SecurityGroupRuleAnswer ;
6263import com .cloud .agent .api .SecurityGroupRulesCmd ;
@@ -248,7 +249,7 @@ public Map<String, MockVMVO> getVms(final String hostGuid) {
248249 return vmMap ;
249250 } catch (final Exception ex ) {
250251 txn .rollback ();
251- throw new CloudRuntimeException ("unable to fetch vms from host " + hostGuid , ex );
252+ throw new CloudRuntimeException ("unable to fetch vms from host " + hostGuid , ex );
252253 } finally {
253254 txn .close ();
254255 txn = TransactionLegacy .open (TransactionLegacy .CLOUD_DB );
@@ -292,7 +293,7 @@ public Map<String, PowerState> getVmStates(final String hostGuid) {
292293 return states ;
293294 } catch (final Exception ex ) {
294295 txn .rollback ();
295- throw new CloudRuntimeException ("unable to fetch vms from host " + hostGuid , ex );
296+ throw new CloudRuntimeException ("unable to fetch vms from host " + hostGuid , ex );
296297 } finally {
297298 txn .close ();
298299 txn = TransactionLegacy .open (TransactionLegacy .CLOUD_DB );
@@ -369,7 +370,7 @@ public CheckSshAnswer checkSshCommand(final CheckSshCommand cmd) {
369370 }
370371
371372 @ Override
372- public MigrateAnswer Migrate (final MigrateCommand cmd , final SimulatorInfo info ) {
373+ public MigrateAnswer migrate (final MigrateCommand cmd , final SimulatorInfo info ) {
373374 TransactionLegacy txn = TransactionLegacy .open (TransactionLegacy .SIMULATOR_DB );
374375 try {
375376 txn .start ();
@@ -382,7 +383,7 @@ public MigrateAnswer Migrate(final MigrateCommand cmd, final SimulatorInfo info)
382383
383384 final MockHost destHost = _mockHostDao .findByGuid (destGuid );
384385 if (destHost == null ) {
385- return new MigrateAnswer (cmd , false , "can; t find host:" + info . getHostUuid () , null );
386+ return new MigrateAnswer (cmd , false , "can' t find destination host:" + destGuid , null );
386387 }
387388 vm .setHostId (destHost .getId ());
388389 _mockVmDao .update (vm .getId (), vm );
@@ -424,7 +425,7 @@ public Answer setVmData(final VmDataCommand cmd) {
424425 }
425426
426427 @ Override
427- public Answer CleanupNetworkRules (final CleanupNetworkRulesCmd cmd , final SimulatorInfo info ) {
428+ public Answer cleanupNetworkRules (final CleanupNetworkRulesCmd cmd , final SimulatorInfo info ) {
428429 TransactionLegacy txn = TransactionLegacy .open (TransactionLegacy .SIMULATOR_DB );
429430 try {
430431 txn .start ();
@@ -449,12 +450,34 @@ public Answer CleanupNetworkRules(final CleanupNetworkRulesCmd cmd, final Simula
449450
450451 @ Override
451452 public Answer scaleVm (final ScaleVmCommand cmd ) {
452- return null ; //To change body of implemented methods use File | Settings | File Templates.
453+ TransactionLegacy txn = TransactionLegacy .open (TransactionLegacy .SIMULATOR_DB );
454+ try {
455+ txn .start ();
456+ final String vmName = cmd .getVmName ();
457+ final MockVMVO vm = _mockVmDao .findByVmName (vmName );
458+ if (vm == null ) {
459+ return new ScaleVmAnswer (cmd , false , "Can't find VM " + vmName );
460+ }
461+ vm .setCpu (cmd .getCpus () * cmd .getMaxSpeed ());
462+ vm .setMemory (cmd .getMaxRam ());
463+ _mockVmDao .update (vm .getId (), vm );
464+ s_logger .debug ("Scaled up VM " + vmName );
465+ txn .commit ();
466+ return new ScaleVmAnswer (cmd , true , null );
467+ } catch (final Exception ex ) {
468+ txn .rollback ();
469+ throw new CloudRuntimeException ("Unable to scale up VM" , ex );
470+ } finally {
471+ txn .close ();
472+ txn = TransactionLegacy .open (TransactionLegacy .CLOUD_DB );
473+ txn .close ();
474+ }
453475 }
454476
455477 @ Override
456478 public Answer plugSecondaryIp (final NetworkRulesVmSecondaryIpCommand cmd ) {
457- return null ; //To change body of implemented methods use File | Settings | File Templates.
479+ s_logger .debug ("Plugged secondary IP to VM " + cmd .getVmName ());
480+ return new Answer (cmd , true , null );
458481 }
459482
460483 @ Override
@@ -527,12 +550,12 @@ public Answer getVncPort(final GetVncPortCommand cmd) {
527550 }
528551
529552 @ Override
530- public Answer CheckConsoleProxyLoad (final CheckConsoleProxyLoadCommand cmd ) {
553+ public Answer checkConsoleProxyLoad (final CheckConsoleProxyLoadCommand cmd ) {
531554 return Answer .createUnsupportedCommandAnswer (cmd );
532555 }
533556
534557 @ Override
535- public Answer WatchConsoleProxyLoad (final WatchConsoleProxyLoadCommand cmd ) {
558+ public Answer watchConsoleProxyLoad (final WatchConsoleProxyLoadCommand cmd ) {
536559 return Answer .createUnsupportedCommandAnswer (cmd );
537560 }
538561
@@ -543,7 +566,7 @@ public GetDomRVersionAnswer getDomRVersion(final GetDomRVersionCmd cmd) {
543566 }
544567
545568 @ Override
546- public SecurityGroupRuleAnswer AddSecurityGroupRules (final SecurityGroupRulesCmd cmd , final SimulatorInfo info ) {
569+ public SecurityGroupRuleAnswer addSecurityGroupRules (final SecurityGroupRulesCmd cmd , final SimulatorInfo info ) {
547570 if (!info .isEnabled ()) {
548571 return new SecurityGroupRuleAnswer (cmd , false , "Disabled" , SecurityGroupRuleAnswer .FailureReason .CANNOT_BRIDGE_FIREWALL );
549572 }
@@ -611,7 +634,7 @@ private boolean logSecurityGroupAction(final SecurityGroupRulesCmd cmd, final Te
611634 }
612635
613636 @ Override
614- public Answer SavePassword (final SavePasswordCommand cmd ) {
637+ public Answer savePassword (final SavePasswordCommand cmd ) {
615638 return new Answer (cmd );
616639 }
617640
0 commit comments