d5a898e62adfb4de64827b0b852f7b930b14f2bc
[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 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 /**
18  * Created by hj on 12/8/15.
19  */
20 public class VirtualMachine extends Host {
21     private static Logger log = LoggerFactory.getLogger(VirtualMachine.class);
22     public VirtualMachine(String name,String uuId) {
23         super(NodeType.VM, name,uuId);
24     }
25
26     @Override
27     protected List<String> generateCommands() {
28         List<String> commands = new ArrayList<String>(generateHost());
29         //TODO: host script.
30         //open route flag
31         commands.add("ip netns exec "+getName()+"echo 1 > /proc/sys/net/ipv4/ip_forward");
32         //add default route
33         if(connectors.size()>0) {
34             commands.add("ip netns exec route add default dev "+ connectors.get(0));
35         }
36         return commands;
37     }
38
39     @Override
40     public void uninstall(){
41         try {
42             CmdExecutor.sshExecute("ip netns del " + getName());
43         } catch (Exception e) {
44             // TODO Auto-generated catch block
45             log.error("Exception:",e);
46         }
47     }
48 }