use of com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner in project photon-model by vmware.
the class AzureInstanceService method newAzureNetworkInterface.
/**
* Converts Photon model constructs to underlying Azure NetworkInterface model.
*/
private NetworkInterfaceInner newAzureNetworkInterface(AzureInstanceContext ctx, AzureNicContext nicCtx) {
NetworkInterfaceDescription description = nicCtx.nicStateWithDesc.description;
NetworkInterfaceIPConfigurationInner ipConfig = new NetworkInterfaceIPConfigurationInner();
ipConfig.withName(AzureUtils.generateClusterCommonName(NICCONFIG_NAME_PREFIX, ctx));
ipConfig.withSubnet(nicCtx.subnet);
if (nicCtx.publicIP != null) {
// Public IP is not auto-assigned so check for existence
ipConfig.withPublicIPAddress(new SubResource().withId(nicCtx.publicIP.id()));
}
ipConfig.withPrivateIPAllocationMethod(new IPAllocationMethod(description.assignment.name()));
if (description.assignment == IpAssignment.STATIC) {
ipConfig.withPrivateIPAddress(description.address);
}
NetworkInterfaceInner nic = new NetworkInterfaceInner();
nic.withLocation(ctx.resourceGroup.location());
// Azure's custom serializers don't handle well collections constructed with
// Collections.singletonList(), so initialize an ArrayList
List<NetworkInterfaceIPConfigurationInner> ipConfigs = new ArrayList<>();
ipConfigs.add(ipConfig);
nic.withIpConfigurations(ipConfigs);
if (nicCtx.securityGroup != null) {
// Security group is optional so check for existence
nic.withNetworkSecurityGroup(new SubResource().withId(nicCtx.securityGroup.id()));
}
return nic;
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method processCreateUpdateNicRequest.
/**
* Processes request for creating and updating Network interface resources.
*/
private void processCreateUpdateNicRequest(NetworkInterfaceState nic, NetworkInterfaceInner remoteNic, EnumerationContext ctx, List<DeferredResult<NetworkInterfaceState>> ops, Map<String, String> subnetPerNicId, boolean isCreate) {
nic.name = remoteNic.name();
nic.subnetLink = subnetPerNicId.get(remoteNic.id());
NicMetadata nicMeta = new NicMetadata();
nicMeta.state = nic;
nicMeta.macAddress = remoteNic.macAddress();
// else will default to original ID for PATCH requests
if (isCreate) {
nic.id = remoteNic.id();
nic.endpointLink = ctx.request.endpointLink;
AdapterUtils.addToEndpointLinks(nic, ctx.request.endpointLink);
nic.tenantLinks = ctx.parentCompute.tenantLinks;
nic.regionId = remoteNic.location();
nic.computeHostLink = ctx.parentCompute.documentSelfLink;
} else {
if (StringUtils.isEmpty(nic.endpointLink)) {
nic.endpointLink = ctx.request.endpointLink;
}
nic.endpointLinks.add(ctx.request.endpointLink);
}
List<NetworkInterfaceIPConfigurationInner> ipConfigurations = remoteNic.ipConfigurations();
if (ipConfigurations == null || ipConfigurations.isEmpty()) {
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
return;
}
NetworkInterfaceIPConfigurationInner nicIPConf = ipConfigurations.get(0);
nic.address = nicIPConf.privateIPAddress();
if (nicIPConf.publicIPAddress() == null) {
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
return;
}
// IP address is not directly available in NetworkInterfaceIPConfigurationInner.
// It is available as a SubResource, We use the SubResource ID of IP address from
// NetworkInterfaceIPConfigurationInner to obtain the IP address.
Consumer<Throwable> failure = e -> {
logWarning("Error getting public IP address from Azure [endpointLink:%s], [Exception:%s]", ctx.request.endpointLink, e.getMessage());
handleError(ctx, e);
};
PhotonModelUtils.runInExecutor(this.executorService, () -> {
Azure azure = ctx.azureSdkClients.getAzureClient();
azure.publicIPAddresses().getByIdAsync(nicIPConf.publicIPAddress().id()).subscribe(injectOperationContext(new Action1<PublicIPAddress>() {
@Override
public void call(PublicIPAddress publicIPAddress) {
nicMeta.publicIp = publicIPAddress.ipAddress();
if (publicIPAddress.inner().dnsSettings() != null) {
nicMeta.publicDnsName = publicIPAddress.inner().dnsSettings().fqdn();
}
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
}
}));
}, failure);
}
Aggregations