コード例 #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();
    }
  }
コード例 #2
0
 public boolean checkNetworkAddrExist(String cidr) throws RegionException {
   ArrayList<Subnet> list = listSubnet();
   for (Subnet subnet : list) {
     if (cidr.equalsIgnoreCase(subnet.getCidr())) {
       return true;
     }
   }
   return false;
 }
コード例 #3
0
  public String getSubnetIdByName(String subnetName, String networkId)
      throws NeutronException, RegionException {
    ArrayList<Subnet> list = listSubnet();

    if (list != null) {
      for (Subnet subnet : list) {
        if (subnetName.equals(subnet.getName()) && networkId.equals(subnet.getNetworkId())) {
          return subnet.getId();
        }
      }

      throw new NotFoundByNameException();
    } else {

      throw new NotFoundAny();
    }
  }