use of com.microsoft.azure.management.Azure in project azure-tools-for-java by Microsoft.
the class ContainerRegistryMvpModel method setAdminUserEnabled.
/**
* Set AdminUser enabled status of container registry.
*/
public Registry setAdminUserEnabled(String sid, String id, boolean enabled) {
Azure azure = AuthMethodManager.getInstance().getAzureClient(sid);
Registries registries = azure.containerRegistries();
if (registries != null) {
Registry registry = registries.getById(id);
if (registry != null) {
clearTags(registry);
if (enabled) {
registry.update().withRegistryNameAsAdminUser().apply();
} else {
registry.update().withoutRegistryNameAsAdminUser().apply();
}
}
return registry;
} else {
return null;
}
}
use of com.microsoft.azure.management.Azure in project azure-tools-for-java by Microsoft.
the class AzureManagerBase method getInsightsManager.
@Nullable
public InsightsManager getInsightsManager(String sid) {
if (!isSignedIn()) {
return null;
}
return sidToInsightsManagerMap.computeIfAbsent(sid, s -> {
// Register insights namespace first
final Azure azure = getAzure(sid);
azure.providers().register(MICROSOFT_INSIGHTS_NAMESPACE);
final String tid = this.subscriptionManager.getSubscriptionTenant(sid);
return authApplicationInsights(sid, tid);
});
}
use of com.microsoft.azure.management.Azure in project azure-tools-for-java by Microsoft.
the class AzureManagerBase method getAzure.
@Override
@Nullable
public Azure getAzure(String sid) {
if (!isSignedIn()) {
return null;
}
if (sidToAzureMap.containsKey(sid)) {
return sidToAzureMap.get(sid);
}
final String tid = this.subscriptionManager.getSubscriptionTenant(sid);
final Azure azure = authTenant(tid).withSubscription(sid);
// TODO: remove this call after Azure SDK properly implements handling of unregistered provider namespaces
AzureRegisterProviderNamespaces.registerAzureNamespaces(azure);
sidToAzureMap.put(sid, azure);
return azure;
}
use of com.microsoft.azure.management.Azure in project azure-tools-for-java by Microsoft.
the class AzureSDKManager method createVirtualMachine.
public static VirtualMachine createVirtualMachine(String subscriptionId, @NotNull String name, @NotNull String resourceGroup, boolean withNewResourceGroup, @NotNull String size, @NotNull String region, final VirtualMachineImage vmImage, Object knownImage, boolean isKnownImage, final StorageAccount storageAccount, final Network network, VirtualNetwork newNetwork, boolean withNewNetwork, @NotNull String subnet, @Nullable PublicIPAddress pip, boolean withNewPip, @Nullable AvailabilitySet availabilitySet, boolean withNewAvailabilitySet, @NotNull final String username, @Nullable final String password, @Nullable String publicKey) throws Exception {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
Azure azure = azureManager.getAzure(subscriptionId);
boolean isWindows;
if (isKnownImage) {
isWindows = knownImage instanceof KnownWindowsVirtualMachineImage;
} else {
isWindows = vmImage.osDiskImage().operatingSystem().equals(OperatingSystemTypes.WINDOWS);
}
// ------ Resource Group ------
VirtualMachine.DefinitionStages.WithGroup withGroup = azure.virtualMachines().define(name).withRegion(region);
Creatable<ResourceGroup> newResourceGroup = null;
VirtualMachine.DefinitionStages.WithNetwork withNetwork;
if (withNewResourceGroup) {
newResourceGroup = azure.resourceGroups().define(resourceGroup).withRegion(region);
withNetwork = withGroup.withNewResourceGroup(newResourceGroup);
} else {
withNetwork = withGroup.withExistingResourceGroup(resourceGroup);
}
// ------ Virtual Network -----
VirtualMachine.DefinitionStages.WithPublicIPAddress withPublicIpAddress;
if (withNewNetwork) {
Network.DefinitionStages.WithGroup networkWithGroup = azure.networks().define(newNetwork.name).withRegion(region);
Creatable<Network> newVirtualNetwork;
if (withNewResourceGroup) {
newVirtualNetwork = networkWithGroup.withNewResourceGroup(newResourceGroup).withAddressSpace(newNetwork.addressSpace).withSubnet(newNetwork.subnet.name, newNetwork.subnet.addressSpace);
} else {
newVirtualNetwork = networkWithGroup.withExistingResourceGroup(resourceGroup).withAddressSpace(newNetwork.addressSpace).withSubnet(newNetwork.subnet.name, newNetwork.subnet.addressSpace);
}
withPublicIpAddress = withNetwork.withNewPrimaryNetwork(newVirtualNetwork).withPrimaryPrivateIPAddressDynamic();
// withPublicIpAddress = withNetwork.withNewPrimaryNetwork("10.0.0.0/28").
// .withPrimaryPrivateIpAddressDynamic();
} else {
withPublicIpAddress = withNetwork.withExistingPrimaryNetwork(network).withSubnet(subnet).withPrimaryPrivateIPAddressDynamic();
}
// ------ Public IP Address------
VirtualMachine.DefinitionStages.WithOS withOS;
if (pip == null) {
if (withNewPip) {
withOS = withPublicIpAddress.withNewPrimaryPublicIPAddress(name + "pip");
} else {
withOS = withPublicIpAddress.withoutPrimaryPublicIPAddress();
}
} else {
withOS = withPublicIpAddress.withExistingPrimaryPublicIPAddress(pip);
}
// ------ OS and credentials -----
VirtualMachine.DefinitionStages.WithCreate withCreate;
if (isWindows) {
VirtualMachine.DefinitionStages.WithWindowsAdminUsernameManagedOrUnmanaged withWindowsAdminUsername;
if (isKnownImage) {
withWindowsAdminUsername = withOS.withPopularWindowsImage((KnownWindowsVirtualMachineImage) knownImage);
} else {
withWindowsAdminUsername = withOS.withSpecificWindowsImageVersion(vmImage.imageReference());
}
withCreate = withWindowsAdminUsername.withAdminUsername(username).withAdminPassword(password).withUnmanagedDisks();
} else {
VirtualMachine.DefinitionStages.WithLinuxRootPasswordOrPublicKeyManagedOrUnmanaged withLinuxRootPasswordOrPublicKey;
if (isKnownImage) {
withLinuxRootPasswordOrPublicKey = withOS.withPopularLinuxImage((KnownLinuxVirtualMachineImage) knownImage).withRootUsername(username);
} else {
withLinuxRootPasswordOrPublicKey = withOS.withSpecificLinuxImageVersion(vmImage.imageReference()).withRootUsername(username);
}
VirtualMachine.DefinitionStages.WithLinuxCreateManagedOrUnmanaged withLinuxCreate;
// we assume either password or public key is not empty
if (password != null && !password.isEmpty()) {
withLinuxCreate = withLinuxRootPasswordOrPublicKey.withRootPassword(password);
if (publicKey != null) {
withLinuxCreate = withLinuxCreate.withSsh(publicKey);
}
} else {
withLinuxCreate = withLinuxRootPasswordOrPublicKey.withSsh(publicKey);
}
withCreate = withLinuxCreate.withUnmanagedDisks();
}
withCreate = withCreate.withSize(size);
// ---- Storage Account --------
com.microsoft.azure.management.storage.StorageAccount existedStorageAccount = azure.storageAccounts().getById(storageAccount.id());
withCreate = withCreate.withExistingStorageAccount(existedStorageAccount);
if (withNewAvailabilitySet) {
withCreate = withCreate.withNewAvailabilitySet(name + "as");
} else if (availabilitySet != null) {
withCreate = withCreate.withExistingAvailabilitySet(availabilitySet);
}
return withCreate.create();
}
use of com.microsoft.azure.management.Azure in project azure-tools-for-java by Microsoft.
the class AzureSDKManager method createInsightsResource.
public static ApplicationInsightsComponent createInsightsResource(@NotNull String subscriptionId, @NotNull String resourceGroupName, @NotNull String resourceName, @NotNull String location) throws IOException {
final InsightsManager insightsManager = getInsightsManagerClient(subscriptionId);
if (insightsManager == null) {
// not signed in
return null;
}
final Azure azure = AuthMethodManager.getInstance().getAzureClient(subscriptionId);
if (!azure.resourceGroups().contain(resourceGroupName)) {
azure.resourceGroups().define(resourceGroupName).withRegion(location).create();
}
return insightsManager.components().define(resourceName).withRegion(location).withExistingResourceGroup(resourceGroupName).withApplicationType(ApplicationType.WEB).withKind("web").create();
}
Aggregations