Créer une listener rule

Vous pouvez créer une listener rule pour gérer la redirection du trafic entrant entre un load balancer et ses machines virtuelles (VM) backend.

Cette action crée une règle associée à un listener spécifié, basée sur un chemin d’accès contenu dans l’URI de la requête. Les listener rules sont traitées par ordre de priorité, de la plus grande à la plus petite.

Pour modifier la règle d’une listener rule existante, voir Modifier une listener rule.

À la création d’une listener rule, vous devez enregistrer toutes les backends cibles. Pour modifier la liste des VM backend d’une listener rule, vous devez supprimer la règle et en créer une nouvelle.

Créer une listener rule avec OSC CLI

À ce jour, cette section est disponible en anglais uniquement.

The CreateListenerRule command creates a rule for traffic redirection for the specified listener. Each rule must have either the HostNamePattern or PathPattern parameter specified. Rules are treated in priority order, from the highest value to the lowest value.
Once the rule is created, you need to register backend VMs with it. For more information, see the RegisterVmsInLoadBalancer method.

For more information, see About Load Balancers.

Request sample: Creating a listener rule based on a host pattern
$ osc-cli api CreateListenerRule --profile "default" \
    --Listener '{
        "LoadBalancerName": "example-lbu",
        "LoadBalancerPort": 80
      }' \
    --ListenerRule '{
        "Action": "forward",
        "HostNamePattern": "*.example.com",
        "ListenerRuleName": "example-listener-rule",
        "Priority": 10
      }' \
    --VmIds '["i-12345678"]'
Request sample: Creating a listener rule based on a path pattern
$ osc-cli api CreateListenerRule --profile "default" \
    --Listener '{
        "LoadBalancerName": "example-lbu",
        "LoadBalancerPort": 80
      }' \
    --ListenerRule '{
        "Action": "forward",
        "PathPattern": "/docs/*",
        "ListenerRuleName": "example-listener-rule",
        "Priority": 100
      }' \
    --VmIds '["i-12345678"]'

This command contains the following attributes that you need to specify:

  • DryRun: (optional) If true, checks whether you have the required permissions to perform the action.

  • Listener: Information about the load balancer.

    • LoadBalancerName: The name of the load balancer to which the listener is attached.

    • LoadBalancerPort: The port of load balancer on which the load balancer is listening (between 1 and 65535 both included).

  • ListenerRule: Information about the listener rule.

    • Action: (optional) The type of action for the rule (always forward).

    • HostNamePattern: (optional) A host-name pattern for the rule, with a maximum length of 128 characters. This host-name pattern supports maximum three wildcards, and must not contain any special characters except -.?.

    • ListenerRuleName: A human-readable name for the listener rule.

    • PathPattern: (optional) A path pattern for the rule, with a maximum length of 128 characters. This path pattern supports maximum three wildcards, and must not contain any special characters except _-.$/~"'@:+?.

    • Priority: The priority level of the listener rule, between 1 and 19999 both included. Each rule must have a unique priority level. Otherwise, an error is returned.

  • VmIds: The IDs of the backend VMs.

The CreateListenerRule command returns the following elements:

  • ListenerRule: Information about the listener rule.

    • Action: The type of action for the rule (always forward).

    • HostNamePattern: A host-name pattern for the rule, with a maximum length of 128 characters. This host-name pattern supports maximum three wildcards, and must not contain any special characters except -.?.

    • ListenerId: The ID of the listener.

    • ListenerRuleId: The ID of the listener rule.

    • ListenerRuleName: A human-readable name for the listener rule.

    • PathPattern: A path pattern for the rule, with a maximum length of 128 characters. This path pattern supports maximum three wildcards, and must not contain any special characters except _-.$/~"'@:+?.

    • Priority: The priority level of the listener rule, between 1 and 19999 both included. Each rule must have a unique priority level. Otherwise, an error is returned.

    • VmIds: The IDs of the backend VMs.

  • ResponseContext: Information about the context of the response.

    • RequestId: The ID of the request.

Result sample: Creating a listener rule based on a host pattern
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "ListenerRule": {
    "Priority": 10,
    "VmIds": [
      "i-12345678"
    ],
    "ListenerRuleName": "example-listener-rule",
    "Action": "forward",
    "ListenerId": 123456,
    "HostNamePattern": "*.example.com",
    "ListenerRuleId": 1234
  }
}
Result sample: Creating a listener rule based on a path pattern
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "ListenerRule": {
    "Priority": 100,
    "VmIds": [
      "i-12345678"
    ],
    "ListenerRuleName": "example-listener-rule",
    "Action": "forward",
    "ListenerId": 123456,
    "PathPattern": "/docs/*",
    "ListenerRuleId": 1234
  }
}

Créer une listener rule avec oapi-cli

À ce jour, cette section est disponible en anglais uniquement.

The CreateListenerRule command creates a rule for traffic redirection for the specified listener. Each rule must have either the HostNamePattern or PathPattern parameter specified. Rules are treated in priority order, from the highest value to the lowest value.
Once the rule is created, you need to register backend VMs with it. For more information, see the RegisterVmsInLoadBalancer method.

For more information, see About Load Balancers.

Request sample: Creating a listener rule based on a host pattern
$ oapi-cli --profile "default" CreateListenerRule \
    --Listener '{
        "LoadBalancerName": "example-lbu",
        "LoadBalancerPort": 80
      }' \
    --ListenerRule '{
        "Action": "forward",
        "HostNamePattern": "*.example.com",
        "ListenerRuleName": "example-listener-rule",
        "Priority": 10
      }' \
    --VmIds '["i-12345678"]'
Request sample: Creating a listener rule based on a path pattern
$ oapi-cli --profile "default" CreateListenerRule \
    --Listener '{
        "LoadBalancerName": "example-lbu",
        "LoadBalancerPort": 80
      }' \
    --ListenerRule '{
        "Action": "forward",
        "PathPattern": "/docs/*",
        "ListenerRuleName": "example-listener-rule",
        "Priority": 100
      }' \
    --VmIds '["i-12345678"]'

This command contains the following attributes that you need to specify:

  • DryRun: (optional) If true, checks whether you have the required permissions to perform the action.

  • Listener: Information about the load balancer.

    • LoadBalancerName: The name of the load balancer to which the listener is attached.

    • LoadBalancerPort: The port of load balancer on which the load balancer is listening (between 1 and 65535 both included).

  • ListenerRule: Information about the listener rule.

    • Action: (optional) The type of action for the rule (always forward).

    • HostNamePattern: (optional) A host-name pattern for the rule, with a maximum length of 128 characters. This host-name pattern supports maximum three wildcards, and must not contain any special characters except -.?.

    • ListenerRuleName: A human-readable name for the listener rule.

    • PathPattern: (optional) A path pattern for the rule, with a maximum length of 128 characters. This path pattern supports maximum three wildcards, and must not contain any special characters except _-.$/~"'@:+?.

    • Priority: The priority level of the listener rule, between 1 and 19999 both included. Each rule must have a unique priority level. Otherwise, an error is returned.

  • VmIds: The IDs of the backend VMs.

The CreateListenerRule command returns the following elements:

  • ListenerRule: Information about the listener rule.

    • Action: The type of action for the rule (always forward).

    • HostNamePattern: A host-name pattern for the rule, with a maximum length of 128 characters. This host-name pattern supports maximum three wildcards, and must not contain any special characters except -.?.

    • ListenerId: The ID of the listener.

    • ListenerRuleId: The ID of the listener rule.

    • ListenerRuleName: A human-readable name for the listener rule.

    • PathPattern: A path pattern for the rule, with a maximum length of 128 characters. This path pattern supports maximum three wildcards, and must not contain any special characters except _-.$/~"'@:+?.

    • Priority: The priority level of the listener rule, between 1 and 19999 both included. Each rule must have a unique priority level. Otherwise, an error is returned.

    • VmIds: The IDs of the backend VMs.

  • ResponseContext: Information about the context of the response.

    • RequestId: The ID of the request.

Result sample: Creating a listener rule based on a host pattern
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "ListenerRule": {
    "Priority": 10,
    "VmIds": [
      "i-12345678"
    ],
    "ListenerRuleName": "example-listener-rule",
    "Action": "forward",
    "ListenerId": 123456,
    "HostNamePattern": "*.example.com",
    "ListenerRuleId": 1234
  }
}
Result sample: Creating a listener rule based on a path pattern
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "ListenerRule": {
    "Priority": 100,
    "VmIds": [
      "i-12345678"
    ],
    "ListenerRuleName": "example-listener-rule",
    "Action": "forward",
    "ListenerId": 123456,
    "PathPattern": "/docs/*",
    "ListenerRuleId": 1234
  }
}

Pages connexes

Méthodes API correspondantes