|
21 | 21 | use OpenCloud\DNS\Resource\HasPtrRecordsInterface;
|
22 | 22 | use OpenCloud\Image\Resource\ImageInterface;
|
23 | 23 | use OpenCloud\Networking\Resource\NetworkInterface;
|
| 24 | +use OpenCloud\Networking\Resource\SecurityGroup; |
24 | 25 | use OpenCloud\Networking\Resource\Port;
|
25 | 26 | use OpenCloud\Volume\Resource\Volume;
|
26 | 27 | use OpenCloud\Common\Exceptions;
|
@@ -104,6 +105,12 @@ class Server extends NovaResource implements HasPtrRecordsInterface
|
104 | 105 | */
|
105 | 106 | public $networks = array();
|
106 | 107 |
|
| 108 | + /** |
| 109 | + * Security groups for this server. An array of either the names or SecurityGroup objects. |
| 110 | + * @var (string|SecurityGroup)[] |
| 111 | + */ |
| 112 | + public $security_groups = array(); |
| 113 | + |
107 | 114 | /**
|
108 | 115 | * @var string The server ID.
|
109 | 116 | */
|
@@ -705,6 +712,27 @@ protected function createJson()
|
705 | 712 | }
|
706 | 713 | }
|
707 | 714 |
|
| 715 | + // Security groups |
| 716 | + if (is_array($this->security_groups) && count($this->security_groups)) { |
| 717 | + $server->security_groups = array(); |
| 718 | + |
| 719 | + foreach ($this->security_groups as $security_group) { |
| 720 | + if ($security_group instanceof SecurityGroup) { |
| 721 | + $securityGroupName = $security_group->name(); |
| 722 | + } elseif (is_string($security_group)) { |
| 723 | + $securityGroupName = $security_group; |
| 724 | + } else { |
| 725 | + throw new Exceptions\InvalidParameterError(sprintf( |
| 726 | + 'When creating a server, the "security_groups" key must be an ' . |
| 727 | + 'array of strings or objects of type OpenCloud\Networking\Resource\SecurityGroup;' . |
| 728 | + 'variable passed in was a [%s]', |
| 729 | + gettype($security_group) |
| 730 | + )); |
| 731 | + } |
| 732 | + $server->security_groups[] = (object) array('name' => $securityGroupName); |
| 733 | + } |
| 734 | + } |
| 735 | + |
708 | 736 | // Personality files
|
709 | 737 | if (!empty($this->personality)) {
|
710 | 738 | $server->personality = array();
|
|
0 commit comments