@Inject public VSphereComputeServiceAdapter(Supplier<VSphereServiceInstance> serviceInstance, Supplier<Map<String, CustomFieldDef>> customFields, Supplier<VSphereHost> vSphereHost, VirtualMachineToImage virtualMachineToImage, Function<String, DistributedVirtualPortgroup> distributedVirtualSwitchFunction, NetworkConfigurationForNetworkAndOptions networkConfigurationForNetworkAndOptions, Function<String, VSphereHost> hostFunction, @Named(VSphereConstants.JCLOUDS_VSPHERE_VM_PASSWORD) String vmInitPassword) { this.serviceInstance = checkNotNull(serviceInstance, "serviceInstance"); this.customFields = checkNotNull(customFields, "customFields"); this.virtualMachineToImage = virtualMachineToImage; this.vmInitPassword = checkNotNull(vmInitPassword, "vmInitPassword"); this.networkConfigurationForNetworkAndOptions = checkNotNull(networkConfigurationForNetworkAndOptions, "networkConfigurationForNetworkAndOptions"); this.vSphereHost = checkNotNull(vSphereHost, "vSphereHost"); this.distributedVirtualPortgroupFunction = distributedVirtualSwitchFunction; this.hostFunction = hostFunction; }
@Inject public synchronized void start() { try (VSphereServiceInstance client = serviceInstance.get();) { CustomFieldDef[] customFieldDefs = client.getInstance().getCustomFieldsManager().getField(); if (null != customFieldDefs) { for (CustomFieldDef field : customFieldDefs) { if (field.getName().equalsIgnoreCase(VSphereConstants.JCLOUDS_TAGS)) { customFieldDefMap.put(VSphereConstants.JCLOUDS_TAGS, field); } else if (field.getName().equalsIgnoreCase(VSphereConstants.JCLOUDS_GROUP)) { customFieldDefMap.put(VSphereConstants.JCLOUDS_GROUP, field); } } } if (!customFieldDefMap.containsKey(VSphereConstants.JCLOUDS_TAGS)) customFieldDefMap.put(VSphereConstants.JCLOUDS_TAGS, client.getInstance().getCustomFieldsManager().addCustomFieldDef(VSphereConstants.JCLOUDS_TAGS, null, null, null)); if (!customFieldDefMap.containsKey(VSphereConstants.JCLOUDS_GROUP)) customFieldDefMap.put(VSphereConstants.JCLOUDS_GROUP, client.getInstance().getCustomFieldsManager().addCustomFieldDef(VSphereConstants.JCLOUDS_GROUP, null, null, null)); } catch (Throwable t) { Throwables.propagate(t); } }
/** * TODO: メソッドコメントを記述 * * @param vmwareProcessClient * @param instanceNo */ public void updateCustomValue(VmwareProcessClient vmwareProcessClient, Long instanceNo) { // カスタムフィールドがない場合は作成 CustomFieldDef customFieldDef = vmwareProcessClient.getCustomFieldDef(fieldUserName, VirtualMachine.class); if (customFieldDef == null) { vmwareProcessClient.addCustomFieldDef(fieldUserName, VirtualMachine.class); } VmwareInstance vmwareInstance = vmwareInstanceDao.read(instanceNo); Instance instance = instanceDao.read(instanceNo); Farm farm = farmDao.read(instance.getFarmNo()); User user = userDao.read(farm.getUserNo()); // カスタムフィールドの値を設定 vmwareProcessClient.setCustomValue(vmwareInstance.getMachineName(), fieldUserName, user.getUsername()); }
public void setCustomFieldValue(String fieldName, String value) throws Exception { CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager()); int key = getCustomFieldKey(fieldName); if (key == 0) { try { CustomFieldDef field = cfmMo.addCustomerFieldDef(fieldName, getMor().getType(), null, null); key = field.getKey(); } catch (Exception e) { // assuming the exception is caused by concurrent operation from other places // so we retieve the key again key = getCustomFieldKey(fieldName); } } if (key == 0) throw new Exception("Unable to setup custom field facility"); cfmMo.setField(getMor(), key, value); }
public int ensureCustomFieldDef(String morType, String fieldName) throws Exception { int key = getCustomFieldKey(morType, fieldName); if (key > 0) return key; try { CustomFieldDef field = addCustomerFieldDef(fieldName, morType, null, null); return field.getKey(); } catch (Exception e) { // assuming that someone is adding it key = getCustomFieldKey(morType, fieldName); } if (key == 0) throw new Exception("Unable to setup custom field facility for " + morType + ":" + fieldName); return key; }
@Inject public VirtualMachineToNodeMetadata(Map<VirtualMachinePowerState, NodeMetadata.Status> toPortableNodeStatus, Supplier<Map<String, CustomFieldDef>> customFields, Supplier<VSphereServiceInstance> serviceInstanceSupplier, Function<String, DistributedVirtualPortgroup> distributedVirtualPortgroupFunction, @Named(VSphereConstants.JCLOUDS_VSPHERE_VM_PASSWORD) String vmInitPassword) { this.toPortableNodeStatus = checkNotNull(toPortableNodeStatus, "PortableNodeStatus"); this.customFields = checkNotNull(customFields, "customFields"); this.serviceInstanceSupplier = checkNotNull(serviceInstanceSupplier, "serviceInstanceSupplier"); this.distributedVirtualPortgroupFunction = checkNotNull(distributedVirtualPortgroupFunction, "distributedVirtualPortgroupFunction"); this.vmInitPassword = vmInitPassword; }
public List<CustomFieldDef> getCustomFieldDefs() { CustomFieldsManager manager = vmwareClient.getServiceInstance().getCustomFieldsManager(); CustomFieldDef[] defs = manager.getField(); List<CustomFieldDef> customFieldDefs = new ArrayList<CustomFieldDef>(); if (defs != null) { for (CustomFieldDef def : defs) { customFieldDefs.add(def); } } return customFieldDefs; }
public CustomFieldDef getCustomFieldDef(String name, Class<?> type) { CustomFieldsManager manager = vmwareClient.getServiceInstance().getCustomFieldsManager(); CustomFieldDef[] defs = manager.getField(); String typeName = type.getSimpleName(); if (defs != null) { for (CustomFieldDef def : defs) { if (def.getName().equals(name) && def.getManagedObjectType().equals(typeName)) { return def; } } } return null; }
public void addCustomFieldDef(String name, Class<?> type) { CustomFieldsManager manager = vmwareClient.getServiceInstance().getCustomFieldsManager(); CustomFieldDef[] defs = manager.getField(); String typeName = type.getSimpleName(); if (defs != null) { for (CustomFieldDef def : defs) { if (def.getName().equals(name) && def.getManagedObjectType().equals(typeName)) { // 既にカスタムフィールドが追加されている場合はスキップ return; } } } try { manager.addCustomFieldDef(name, typeName, null, null); } catch (DuplicateName ignore) { // 他のスレッドで同時に追加された場合に備えて握りつぶす return; } catch (RemoteException e) { throw new AutoException("EPROCESS-000525", e, name, typeName); } if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100461", name)); } }
public void removeCustomFieldDef(String name, Class<?> type) { CustomFieldsManager manager = vmwareClient.getServiceInstance().getCustomFieldsManager(); CustomFieldDef[] defs = manager.getField(); String typeName = type.getSimpleName(); CustomFieldDef customFieldDef = null; if (defs != null) { for (CustomFieldDef def : defs) { if (def.getName().equals(name) && def.getManagedObjectType().equals(typeName)) { customFieldDef = def; } } } if (customFieldDef == null) { // 既にカスタムフィールドが存在しない場合はスキップ } try { manager.removeCustomFieldDef(customFieldDef.getKey()); } catch (InvalidArgument ignore) { // 他のスレッドで同時に削除された場合に備えて握りつぶす return; } catch (RemoteException e) { throw new AutoException("EPROCESS-000526", e, name, typeName); } if (log.isInfoEnabled()) { log.info(MessageUtils.getMessage("IPROCESS-100462", name)); } }
@Override public int getCustomFieldKey(String morType, String fieldName) throws Exception { List<CustomFieldDef> fields = getFields(); if (fields != null) { for (CustomFieldDef field : fields) { if (field.getName().equals(fieldName) && field.getManagedObjectType().equals(morType)) return field.getKey(); } } return 0; }
@Override protected void configure() { super.configure(); //bind(ComputeService.class).to(VSphereComputeService.class); bind(TemplateOptions.class).to(VSphereTemplateOptions.class); bind(LocationsSupplier.class).to(VSphereLocationSupplier.class); bind(FileManagerApi.class).to(VSphereFileManager.class); bind(new TypeLiteral<ComputeServiceAdapter<VirtualMachine, Hardware, Image, Location>>() { }).to(VSphereComputeServiceAdapter.class); bind(new TypeLiteral<Function<String, DistributedVirtualPortgroup>>() { }).to(Class.class.cast(VLanNameToDistributedVirtualPortgroup.class)); bind(new TypeLiteral<Function<Location, Location>>() { }).to(Class.class.cast(IdentityFunction.class)); bind(new TypeLiteral<Function<Image, Image>>() { }).to(Class.class.cast(IdentityFunction.class)); bind(new TypeLiteral<Function<Hardware, Hardware>>() { }).to(Class.class.cast(IdentityFunction.class)); bind(new TypeLiteral<Function<VirtualMachine, NodeMetadata>>() { }).to(VirtualMachineToNodeMetadata.class); bind(new TypeLiteral<Function<HostSystem, VSphereHost>>() { }).to(HostSystemToVSphereHost.class); bind(new TypeLiteral<Supplier<VSphereServiceInstance>>() { }).to((Class) CreateAndConnectVSphereClient.class); // bind(new TypeLiteral<Supplier<Set<? extends Location>>>() { // }).to((Class) VSphereLocationSupplier.class); bind(new TypeLiteral<Supplier<VSphereHost>>() { }).to((Class) VSphereHostSupplier.class); bind(new TypeLiteral<Supplier<Map<String, CustomFieldDef>>>() { }).to((Class) CreateOrGetTagsId.class); bind(new TypeLiteral<Supplier<NetworkConfigSupplier>>() { }).to((Class) NetworkConfigSupplier.class); bind(new TypeLiteral<Function<VirtualMachine, SshClient>>() { }).to(VirtualMachineToSshClient.class); bind(new TypeLiteral<Function<VirtualMachine, Image>>() { }).to(VirtualMachineToImage.class); bind(new TypeLiteral<Function<String, VSphereHost>>() { }).to(GetRecommendedVSphereHost.class); }
CustomFieldDef addCustomFieldDef(String name, String moType, PrivilegePolicyDef fieldDefPolicy, PrivilegePolicyDef fieldPolicy) throws DuplicateName, InvalidPrivilege, RuntimeFault, RemoteException;
@Override public Map<String, CustomFieldDef> get() { checkState(customFieldDefMap.size() > 0, "(CreateOrGetTagsId) start not called"); return customFieldDefMap; }
public CustomFieldDef addCustomerFieldDef(String fieldName, String morType, PrivilegePolicyDef fieldDefPolicy, PrivilegePolicyDef fieldPolicy) throws Exception { return _context.getService().addCustomFieldDef(getMor(), fieldName, morType, fieldDefPolicy, fieldPolicy); }
public List<CustomFieldDef> getFields() throws Exception { return _context.getVimClient().getDynamicProperty(getMor(), "field"); }
List<CustomFieldDef> getField();