Ejemplo n.º 1
0
  public static void main(String[] args) throws IOException {
    System.out.format("Create, List, and Delete Networks");

    JCloudsNeutron jcloudsNeutron = new JCloudsNeutron("testTenant1", "usertest1", "123456");
    // JCloudsNeutron jcloudsNeutron = new JCloudsNeutron("demo", "demo", "DEMO_PASS");

    try {
      // Network network = jcloudsNeutron.createNetwork("abc");
      // jcloudsNeutron.listNetworks();
      // jcloudsNeutron.deleteNetwork(network);
      Network network = jcloudsNeutron.createNetwork("network5");
      //          System.out.println("NETWORKID" + network.getId());
      //  String  networkId = jcloudsNeutron.getNetworkIdByName("network1");
      //

      Subnet subnet = jcloudsNeutron.createSubnet("subnetnew", network.getId(), "192.168.4.0/24");
      //         String externalNetworkID = jcloudsNeutron.getNetworkIdByName("ext-net");
      //         Router router = jcloudsNeutron.createRouter("testRouter", externalNetworkID);
      String routerId = jcloudsNeutron.getRouterIdByName("testRouter");

      jcloudsNeutron.addRouterToInterface(routerId, subnet.getId());

      jcloudsNeutron.close();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      jcloudsNeutron.close();
    }
  }
Ejemplo n.º 2
0
  public String getNetworkIdByName(String networkName) throws NeutronException, RegionException {
    ArrayList<Network> list = listNetworks();
    if (list != null) {
      for (Network network : list) {
        if (networkName.equals(network.getName())) {
          return network.getId();
        }
      }

      throw new NotFoundByNameException();
    } else {

      throw new NotFoundAny();
    }
  }