Bug 5077: Codes break the security rules
[nemo.git] / nemo-tools / sandbox / src / main / java / org / opendaylight / nemo / tool / sandbox / models / VirtualMachine.java
1 /*
2  * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.nemo.tool.sandbox.models;
10
11 import org.opendaylight.nemo.tool.sandbox.CmdExecutor;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 /**
17  * Created by hj on 12/8/15.
18  */
19 public class VirtualMachine extends Host {
20     private static Logger log = LoggerFactory.getLogger(VirtualMachine.class);
21     public VirtualMachine(String name,String uuId) {
22         super(NodeType.VM, name,uuId);
23     }
24
25     @Override
26     protected List<String> generateCommands() {
27         List<String> commands = new ArrayList<String>(generateHost());
28         //TODO: host script.
29         //open route flag
30         commands.add("ip netns exec "+getName()+"echo 1 > /proc/sys/net/ipv4/ip_forward");
31         //add default route
32         if(connectors.size()>0) {
33             commands.add("ip netns exec route add default dev "+ connectors.get(0));
34         }
35         return commands;
36     }
37
38     @Override
39     public void uninstall(){
40         try {
41             CmdExecutor.sshExecute("ip netns del " + getName());
42         } catch (Exception e) {
43             // TODO Auto-generated catch block
44             log.error(e);
45         }
46     }
47 }