use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner 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.NetworkInterfaceInner in project photon-model by vmware.
the class AzureLoadBalancerService method getNetworkInterfaceInner.
/**
* Fetch single Network Interface from Azure
*
* @param context Azure load balancer context
* @param networkInterfaceState state of the network interface to be fetched from Azure
* @return DeferredResult
*/
private DeferredResult<NetworkInterfaceInner> getNetworkInterfaceInner(AzureLoadBalancerContext context, NetworkInterfaceState networkInterfaceState) {
String networkInterfaceResGrp = AzureUtils.getResourceGroupName(networkInterfaceState.id);
final String msg = "Getting network Interface [" + networkInterfaceState.name + "] in resource group [" + networkInterfaceResGrp + "].";
logInfo(() -> msg);
AzureDeferredResultServiceCallback<NetworkInterfaceInner> callback = new AzureDeferredResultServiceCallback<NetworkInterfaceInner>(this, msg) {
@Override
protected DeferredResult<NetworkInterfaceInner> consumeSuccess(NetworkInterfaceInner networkInterface) {
if (networkInterface == null) {
logWarning("Failed to get information for network interface: %s", networkInterfaceState.name);
}
return DeferredResult.completed(networkInterface);
}
};
NetworkInterfacesInner azureNetworkInterfaceClient = context.azureSdkClients.getNetworkManagementClientImpl().networkInterfaces();
azureNetworkInterfaceClient.getByResourceGroupAsync(networkInterfaceResGrp, networkInterfaceState.name, null, /* expand */
callback);
return callback.toDeferredResult();
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner in project photon-model by vmware.
the class AzureLoadBalancerService method createOrUpdateNetworkInterface.
/**
* Create or Update network interface in Azure
*
* @param context Azure load balancer context
* @param networkInterfaceInner Azure network interface construct
* @return DeferredResult
*/
private DeferredResult<NetworkInterfaceInner> createOrUpdateNetworkInterface(AzureLoadBalancerContext context, NetworkInterfaceInner networkInterfaceInner) {
String networkInterfaceResGrp = AzureUtils.getResourceGroupName(networkInterfaceInner.id());
final String msg = "Update network Interface [" + networkInterfaceInner.name() + "] in resource group [" + networkInterfaceResGrp + "].";
logInfo(() -> msg);
NetworkInterfacesInner azureNetworkInterfaceClient = context.azureSdkClients.getNetworkManagementClientImpl().networkInterfaces();
AzureProvisioningCallbackWithRetry<NetworkInterfaceInner> handler = new AzureProvisioningCallbackWithRetry<NetworkInterfaceInner>(this, msg) {
@Override
protected DeferredResult<NetworkInterfaceInner> consumeProvisioningSuccess(NetworkInterfaceInner networkInterfaceInner) {
return DeferredResult.completed(networkInterfaceInner);
}
@Override
protected Runnable checkProvisioningStateCall(ServiceCallback<NetworkInterfaceInner> checkProvisioningStateCallback) {
return () -> azureNetworkInterfaceClient.getByResourceGroupAsync(networkInterfaceResGrp, networkInterfaceInner.name(), null, /* expand */
checkProvisioningStateCallback);
}
@Override
protected String getProvisioningState(NetworkInterfaceInner body) {
return body.provisioningState();
}
@Override
protected Runnable retryServiceCall(ServiceCallback<NetworkInterfaceInner> retryCallback) {
return () -> azureNetworkInterfaceClient.createOrUpdateAsync(networkInterfaceResGrp, networkInterfaceInner.name(), networkInterfaceInner, retryCallback);
}
};
azureNetworkInterfaceClient.createOrUpdateAsync(networkInterfaceResGrp, networkInterfaceInner.name(), networkInterfaceInner, handler);
return handler.toDeferredResult();
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method createNic.
private void createNic(Map<String, Pair<NetworkInterfaceInner, String>> remoteStates, EnumerationContext ctx, Map<String, String> subnetPerNicId, List<DeferredResult<NetworkInterfaceState>> ops) {
remoteStates.values().stream().forEach(p -> {
NetworkInterfaceInner remoteNic = p.getLeft();
NetworkInterfaceState state = new NetworkInterfaceState();
processCreateUpdateNicRequest(state, remoteNic, ctx, ops, subnetPerNicId, true);
});
}
use of com.microsoft.azure.management.network.implementation.NetworkInterfaceInner 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