Creating a Listener Rule
You can create a listener rule to manage redirection of incoming traffic between a load balancer and its backend virtual machines (VMs).
This action creates a pattern associated with a specified listener, based on a path in the URI of the request. Listener rules are treated in priority order, from the highest value to the lowest value.
Once the listener rule is created, you need to register one or more target backends with it. For more information, see Registering VMs with a Listener Rule.
To modify the pattern of an existing rule, see Modifying a Listener Rule. To display the pattern and list of VMs registered with a rule, see Getting Information About Your Listener Rules.
Creating a Listener Rule Using OSC CLI
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.
$ 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"]'
$ 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. -
ListenerRule
: Information about the listener rule. -
VmIds
: The IDs of the backend VMs.
The CreateListenerRule command returns the following elements:
-
ListenerRule
: Information about the listener rule. -
ResponseContext
: Information about the context of the response.
{
"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
}
}
{
"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
}
}
Related Pages
Corresponding API Methods