com.microsoft.azure.management.Azure.virtualMachines()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中com.microsoft.azure.management.Azure.virtualMachines()方法的一些代码示例,展示了Azure.virtualMachines()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Azure.virtualMachines()方法的具体详情如下:
包路径:com.microsoft.azure.management.Azure
类名称:Azure
方法名:virtualMachines

Azure.virtualMachines介绍

暂无

代码示例

代码示例来源:origin: Microsoft/azure-tools-for-java

public static VirtualMachine getVM(Azure azureClient, String resourceGroup, String hostName) throws AzureDockerException {
 try {
  return azureClient.virtualMachines().getByResourceGroup(resourceGroup, hostName);
 } catch (Exception e) {
  throw new AzureDockerException(e.getMessage(), e);
 }
}

代码示例来源:origin: jenkinsci/azure-vm-agents-plugin

/**
 * Determines whether a virtual machine exists.
 *
 * @param vmName            Name of the VM.
 * @param resourceGroupName Resource group of the VM.
 * @return If the virtual machine exists
 */
private boolean virtualMachineExists(
    String vmName,
    String resourceGroupName) throws AzureCloudException {
  LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: virtualMachineExists: check for {0}", vmName);
  VirtualMachine vm = null;
  try {
    vm = azureClient.virtualMachines().getByResourceGroup(resourceGroupName, vmName);
  } catch (Exception e) {
    throw AzureCloudException.create(e);
  }
  if (vm != null) {
    LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: virtualMachineExists: {0} exists", vmName);
    return true;
  } else {
    LOGGER.log(Level.INFO,
        "AzureVMManagementServiceDelegate: virtualMachineExists: {0} doesn't exist",
        vmName);
    return false;
  }
}

代码示例来源:origin: Microsoft/azure-tools-for-java

public static void deleteDockerHost(Azure azureClient, String resourceGroup, String vmName) {
 if (azureClient == null || resourceGroup == null || vmName == null ) {
  throw new AzureDockerException("Unexpected param values; Azure instance, resource group and VM name cannot be null");
 }
 VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(resourceGroup, vmName);
 if (vm == null) {
  throw new AzureDockerException(String.format("Unexpected error retrieving VM %s from Azure", vmName));
 }
 try {
  azureClient.virtualMachines().deleteById(vm.id());
 } catch (Exception e) {
  throw new AzureDockerException(String.format("Unexpected error while deleting VM %s and its associated resources", vmName));
 }
}

代码示例来源:origin: jenkinsci/azure-vm-agents-plugin

/**
 * Gets list of virtual machine sizes. If it can't fetch the data then it will return a default hardcoded list
 *
 * @param location Location to obtain VM sizes for
 * @return List of VM sizes
 */
public List<String> getVMSizes(String location) {
  if (location == null || location.isEmpty()) {
    //if the location is not available we'll just return a default list with some of the most common VM sizes
    return DEFAULT_VM_SIZES;
  }
  try {
    List<String> ret = new ArrayList<>();
    PagedList<VirtualMachineSize> vmSizes = azureClient.virtualMachines().sizes().listByRegion(location);
    for (VirtualMachineSize vmSize : vmSizes) {
      ret.add(vmSize.name());
    }
    return ret;
  } catch (Exception e) {
    LOGGER.log(Level.WARNING,
        "AzureVMManagementServiceDelegate: getVMSizes: "
            + "error while fetching the VM sizes {0}. Will return default list ",
        e);
    return AVAILABLE_ROLE_SIZES.get(location);
  }
}

代码示例来源:origin: Microsoft/azure-tools-for-java

@Override
protected void refreshItems() throws AzureCmdException {
 try {
  Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient;
  VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
  if (vm != null) {
   refreshDockerHostInstance(vm);
  }
 } catch (Exception e) {
  DefaultLoader.getUIHelper().logError(e.getMessage(), e);
 }
}

代码示例来源:origin: Microsoft/azure-tools-for-java

public static AzureDockerVM getDockerVM(Azure azureClient, String resourceGroup, String hostName) {
 try {
  AzureDockerVM azureDockerVM = getDockerVM(azureClient.virtualMachines().getByResourceGroup(resourceGroup, hostName));
  azureDockerVM.sid = azureClient.subscriptionId();
  return azureDockerVM;
 } catch (Exception e) {
  throw new AzureDockerException(e.getMessage(), e);
 }
}

代码示例来源:origin: Microsoft/azure-tools-for-java

public static Map<String, DockerHost> getDockerHosts(Azure azureClient, Map<String, AzureDockerCertVault> dockerVaultsMap) {
 Map<String, DockerHost> dockerHostMap = getDockerHosts(azureClient.virtualMachines().list(), dockerVaultsMap);
 for (DockerHost dockerHost : dockerHostMap.values()) {
  dockerHost.sid = azureClient.subscriptionId();
  if (dockerHost.hostVM != null) dockerHost.hostVM.sid = azureClient.subscriptionId();
 }
 return dockerHostMap;
}

代码示例来源:origin: Microsoft/azure-tools-for-java

try {
  Azure azure = azureManager.getAzure(sid);
  List<VirtualMachine> virtualMachines = azure.virtualMachines().list();

代码示例来源:origin: Microsoft/azure-tools-for-java

public static boolean isDeletingDockerHostAllSafe(Azure azureClient, String resourceGroup, String vmName) {
 if (azureClient == null || resourceGroup == null || vmName == null ) {
  return false;
 }
 VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(resourceGroup, vmName);
 if (vm == null) {
  return false;
 }
 PublicIPAddress publicIp = vm.getPrimaryPublicIPAddress();
 NicIPConfiguration nicIPConfiguration = publicIp.getAssignedNetworkInterfaceIPConfiguration();
 Network vnet = nicIPConfiguration.getNetwork();
 NetworkInterface nic = vm.getPrimaryNetworkInterface();
 return nic.ipConfigurations().size() == 1 &&
   vnet.subnets().size() == 1  &&
   vnet.subnets().values().toArray(new Subnet[1])[0].inner().ipConfigurations().size() == 1;
}

代码示例来源:origin: jenkinsci/azure-vm-agents-plugin

/**
 * Shutdowns Azure virtual machine.
 *
 * @param agent
 * @throws Exception
 */
public void shutdownVirtualMachine(AzureVMAgent agent) {
  LOGGER.log(Level.INFO, "AzureVMManagementServiceDelegate: shutdownVirtualMachine: called for {0}",
      agent.getNodeName());
  try {
    azureClient.virtualMachines()
        .getByResourceGroup(agent.getResourceGroupName(), agent.getNodeName()).deallocate();
  } catch (Exception e) {
    LOGGER.log(Level.WARNING,
        "AzureVMManagementServiceDelegate: provision: could not terminate or shutdown {0}, {1}",
        new Object[]{agent.getNodeName(), e});
  }
}

代码示例来源:origin: jenkinsci/azure-vm-agents-plugin

/**
 * Gets current status of virtual machine.
 *
 * @param vmName            Virtual machine name.
 * @param resourceGroupName Resource group name.
 * @return Virtual machine status.
 * @throws AzureCloudException
 */
private VMStatus getVirtualMachineStatus(
    String vmName,
    String resourceGroupName) throws AzureCloudException {
  VirtualMachine vm;
  try {
    vm = azureClient.virtualMachines().getByResourceGroup(resourceGroupName, vmName);
  } catch (Exception e) {
    throw AzureCloudException.create(e);
  }
  final String provisioningState = vm.provisioningState();
  if (!provisioningState.equalsIgnoreCase("succeeded")) {
    if (provisioningState.equalsIgnoreCase("updating")) {
      return VMStatus.UPDATING;
    } else {
      return VMStatus.PROVISIONING_OR_DEPROVISIONING;
    }
  } else {
    return VMStatus.fromPowerState(vm.powerState());
  }
}

代码示例来源:origin: jenkinsci/azure-vm-agents-plugin

/**
 * Restarts Azure virtual machine.
 *
 * @param agent
 * @throws AzureCloudException
 */
public void restartVirtualMachine(AzureVMAgent agent) throws AzureCloudException {
  try {
    azureClient.virtualMachines()
        .getByResourceGroup(agent.getResourceGroupName(), agent.getNodeName()).restart();
  } catch (Exception e) {
    throw AzureCloudException.create(e);
  }
}

代码示例来源:origin: Microsoft/azure-tools-for-java

@Override
protected void azureNodeAction(NodeActionEvent e)
  throws AzureCmdException {
 try {
  removeAllChildNodes();
  setIconPath(DOCKERHOST_WAIT_ICON_PATH);
  Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient;
  VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
  if (vm != null) {
   vm.restart();
   setIconPath(DOCKERHOST_RUN_ICON_PATH);
   refreshDockerHostInstance(vm);
  }
 } catch (Exception ee) {
  DefaultLoader.getUIHelper().logError(ee.getMessage(), ee);
 }
}

代码示例来源:origin: jenkinsci/azure-vm-agents-plugin

azureClient.virtualMachines().getByResourceGroup(agent.getResourceGroupName(), agent.getNodeName()).start();
  successful = true; // may be we can just return
} catch (Exception e) {

代码示例来源:origin: Microsoft/azure-tools-for-java

public static VirtualMachine updateDockerHostVM(Azure azureClient, DockerHost dockerHost) throws AzureDockerException {
 try {
  VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
  HashMap<String, Object> protectedSettings = new HashMap<>();
  protectedSettings.put("username", dockerHost.certVault.vmUsername);

代码示例来源:origin: Microsoft/azure-tools-for-java

public static void deleteDockerHostAll(Azure azureClient, String resourceGroup, String vmName) {
 if (azureClient == null || resourceGroup == null || vmName == null ) {
  throw new AzureDockerException("Unexpected param values; Azure instance, resource group and VM name cannot be null");
 }
 VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(resourceGroup, vmName);
 if (vm == null) {
  throw new AzureDockerException(String.format("Unexpected error retrieving VM %s from Azure", vmName));
 }
 try {
  PublicIPAddress publicIp = vm.getPrimaryPublicIPAddress();
  NicIPConfiguration nicIPConfiguration = publicIp.getAssignedNetworkInterfaceIPConfiguration();
  Network vnet = nicIPConfiguration.getNetwork();
  NetworkInterface nic = vm.getPrimaryNetworkInterface();
  azureClient.virtualMachines().deleteById(vm.id());
  azureClient.networkInterfaces().deleteById(nic.id());
  azureClient.publicIPAddresses().deleteById(publicIp.id());
  azureClient.networks().deleteById(vnet.id());
 } catch (Exception e) {
  throw new AzureDockerException(String.format("Unexpected error while deleting VM %s and its associated resources", vmName));
 }
}

代码示例来源:origin: Microsoft/azure-tools-for-java

@Override
protected void azureNodeAction(NodeActionEvent e)
    throws AzureCmdException {
  try {
    AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    // not signed in
    if (azureManager == null) {
      return;
    }
    azureManager.getAzure(subscriptionId).virtualMachines().deleteByResourceGroup(virtualMachine.resourceGroupName(), virtualMachine.name());
  } catch (Exception ex) {
  }
  DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
    @Override
    public void run() {
      // instruct parent node to remove this node
      getParent().removeDirectChildNode(VMNode.this);
    }
  });
}

代码示例来源:origin: Microsoft/azure-tools-for-java

@Override
protected void azureNodeAction(NodeActionEvent e)
  throws AzureCmdException {
 try {
  removeAllChildNodes();
  setIconPath(DOCKERHOST_STOP_ICON_PATH);
  for (NodeAction nodeAction : getNodeActions()) {
   nodeAction.setEnabled(false);
  }
  getNodeActionByName(ACTION_START).setEnabled(true);
  getNodeActionByName(ACTION_RESTART).setEnabled(true);
  Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient;
  VirtualMachine vm = azureClient.virtualMachines().getByResourceGroup(dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
  if (vm != null) {
   vm.powerOff();
   refreshDockerHostInstance(vm);
  }
  for (NodeAction nodeAction : getNodeActions()) {
   nodeAction.setEnabled(true);
  }
 } catch (Exception ee) {
  DefaultLoader.getUIHelper().logError(ee.getMessage(), ee);
 }
}

代码示例来源:origin: jenkinsci/azure-vm-agents-plugin

azureClient.virtualMachines().getByResourceGroup(template.getResourceGroupName(), azureAgent.getNodeName());

代码示例来源:origin: jenkinsci/azure-vm-agents-plugin

vm = azureClient.virtualMachines().getByResourceGroup(template.getResourceGroupName(), azureAgent.getNodeName());
} catch (Exception e) {
  throw AzureCloudException.create(e);

相关文章