Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,8 @@ When access to the VM must go through a proxy, the proxy configuration should be

To configure the IP-port mapping, use the cidr-port-rel key. This requires a list of entries in the format "CIDR:initial-port". Based on this list, the system will assign a port by matching the allocated IP with the corresponding CIDR and applying the specified initial port.

In order to allow reusing a backend definitions, the proxy configuration is not used by spread when it can ssh directly to the destination IP address.

<a name="linode"/>

## Linode backend
Expand Down
4 changes: 4 additions & 0 deletions smoke/spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ backends:
halt-timeout: 2h
wait-timeout: 5m
groups: [default]
proxy: ingress-haproxy.ps7.canonical.com
cidr-port-rel: [10.151.54.0/24:4000]
environment:
HTTP_PROXY: 'http://egress.ps7.internal:3128'
HTTPS_PROXY: 'http://egress.ps7.internal:3128'
Expand Down Expand Up @@ -83,6 +85,8 @@ backends:
halt-timeout: 2h
wait-timeout: 5m
groups: [default]
proxy: ingress-haproxy.ps7.canonical.com
cidr-port-rel: [10.151.89.0/24:8000]
environment:
HTTP_PROXY: 'http://egress.ps7.internal:3128'
HTTPS_PROXY: 'http://egress.ps7.internal:3128'
Expand Down
2 changes: 2 additions & 0 deletions spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ backends:
plan: shared.small
halt-timeout: 2h
wait-timeout: 10m
proxy: ingress-haproxy.ps7.canonical.com
cidr-port-rel: [10.151.54.0/24:4000]
groups: [default]
environment: &openstack-env
HTTP_PROXY: 'http://egress.ps7.internal:3128'
Expand Down
28 changes: 28 additions & 0 deletions spread/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,29 @@ func (p *openstackProvider) waitProvision(ctx context.Context, s *openstackServe

var openstackServerBootTimeout = 5 * time.Minute
var openstackServerBootRetry = 5 * time.Second
var openstackDirectSSHProbeTimeout = 3 * time.Second

func canReachDirectSSH(ctx context.Context, address string, timeout time.Duration) bool {
if net.ParseIP(address) == nil {
return false
}

dialCtx := ctx
if _, hasDeadline := ctx.Deadline(); !hasDeadline {
var cancel context.CancelFunc
dialCtx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()
}

dialer := net.Dialer{Timeout: timeout}
conn, err := dialer.DialContext(dialCtx, "tcp", net.JoinHostPort(address, "22"))
if err != nil {
debugf("Direct SSH probe to %s failed: %v", address, err)
return false
}
_ = conn.Close()
return true
}

func countIPsBetween(initialIp net.IP, finalIp net.IP) (uint32, error) {
ip1Int := binary.BigEndian.Uint32(initialIp.To4())
Expand All @@ -594,6 +617,11 @@ func (p *openstackProvider) updateAddressIfProxyDefined(ctx context.Context, s *
return nil
}

if canReachDirectSSH(ctx, s.address, openstackDirectSSHProbeTimeout) {
printf("Server reachable directly via SSH, skipping proxy mapping (%s)", s.d.Name)
return nil
}

for _, rel := range s.p.backend.CIDRPortRel {
parts := strings.SplitN(rel, ":", 2)
if len(parts) != 2 {
Expand Down
Loading