/// <summary> /// /// </summary> /// <param name="hostname">Fully qualified host name, i.e. host.domain.com</param> /// <param name="ipAddress">The IP Address to update to.</param> public override bool UpdateHostname(string hostname, string ipAddress) { if (HasIpAddresssChanged(hostname, ipAddress) == false) { return(true); // No change, no need to update } if (IsValidIpAddress(ipAddress) == false) { logger.Error(string.Format("Invalid IP Address provided: {0}", ipAddress)); return(false); } var zones = GetHostedZones(); if (zones == null) { return(false); } try { if (!LastUpdateIpAddresses.ContainsKey(hostname)) { InitializeLastUpdateIpAddresses(hostname); } var lastIpAddress = LastUpdateIpAddresses[hostname]; var deleteRequest = GetChangeResourceRecordSetsRequest(hostname, lastIpAddress, EnumerationUtility.GetStringValue(ChangeActionType.Delete), zones); var deleteResponse = client.ChangeResourceRecordSets(deleteRequest); } //Ignore, if delete fails, its probably because the record didn't already exists catch (AmazonRoute53Exception ex) { logger.Warn(ex); } catch (Exception ex) { logger.Error(ex); } try { var createRequest = GetChangeResourceRecordSetsRequest(hostname, ipAddress, EnumerationUtility.GetStringValue(ChangeActionType.Create), zones); var createResponse = client.ChangeResourceRecordSets(createRequest); //ChangeInfo info: http://docs.amazonwebservices.com/sdkfornet/latest/apidocs/?topic=html/T_Amazon_Route53_Model_ChangeInfo.htm //response.ChangeResourceRecordSetsResult.ChangeInfo.Status LastUpdateIpAddresses[hostname] = ipAddress; return(true); } catch (Exception ex) { logger.Error(ex); return(false); } }
/// <summary> /// Checks if the given IP Address has changed from the last update. /// </summary> /// <param name="hostname">The hostname that we are checking for an update.</param> /// <param name="ipAddress">The current IP Address.</param> /// <returns>True, if the ip address has changed, otherwise false.</returns> public bool HasIpAddresssChanged(string hostname, string ipAddress) { if (LastUpdateIpAddresses.ContainsKey(hostname) && LastUpdateIpAddresses[hostname] == ipAddress) { logger.Info(string.Format("No need to update hostname {0}, the IP Address ({1}) hasn't changed.", hostname, ipAddress)); return(false); } return(true); }