/// <summary> /// Checks if ElasticIP is free to assign /// </summary> /// <param name="elasticIp">IP to check</param> /// <returns>TRUE if ElasticIP is free to assign</returns> public bool IsElasticIpFree(String elasticIp) { DescribeAddressesResult describeAddressesResult = _ec2.DescribeAddresses(new DescribeAddressesRequest()).DescribeAddressesResult; foreach (Address address in describeAddressesResult.Address) { if (address.PublicIp == elasticIp && string.IsNullOrEmpty(address.InstanceId)) { return(true); } } return(false); }
/// <summary> /// Checks if elastic IP is assigned /// </summary> /// <param name="instance">Amazon instance</param> /// <returns>True if ElasticIP is assigned to the current instance.</returns> public bool IsElasticIpAssigned(RunningInstance instance) { if (null != instance) { DescribeAddressesResult describeAddressesResult = _ec2.DescribeAddresses(new DescribeAddressesRequest()).DescribeAddressesResult; foreach (Address address in describeAddressesResult.Address) { if (instance.InstanceId.Equals(address.InstanceId, StringComparison.OrdinalIgnoreCase)) { return(true); } } } return(false); }