Skip to content

Commit a0ec998

Browse files
author
Jamie Hannaford
committed
Merge pull request #551 from ycombinator/neutron-sg
[WIP] Neutron Security Groups + Security Group Rules
2 parents 2873570 + fbf4074 commit a0ec998

File tree

17 files changed

+841
-21
lines changed

17 files changed

+841
-21
lines changed

docs/userguide/Networking/USERGUIDE.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ these entities.
3333
* [Get a port](#get-a-port)
3434
* [Update a port](#update-a-port)
3535
* [Delete a port](#delete-a-port)
36+
* [Security Groups](#security-groups)
37+
* [Create a security group](#create-a-security-group)
38+
* [List security groups](#list-security-groups)
39+
* [Get a security group](#get-a-security-group)
40+
* [Delete a security group](#delete-a-security-group)
41+
* [Security group rule Rules](#security-group-rules)
42+
* [Create a security group rule](#create-a-security-group-rule)
43+
* [List security group rules](#list-security-group-rules)
44+
* [Get a security group rule](#get-a-security-group-rule)
45+
* [Delete a security group rule](#delete-a-security-group-rule)
3646

3747
## Concepts
3848

@@ -55,6 +65,10 @@ be assigned to the interfaces plugged into them. When IP addresses are
5565
associated with a port, this also implies the port is associated with a subnet
5666
because the IP address is taken from the allocation pool for a specific subnet.
5767

68+
* **Security Group**: A named container for security group rules.
69+
70+
* **Security Group Rule**: Provide users the ability to specify the types of traffic that are allowed to pass through to and from ports on a virtual server instance.
71+
5872
## Prerequisites
5973

6074
### Client
@@ -468,3 +482,136 @@ $port->delete();
468482
```
469483

470484
[ [Get the executable PHP script for this example](/samples/Networking/delete-port.php) ]
485+
486+
## Security Groups
487+
488+
A security group is a named container for [security group rules](#security-group-rules).
489+
490+
### Create a security group
491+
492+
This operation takes one parameter, an associative array, with the following keys:
493+
494+
| Name | Description | Data type | Required? | Default value | Example value |
495+
| ---- | ----------- | --------- | --------- | ------------- | ------------- |
496+
| `name` | A human-readable name for the security group. This name might not be unique. | String | Yes | - | `new-webservers` |
497+
| `description` | Description of the security group. | String | No | `null` | `security group for webservers` |
498+
499+
You can create a security group as shown in the following example:
500+
501+
```php
502+
$securityGroup = $networkingService->createSecurityGroup(array(
503+
'name' => 'new-webservers',
504+
'description' => 'security group for webservers'
505+
));
506+
/** @var $securityGroup OpenCloud\Networking\Resource\SecurityGroup **/
507+
```
508+
509+
[ [Get the executable PHP script for this example](/samples/Networking/create-security-group.php) ]
510+
511+
### List security groups
512+
513+
You can list all the security groups to which you have access as shown in the following
514+
example:
515+
516+
```php
517+
$securityGroups = $networkingService->listSecurityGroups();
518+
foreach ($securityGroups as $securityGroup) {
519+
/** @var $securityGroup OpenCloud\Networking\Resource\SecurityGroup **/
520+
}
521+
```
522+
523+
[ [Get the executable PHP script for this example](/samples/Networking/list-security-groups.php) ]
524+
525+
### Get a security group
526+
527+
You can retrieve a specific security group by using that security group's ID, as shown in the
528+
following example:
529+
530+
```php
531+
$securityGroup = $networkingService->getSecurityGroup('2076db17-a522-4506-91de-c6dd8e837028');
532+
/** @var $securityGroup OpenCloud\Networking\Resource\SecurityGroup **/
533+
```
534+
535+
[ [Get the executable PHP script for this example](/samples/Networking/get-security-group.php) ]
536+
537+
### Delete a security group
538+
539+
You can delete a security group as shown in the following example:
540+
541+
```php
542+
$securityGroup->delete();
543+
```
544+
545+
[ [Get the executable PHP script for this example](/samples/Networking/delete-security-group.php) ]
546+
547+
## Security Group Rules
548+
549+
A security group rule provides users the ability to specify the types of traffic that are allowed to pass through to and from ports on a virtual server instance.
550+
551+
### Create a security group rule
552+
553+
This operation takes one parameter, an associative array, with the following keys:
554+
555+
| Name | Description | Data type | Required? | Default value | Example value |
556+
| ---- | ----------- | --------- | --------- | ------------- | ------------- |
557+
| `securityGroupId` | The security group ID to associate with this security group rule. | String | Yes | - | `2076db17-a522-4506-91de-c6dd8e837028` |
558+
| `direction` | The direction in which the security group rule is applied. For a compute instance, an ingress security group rule is applied to incoming (ingress) traffic for that instance. An egress rule is applied to traffic leaving the instance. | String (`ingress` or `egress`) | Yes | - | `ingress` |
559+
| `ethertype` | Must be IPv4 or IPv6, and addresses represented in CIDR must match the ingress or egress rules. | String (`IPv4` or `IPv6`) | No | `IPv4` | `IPv6` |
560+
| `portRangeMin` | The minimum port number in the range that is matched by the security group rule. If the protocol is TCP or UDP, this value must be less than or equal to the value of the `portRangeMax` attribute. If the protocol is ICMP, this value must be an ICMP type. | Integer | No | `null` | `80` |
561+
| `portRangeMax` | The maximum port number in the range that is matched by the security group rule. The port_range_min attribute constrains the attribute. If the protocol is ICMP, this value must be an ICMP type. | Integer | No | `null` | `80` |
562+
| `protocol` | The protocol that is matched by the security group rule. | String (`tcp`, `udp`, `icmp`) | No | `null` | `tcp` |
563+
| `remoteGroupId` | The remote group ID to be associated with this security group rule. You can specify either `remoteGroupId` or `remoteGroupPrefix`. | String | Optional | `null` | `85cc3048-abc3-43cc-89b3-377341426ac5` |
564+
| `remoteIpPrefix` | The remote IP prefix to be associated with this security group rule. You can specify either `remoteGroupId` or `remoteGroupPrefix`. | String | Optional | `null` | `192.168.5.0` |
565+
566+
You can create a security group rule as shown in the following example:
567+
568+
```php
569+
$securityGroupRule = $networkingService->createSecurityGroupRule(array(
570+
'securityGroupId' => '2076db17-a522-4506-91de-c6dd8e837028',
571+
'direction' => 'egress',
572+
'ethertype' => 'IPv4',
573+
'portRangeMin' => 80,
574+
'portRangeMax' => 80,
575+
'protocol' => 'tcp',
576+
'remoteGroupId' => '85cc3048-abc3-43cc-89b3-377341426ac5'
577+
));
578+
/** @var $securityGroupRule OpenCloud\Networking\Resource\SecurityGroupRule **/
579+
```
580+
581+
[ [Get the executable PHP script for this example](/samples/Networking/create-security-group-rule.php) ]
582+
583+
### List security group rules
584+
585+
You can list all the security group rules to which you have access as shown in the following
586+
example:
587+
588+
```php
589+
$securityGroupRules = $networkingService->listSecurityGroupRules();
590+
foreach ($securityGroupRules as $securityGroupRule) {
591+
/** @var $securityGroupRule OpenCloud\Networking\Resource\SecurityGroupRule **/
592+
}
593+
```
594+
595+
[ [Get the executable PHP script for this example](/samples/Networking/list-security-group-rules.php) ]
596+
597+
### Get a security group rule
598+
599+
You can retrieve a specific security group rule by using that security group rule's ID, as shown in the
600+
following example:
601+
602+
```php
603+
$securityGroupRule = $networkingService->getSecurityGroupRule('');
604+
/** @var $securityGroupRule OpenCloud\Networking\Resource\SecurityGroupRule **/
605+
```
606+
607+
[ [Get the executable PHP script for this example](/samples/Networking/get-security-group-rule.php) ]
608+
609+
### Delete a security group rule
610+
611+
You can delete a security group rule as shown in the following example:
612+
613+
```php
614+
$securityGroupRule->delete();
615+
```
616+
617+
[ [Get the executable PHP script for this example](/samples/Networking/delete-security-group-rule.php) ]

lib/OpenCloud/Networking/Resource/Network.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ class Network extends PersistentResource implements NetworkInterface
5757
);
5858

5959
protected $updateKeys = array(
60-
'adminStateUp',
61-
'name',
62-
'shared'
60+
'name'
6361
);
6462

6563
/**

lib/OpenCloud/Networking/Resource/Port.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ class Port extends PersistentResource
7878

7979
protected $updateKeys = array(
8080
'name',
81-
'adminStateUp',
82-
'deviceId',
83-
'deviceOwner',
84-
'fixedIps',
85-
'securityGroups'
81+
'deviceId'
8682
);
8783

8884
/**
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright 2012-2014 Rackspace US, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace OpenCloud\Networking\Resource;
19+
20+
use OpenCloud\Common\Resource\PersistentResource;
21+
22+
/**
23+
* A security group is a named container for security group rules, each of which is
24+
* represented by {@see \OpenCloud\Networking\Resource\SecurityGroupRule}.
25+
*
26+
* @see http://developer.openstack.org/api-ref-networking-v2.html#security_groups
27+
*
28+
* @package OpenCloud\Networking\Resource
29+
*/
30+
class SecurityGroup extends PersistentResource
31+
{
32+
protected static $url_resource = 'security-groups';
33+
protected static $json_name = 'security_group';
34+
35+
protected $id;
36+
protected $name;
37+
protected $description;
38+
protected $securityGroupRules;
39+
protected $tenantId;
40+
protected $links;
41+
42+
protected $aliases = array(
43+
'security_group_rules' => 'securityGroupRules',
44+
'tenant_id' => 'tenantId'
45+
);
46+
47+
protected $createKeys = array(
48+
'name',
49+
'description'
50+
);
51+
52+
/**
53+
* This method is inherited. The inherited method has protected scope
54+
* but we are widening the scope to public so this method may be called
55+
* from other classes such as {@see OpenCloud\Networking\Service}.
56+
*/
57+
public function createJson()
58+
{
59+
return parent::createJson();
60+
}
61+
62+
/**
63+
* {@inheritDoc}
64+
*/
65+
public function update($params = array())
66+
{
67+
return $this->noUpdate();
68+
}
69+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/**
3+
* Copyright 2012-2014 Rackspace US, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace OpenCloud\Networking\Resource;
19+
20+
use OpenCloud\Common\Resource\PersistentResource;
21+
22+
/**
23+
*
24+
* Security group rules provide users the ability to specify the types of traffic that are allowed
25+
* to pass through to and from ports (represented by {@see \OpenCloud\Networking\Resource\Port})
26+
* on a virtual server instance.
27+
*
28+
* @see http://developer.openstack.org/api-ref-networking-v2.html#security_groups
29+
*
30+
* @package OpenCloud\Networking\Resource
31+
*/
32+
class SecurityGroupRule extends PersistentResource
33+
{
34+
protected static $url_resource = 'security-group-rules';
35+
protected static $json_name = 'security_group_rule';
36+
37+
protected $id;
38+
protected $direction;
39+
protected $ethertype;
40+
protected $portRangeMin;
41+
protected $portRangeMax;
42+
protected $protocol;
43+
protected $remoteGroupId;
44+
protected $remoteIpPrefix;
45+
protected $securityGroupId;
46+
protected $tenantId;
47+
protected $links;
48+
49+
protected $aliases = array(
50+
'port_range_min' => 'portRangeMin',
51+
'port_range_max' => 'portRangeMax',
52+
'remote_group_id' => 'remoteGroupId',
53+
'remote_ip_prefix' => 'remoteIpPrefix',
54+
'security_group_id' => 'securityGroupId',
55+
'tenant_id' => 'tenantId'
56+
);
57+
58+
protected $createKeys = array(
59+
'direction',
60+
'ethertype',
61+
'securityGroupId',
62+
'portRangeMin',
63+
'portRangeMax',
64+
'protocol',
65+
'remoteGroupId',
66+
'remoteIpPrefix'
67+
);
68+
69+
/**
70+
* This method is inherited. The inherited method has protected scope
71+
* but we are widening the scope to public so this method may be called
72+
* from other classes such as {@see OpenCloud\Networking\Service}.
73+
*/
74+
public function createJson()
75+
{
76+
return parent::createJson();
77+
}
78+
79+
/**
80+
* {@inheritDoc}
81+
*/
82+
public function update($params = array())
83+
{
84+
return $this->noUpdate();
85+
}
86+
}

0 commit comments

Comments
 (0)