Get public IP for Azure vmss nodes

This is required for getting public IP when --public-ip-per-vm
(publicIpAddressConfiguration) is enabled for vmss.
pull/58/head
Pengfei Ni 2018-09-11 12:59:13 +08:00
parent 6b1af84d4a
commit 303af63ec9
1 changed files with 24 additions and 4 deletions

View File

@ -291,8 +291,6 @@ func (ss *scaleSet) GetPrimaryVMSetName() string {
}
// GetIPByNodeName gets machine private IP and public IP by node name.
// TODO(feiskyer): Azure vmss doesn't support associating a public IP to single virtual machine yet,
// fix this after it is supported.
func (ss *scaleSet) GetIPByNodeName(nodeName string) (string, string, error) {
nic, err := ss.GetPrimaryInterface(nodeName)
if err != nil {
@ -306,8 +304,30 @@ func (ss *scaleSet) GetIPByNodeName(nodeName string) (string, string, error) {
return "", "", err
}
targetIP := *ipConfig.PrivateIPAddress
return targetIP, "", nil
internalIP := *ipConfig.PrivateIPAddress
publicIP := ""
if ipConfig.PublicIPAddress != nil && ipConfig.PublicIPAddress.ID != nil {
pipID := *ipConfig.PublicIPAddress.ID
pipName, err := getLastSegment(pipID)
if err != nil {
return "", "", fmt.Errorf("failed to get publicIP name for node %q with pipID %q", nodeName, pipID)
}
resourceGroup, err := ss.GetNodeResourceGroup(nodeName)
if err != nil {
return "", "", err
}
pip, existsPip, err := ss.getPublicIPAddress(resourceGroup, pipName)
if err != nil {
return "", "", err
}
if existsPip {
publicIP = *pip.IPAddress
}
}
return internalIP, publicIP, nil
}
// This returns the full identifier of the primary NIC for the given VM.