@Provides @Singleton protected Org provideOrg(CommonVCloudClient discovery) { if (authException.get() != null) throw authException.get(); try { return discovery.findOrgNamed(null); } catch (AuthorizationException e) { authException.set(e); throw e; } }
@Provides @Network @Singleton protected URI provideDefaultNetwork( @org.jclouds.vcloud.endpoints.VDC URI defaultVDC, CommonVCloudClient client, Injector injector) { if (authException.get() != null) throw authException.get(); try { org.jclouds.vcloud.domain.VDC vDC = client.getVDC(defaultVDC); Map<String, ReferenceType> networks = vDC.getAvailableNetworks(); checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName()); if (networks.size() == 1) return Iterables.getLast(networks.values()).getHref(); try { String networkName = injector.getInstance( Key.get(String.class, Names.named(PROPERTY_VCLOUD_DEFAULT_NETWORK))); ReferenceType network = networks.get(networkName); checkState( network != null, String.format("network named %s not in %s", networkName, networks.keySet())); return network.getHref(); } catch (ConfigurationException e) { // TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not // work well. // Each VDC will have differnt network subnets. So we cannot assume the default VDC's // networks will // work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK optional. If this // property // is not set, they are expected to add NetworkConfig to the options when launching a // server. return null; // throw new IllegalStateException(String.format("you must specify the property %s as one of // %s", // PROPERTY_VCLOUD_DEFAULT_NETWORK, networks.keySet()), e); } } catch (AuthorizationException e) { authException.set(e); throw e; } }