From cfc126b86400f6853a3eb255d03cb885c7df3569 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Sat, 1 Nov 2014 10:38:16 -0700 Subject: [PATCH 01/32] Adding initial version of code samples for networking. --- samples/Networking/create-network.php | 44 +++++++++++++++++++ samples/Networking/create-networks.php | 52 ++++++++++++++++++++++ samples/Networking/create-port.php | 48 +++++++++++++++++++++ samples/Networking/create-ports.php | 56 ++++++++++++++++++++++++ samples/Networking/create-subnet.php | 50 +++++++++++++++++++++ samples/Networking/create-subnets.php | 60 ++++++++++++++++++++++++++ samples/Networking/delete-network.php | 45 +++++++++++++++++++ samples/Networking/delete-port.php | 45 +++++++++++++++++++ samples/Networking/delete-subnet.php | 45 +++++++++++++++++++ samples/Networking/get-network.php | 43 ++++++++++++++++++ samples/Networking/get-port.php | 43 ++++++++++++++++++ samples/Networking/get-subnet.php | 43 ++++++++++++++++++ samples/Networking/list-networks.php | 44 +++++++++++++++++++ samples/Networking/list-ports.php | 44 +++++++++++++++++++ samples/Networking/list-subnets.php | 44 +++++++++++++++++++ samples/Networking/update-network.php | 47 ++++++++++++++++++++ samples/Networking/update-port.php | 47 ++++++++++++++++++++ samples/Networking/update-subnet.php | 47 ++++++++++++++++++++ 18 files changed, 847 insertions(+) create mode 100644 samples/Networking/create-network.php create mode 100644 samples/Networking/create-networks.php create mode 100644 samples/Networking/create-port.php create mode 100644 samples/Networking/create-ports.php create mode 100644 samples/Networking/create-subnet.php create mode 100644 samples/Networking/create-subnets.php create mode 100644 samples/Networking/delete-network.php create mode 100644 samples/Networking/delete-port.php create mode 100644 samples/Networking/delete-subnet.php create mode 100644 samples/Networking/get-network.php create mode 100644 samples/Networking/get-port.php create mode 100644 samples/Networking/get-subnet.php create mode 100644 samples/Networking/list-networks.php create mode 100644 samples/Networking/list-ports.php create mode 100644 samples/Networking/list-subnets.php create mode 100644 samples/Networking/update-network.php create mode 100644 samples/Networking/update-port.php create mode 100644 samples/Networking/update-subnet.php diff --git a/samples/Networking/create-network.php b/samples/Networking/create-network.php new file mode 100644 index 000000000..b5dc0a931 --- /dev/null +++ b/samples/Networking/create-network.php @@ -0,0 +1,44 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Create a network. +$network = $networkingService->createNetwork(array( + 'name' => 'My virtual private network' +)); +/** @var $network OpenCloud\Networking\Resource\Network **/ diff --git a/samples/Networking/create-networks.php b/samples/Networking/create-networks.php new file mode 100644 index 000000000..f452db2ee --- /dev/null +++ b/samples/Networking/create-networks.php @@ -0,0 +1,52 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Create multiple networks. +$networks = $networkingService->createNetworks(array( + array( + 'name' => 'My virtual private network #1' + ), + array( + 'name' => 'My virtual private network #2' + ) +)); + +foreach ($networks as $network) { + /** @var $network OpenCloud\Networking\Resource\Network **/ +} diff --git a/samples/Networking/create-port.php b/samples/Networking/create-port.php new file mode 100644 index 000000000..97ee8bc2c --- /dev/null +++ b/samples/Networking/create-port.php @@ -0,0 +1,48 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get network. +$network = $networkingService->getNetwork(getenv('NETWORK_ID')); + +// 4. Create a port. +$port = $networkingService->createPort(array( + 'name' => 'My port' +)); +/** @var $port OpenCloud\Networking\Resource\Port **/ diff --git a/samples/Networking/create-ports.php b/samples/Networking/create-ports.php new file mode 100644 index 000000000..4f6165830 --- /dev/null +++ b/samples/Networking/create-ports.php @@ -0,0 +1,56 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get network. +$network = $networkingService->getNetwork(getenv('NETWORK_ID')); + +// 4. Create multiple ports. +$ports = $network->createPorts(array( + array( + 'name' => 'My port #1' + ), + array( + 'name' => 'My port #2' + ) +)); + +foreach ($ports as $port) { + /** @var $port OpenCloud\Networking\Resource\Port **/ +} diff --git a/samples/Networking/create-subnet.php b/samples/Networking/create-subnet.php new file mode 100644 index 000000000..ac8fba9b3 --- /dev/null +++ b/samples/Networking/create-subnet.php @@ -0,0 +1,50 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get network. +$network = $networkingService->getNetwork(getenv('NETWORK_ID')); + +// 4. Create a subnet. +$subnet = $networkingService->createSubnet(array( + 'name' => 'My subnet', + 'ip_version' => 4, + 'cidr' => '192.168.199.0/24' +)); +/** @var $subnet OpenCloud\Networking\Resource\Subnet **/ diff --git a/samples/Networking/create-subnets.php b/samples/Networking/create-subnets.php new file mode 100644 index 000000000..eeb5c962d --- /dev/null +++ b/samples/Networking/create-subnets.php @@ -0,0 +1,60 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get network. +$network = $networkingService->getNetwork(getenv('NETWORK_ID')); + +// 4. Create multiple subnets. +$subnets = $network->createSubnets(array( + array( + 'name' => 'My subnet #1', + 'ip_version' => 4, + 'cidr' => '192.168.199.0/24' + ), + array( + 'name' => 'My subnet #2', + 'ip_version' => 4, + 'cidr' => '10.56.4.0/22' + ) +)); + +foreach ($subnets as $subnet) { + /** @var $subnet OpenCloud\Networking\Resource\Subnet **/ +} diff --git a/samples/Networking/delete-network.php b/samples/Networking/delete-network.php new file mode 100644 index 000000000..88b7b8a38 --- /dev/null +++ b/samples/Networking/delete-network.php @@ -0,0 +1,45 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get network. +$network = $networkingService->getNetwork(getenv('NETWORK_ID')); + +// 4. Delete network. +$network->delete(); diff --git a/samples/Networking/delete-port.php b/samples/Networking/delete-port.php new file mode 100644 index 000000000..1f840b02e --- /dev/null +++ b/samples/Networking/delete-port.php @@ -0,0 +1,45 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get port. +$port = $networkingService->getPort(getenv('PORT_ID')); + +// 4. Delete port. +$port->delete(); diff --git a/samples/Networking/delete-subnet.php b/samples/Networking/delete-subnet.php new file mode 100644 index 000000000..0e8dfa5dc --- /dev/null +++ b/samples/Networking/delete-subnet.php @@ -0,0 +1,45 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get subnet. +$subnet = $networkingService->getSubnet(getenv('SUBNET_ID')); + +// 4. Delete subnet. +$subnet->delete(); diff --git a/samples/Networking/get-network.php b/samples/Networking/get-network.php new file mode 100644 index 000000000..f9cb456ce --- /dev/null +++ b/samples/Networking/get-network.php @@ -0,0 +1,43 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get network. +$network = $networkingService->getNetwork(getenv('NETWORK_ID')); +/** @var $network OpenCloud\Networking\Resource\Network **/ diff --git a/samples/Networking/get-port.php b/samples/Networking/get-port.php new file mode 100644 index 000000000..33749a2be --- /dev/null +++ b/samples/Networking/get-port.php @@ -0,0 +1,43 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get port. +$port = $networkingService->getPort(getenv('PORT_ID')); +/** @var $port OpenCloud\Networking\Resource\Port **/ diff --git a/samples/Networking/get-subnet.php b/samples/Networking/get-subnet.php new file mode 100644 index 000000000..7397d9226 --- /dev/null +++ b/samples/Networking/get-subnet.php @@ -0,0 +1,43 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get subnet. +$subnet = $networkingService->getSubnet(getenv('SUBNET_ID')); +/** @var $subnet OpenCloud\Networking\Resource\Subnet **/ diff --git a/samples/Networking/list-networks.php b/samples/Networking/list-networks.php new file mode 100644 index 000000000..e1d3abb87 --- /dev/null +++ b/samples/Networking/list-networks.php @@ -0,0 +1,44 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. List networks +$networks = $networkingService->listNetworks(); +foreach ($networks as $network) { + /** @var $network OpenCloud\Networking\Resource\Network **/ +} diff --git a/samples/Networking/list-ports.php b/samples/Networking/list-ports.php new file mode 100644 index 000000000..5ddbe7e4f --- /dev/null +++ b/samples/Networking/list-ports.php @@ -0,0 +1,44 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. List ports +$ports = $networkingService->listPorts(); +foreach ($ports as $port) { + /** @var $port OpenCloud\Networking\Resource\Port **/ +} diff --git a/samples/Networking/list-subnets.php b/samples/Networking/list-subnets.php new file mode 100644 index 000000000..c926d5e71 --- /dev/null +++ b/samples/Networking/list-subnets.php @@ -0,0 +1,44 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. List subnets +$subnets = $networkingService->listSubnets(); +foreach ($subnets as $subnet) { + /** @var $subnet OpenCloud\Networking\Resource\Subnet **/ +} diff --git a/samples/Networking/update-network.php b/samples/Networking/update-network.php new file mode 100644 index 000000000..7650be384 --- /dev/null +++ b/samples/Networking/update-network.php @@ -0,0 +1,47 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get network. +$network = $networkingService->getNetwork(getenv('NETWORK_ID')); + +// 4. Update network. +$network->update(array( + 'name' => 'My updated virtual private network' +)); diff --git a/samples/Networking/update-port.php b/samples/Networking/update-port.php new file mode 100644 index 000000000..b4c4db186 --- /dev/null +++ b/samples/Networking/update-port.php @@ -0,0 +1,47 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get port. +$port = $networkingService->getPort(getenv('PORT_ID')); + +// 4. Update port. +$port->update(array( + 'name' => 'My updated port' +)); diff --git a/samples/Networking/update-subnet.php b/samples/Networking/update-subnet.php new file mode 100644 index 000000000..46f8b5d1a --- /dev/null +++ b/samples/Networking/update-subnet.php @@ -0,0 +1,47 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Get subnet. +$subnet = $networkingService->getSubnet(getenv('SUBNET_ID')); + +// 4. Update subnet. +$subnet->update(array( + 'name' => 'My updated subnet' +)); From d77430ad287e2253f445193d596cf008af14c250 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 3 Nov 2014 15:40:40 -0800 Subject: [PATCH 02/32] Create ports and subnets from service object. --- samples/Networking/create-port.php | 8 +++----- samples/Networking/create-ports.php | 18 +++++++++--------- samples/Networking/create-subnet.php | 8 +++----- samples/Networking/create-subnets.php | 18 +++++++++--------- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/samples/Networking/create-port.php b/samples/Networking/create-port.php index 97ee8bc2c..753211bde 100644 --- a/samples/Networking/create-port.php +++ b/samples/Networking/create-port.php @@ -38,11 +38,9 @@ $region = getenv('OS_REGION_NAME'); $networkingService = $client->networkingService(null, $region); -// 3. Get network. -$network = $networkingService->getNetwork(getenv('NETWORK_ID')); - -// 4. Create a port. +// 3. Create a port. $port = $networkingService->createPort(array( - 'name' => 'My port' + 'name' => 'My port', + 'networkId' => getenv('NETWORK_ID') )); /** @var $port OpenCloud\Networking\Resource\Port **/ diff --git a/samples/Networking/create-ports.php b/samples/Networking/create-ports.php index 4f6165830..00ec0228a 100644 --- a/samples/Networking/create-ports.php +++ b/samples/Networking/create-ports.php @@ -21,8 +21,9 @@ // * OS_AUTH_URL: Your OpenStack Cloud Authentication URL, // * OS_USERNAME: Your OpenStack Cloud Account Username, // * OS_PASSWORD: Your OpenStack Cloud Account Password, -// * OS_REGION_NAME: The OpenStack Cloud region you want to use, and -// * NETWORK_ID: ID of network in which to create ports +// * OS_REGION_NAME: The OpenStack Cloud region you want to use, +// * NETWORK_ID_1: ID of network in which to create port 1, and +// * NETWORK_ID_2: ID of network in which to create port 2 // require __DIR__ . '/../../vendor/autoload.php'; @@ -38,16 +39,15 @@ $region = getenv('OS_REGION_NAME'); $networkingService = $client->networkingService(null, $region); -// 3. Get network. -$network = $networkingService->getNetwork(getenv('NETWORK_ID')); - -// 4. Create multiple ports. -$ports = $network->createPorts(array( +// 3. Create multiple ports. +$ports = $networkingService->createPorts(array( array( - 'name' => 'My port #1' + 'name' => 'My port #1', + 'networkId' => getenv('NETWORK_ID_1') ), array( - 'name' => 'My port #2' + 'name' => 'My port #2', + 'networkId' => getenv('NETWORK_ID_2') ) )); diff --git a/samples/Networking/create-subnet.php b/samples/Networking/create-subnet.php index ac8fba9b3..2bd94c561 100644 --- a/samples/Networking/create-subnet.php +++ b/samples/Networking/create-subnet.php @@ -38,13 +38,11 @@ $region = getenv('OS_REGION_NAME'); $networkingService = $client->networkingService(null, $region); -// 3. Get network. -$network = $networkingService->getNetwork(getenv('NETWORK_ID')); - -// 4. Create a subnet. +// 3. Create a subnet. $subnet = $networkingService->createSubnet(array( 'name' => 'My subnet', - 'ip_version' => 4, + 'networkId' => getenv('NETWORK_ID'), + 'ipVersion' => 4, 'cidr' => '192.168.199.0/24' )); /** @var $subnet OpenCloud\Networking\Resource\Subnet **/ diff --git a/samples/Networking/create-subnets.php b/samples/Networking/create-subnets.php index eeb5c962d..0c74167de 100644 --- a/samples/Networking/create-subnets.php +++ b/samples/Networking/create-subnets.php @@ -21,8 +21,9 @@ // * OS_AUTH_URL: Your OpenStack Cloud Authentication URL, // * OS_USERNAME: Your OpenStack Cloud Account Username, // * OS_PASSWORD: Your OpenStack Cloud Account Password, -// * OS_REGION_NAME: The OpenStack Cloud region you want to use, and -// * NETWORK_ID: ID of network in which to create subnets +// * OS_REGION_NAME: The OpenStack Cloud region you want to use, +// * NETWORK_ID_1: ID of network in which to create port 1, and +// * NETWORK_ID_2: ID of network in which to create port 2 // require __DIR__ . '/../../vendor/autoload.php'; @@ -38,19 +39,18 @@ $region = getenv('OS_REGION_NAME'); $networkingService = $client->networkingService(null, $region); -// 3. Get network. -$network = $networkingService->getNetwork(getenv('NETWORK_ID')); - -// 4. Create multiple subnets. -$subnets = $network->createSubnets(array( +// 3. Create multiple subnets. +$subnets = $networkingService->createSubnets(array( array( 'name' => 'My subnet #1', - 'ip_version' => 4, + 'networkId' => getenv('NETWORK_ID_1'), + 'ipVersion' => 4, 'cidr' => '192.168.199.0/24' ), array( 'name' => 'My subnet #2', - 'ip_version' => 4, + 'networkId' => getenv('NETWORK_ID_2'), + 'ipVersion' => 4, 'cidr' => '10.56.4.0/22' ) )); From d77a8bf7ac794ff1c15c46b00418625922092dfd Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 4 Nov 2014 15:24:33 -0800 Subject: [PATCH 03/32] First cut at unit tests and implementation. --- lib/OpenCloud/Networking/Resource/Network.php | 60 ++++++ lib/OpenCloud/Networking/Resource/Port.php | 80 ++++++++ lib/OpenCloud/Networking/Resource/Subnet.php | 80 ++++++++ lib/OpenCloud/Networking/Service.php | 194 ++++++++++++++++++ lib/OpenCloud/OpenStack.php | 19 ++ .../Tests/Networking/NetworkingTestCase.php | 51 +++++ .../Tests/Networking/ServiceTest.php | 99 +++++++++ tests/OpenCloud/Tests/_response/Auth.resp | 16 ++ 8 files changed, 599 insertions(+) create mode 100644 lib/OpenCloud/Networking/Resource/Network.php create mode 100644 lib/OpenCloud/Networking/Resource/Port.php create mode 100644 lib/OpenCloud/Networking/Resource/Subnet.php create mode 100644 lib/OpenCloud/Networking/Service.php create mode 100644 tests/OpenCloud/Tests/Networking/NetworkingTestCase.php create mode 100644 tests/OpenCloud/Tests/Networking/ServiceTest.php diff --git a/lib/OpenCloud/Networking/Resource/Network.php b/lib/OpenCloud/Networking/Resource/Network.php new file mode 100644 index 000000000..fd9f621f8 --- /dev/null +++ b/lib/OpenCloud/Networking/Resource/Network.php @@ -0,0 +1,60 @@ + 'adminStateUp', + 'tenant_id' => 'tenantId' + ); + + protected $createKeys = array( + 'adminStateUp', + 'name', + 'shared', + 'tenantId' + ); + + protected $updateKeys = array( + 'adminStateUp', + 'name', + 'shared', + 'tenantId' + ); +} diff --git a/lib/OpenCloud/Networking/Resource/Port.php b/lib/OpenCloud/Networking/Resource/Port.php new file mode 100644 index 000000000..aaf14fd87 --- /dev/null +++ b/lib/OpenCloud/Networking/Resource/Port.php @@ -0,0 +1,80 @@ + 'adminStateUp', + 'network_id' => 'networkId', + 'device_id' => 'deviceId', + 'device_owner' => 'deviceOwner', + 'fixed_ips' => 'fixedIps', + 'mac_address' => 'macAddress', + 'security_groups' => 'securityGroups', + 'tenant_id' => 'tenantId' + ); + + protected $createKeys = array( + 'name', + 'enableDhcp', + 'networkId', + 'allocationPools', + 'hostRoutes', + 'ipVersion', + 'gatewayIp', + 'cidr', + 'tenantId' + ); + + protected $updateKeys = array( + 'name', + 'enableDhcp', + 'networkId', + 'allocationPools', + 'hostRoutes', + 'ipVersion', + 'gatewayIp', + 'cidr', + 'tenantId' + ); +} diff --git a/lib/OpenCloud/Networking/Resource/Subnet.php b/lib/OpenCloud/Networking/Resource/Subnet.php new file mode 100644 index 000000000..ab8c313e4 --- /dev/null +++ b/lib/OpenCloud/Networking/Resource/Subnet.php @@ -0,0 +1,80 @@ + 'enableDhcp', + 'network_id' => 'networkId', + 'dns_nameservers' => 'dnsNameservers', + 'allocation_pools' => 'allocationPools', + 'host_routes' => 'hostRoutes', + 'ip_version' => 'ipVersion', + 'gateway_ip' => 'gatewayIp', + 'tenant_id' => 'tenantId' + ); + + protected $createKeys = array( + 'name', + 'enableDhcp', + 'networkId', + 'allocationPools', + 'hostRoutes', + 'ipVersion', + 'gatewayIp', + 'cidr', + 'tenantId' + ); + + protected $updateKeys = array( + 'name', + 'enableDhcp', + 'networkId', + 'allocationPools', + 'hostRoutes', + 'ipVersion', + 'gatewayIp', + 'cidr', + 'tenantId' + ); +} diff --git a/lib/OpenCloud/Networking/Service.php b/lib/OpenCloud/Networking/Service.php new file mode 100644 index 000000000..f18c4d0f4 --- /dev/null +++ b/lib/OpenCloud/Networking/Service.php @@ -0,0 +1,194 @@ +resource('Network', $id); + } + + /** + * Creates a new Network and returns it. + * + * @param array $params Network creation parameters + * @return Network Object representing created network + */ + public function createNetwork($params = array()) + { + $network = $this->network(); + $network->create($params); + return $network; + } + + /** + * Returns a Network object associated with this Networking service + * + * @param string $id ID of network to retrieve + * @return Network object + */ + public function getNetwork($id) + { + return $this->network($id); + } + + /** + * Returns a list of networks you created + * + * @param array $params + * @return \OpenCloud\Common\Collection\PaginatedIterator + */ + public function listNetworks(array $params = array()) + { + $url = clone $this->getUrl(); + $url->addPath(Network::resourceName())->setQuery($params); + + return $this->resourceList('Network', $url); + } + + /** + * Returns a Subnet object associated with this Networking service + * + * @param string $id ID of subnet to retrieve + * @return Subnet object + */ + public function subnet($id = null) + { + return $this->resource('Subnet', $id); + } + + /** + * Creates a new Subnet and returns it. + * + * @param array $params Subnet creation parameters + * @return Subnet Object representing created subnet + */ + public function createSubnet($params = array()) + { + $subnet = $this->subnet(); + $subnet->create($params); + return $subnet; + } + + /** + * Returns a Subnet object associated with this Networking service + * + * @param string $id ID of subnet to retrieve + * @return Subnet object + */ + public function getSubnet($id) + { + return $this->subnet($id); + } + + /** + * Returns a list of subnets you created + * + * @param array $params + * @return \OpenCloud\Common\Collection\PaginatedIterator + */ + public function listSubnets(array $params = array()) + { + $url = clone $this->getUrl(); + $url->addPath(Subnet::resourceName())->setQuery($params); + + return $this->resourceList('Subnet', $url); + } + + /** + * Returns a Port object associated with this Networking service + * + * @param string $id ID of port to retrieve + * @return Port object + */ + public function port($id = null) + { + return $this->resource('Port', $id); + } + + /** + * Creates a new Port and returns it. + * + * @param array $params Port creation parameters + * @return Port Object representing created port + */ + public function createPort($params = array()) + { + $port = $this->port(); + $port->create($params); + return $port; + } + + /** + * Returns a Port object associated with this Networking service + * + * @param string $id ID of port to retrieve + * @return Port object + */ + public function getPort($id) + { + return $this->port($id); + } + + /** + * Returns a list of ports you created + * + * @param array $params + * @return \OpenCloud\Common\Collection\PaginatedIterator + */ + public function listPorts(array $params = array()) + { + $url = clone $this->getUrl(); + $url->addPath(Port::resourceName())->setQuery($params); + + return $this->resourceList('Port', $url); + } + + /** + * Return namespaces. + * + * @return array + */ + public function namespaces() + { + return array(); + } +} diff --git a/lib/OpenCloud/OpenStack.php b/lib/OpenCloud/OpenStack.php index 0ab054eef..9d4dd3dff 100644 --- a/lib/OpenCloud/OpenStack.php +++ b/lib/OpenCloud/OpenStack.php @@ -545,4 +545,23 @@ public function imageService($name = null, $region = null, $urltype = null) 'urlType' => $urltype )); } + + /** + * Creates a new Networking (Neutron) service object + * + * @param string $name The name of the service as it appears in the Catalog + * @param string $region The region (DFW, IAD, ORD, LON, SYD) + * @param string $urltype The URL type ("publicURL" or "internalURL") + * @return \OpenCloud\Networking\Service + * @codeCoverageIgnore + */ + public function networkingService($name = null, $region = null, $urltype = null) + { + return ServiceBuilder::factory($this, 'OpenCloud\Networking\Service', array( + 'name' => $name, + 'region' => $region, + 'urlType' => $urltype + )); + } + } diff --git a/tests/OpenCloud/Tests/Networking/NetworkingTestCase.php b/tests/OpenCloud/Tests/Networking/NetworkingTestCase.php new file mode 100644 index 000000000..be6b304c4 --- /dev/null +++ b/tests/OpenCloud/Tests/Networking/NetworkingTestCase.php @@ -0,0 +1,51 @@ +service = $this->getClient()->networkingService(); + } + + protected function assertIsService($object) + { + $this->assertInstanceOf('OpenCloud\Networking\Service', $object); + } + + protected function assertIsNetwork($object) + { + $this->assertInstanceOf('OpenCloud\Networking\Resource\Network', $object); + } + + protected function assertIsSubnet($object) + { + $this->assertInstanceOf('OpenCloud\Networking\Resource\Subnet', $object); + } + + protected function assertIsPort($object) + { + $this->assertInstanceOf('OpenCloud\Networking\Resource\Port', $object); + } +} diff --git a/tests/OpenCloud/Tests/Networking/ServiceTest.php b/tests/OpenCloud/Tests/Networking/ServiceTest.php new file mode 100644 index 000000000..85092cb2e --- /dev/null +++ b/tests/OpenCloud/Tests/Networking/ServiceTest.php @@ -0,0 +1,99 @@ +getClient()->networkingService(null, 'IAD'); + $this->assertIsService($service); + } + + public function testCreateNetwork() + { + $this->assertIsNetwork($this->service->createNetwork()); + } + + public function testListNetworks() + { + $this->addMockSubscriber($this->makeResponse('{"networks":[{"admin_state_up":true,"id":"00000000-0000-0000-0000-000000000000","name":"public","shared":true,"status":"ACTIVE","subnets":[],"tenant_id":"rackspace"},{"admin_state_up":true,"id":"11111111-1111-1111-1111-111111111111","name":"private","shared":true,"status":"ACTIVE","subnets":[],"tenant_id":"rackspace"},{"admin_state_up":true,"id":"2993e407-5531-4ca8-9d2a-0d13b5cac904","name":"RackNet","shared":false,"status":"ACTIVE","subnets":["017d8997-70ec-4448-91d9-a8097d6d60f3"],"tenant_id":"123456"}]}')); + + $networks = $this->service->listNetworks(); + $this->isCollection($networks); + $this->assertIsNetwork($networks->getElement(0)); + } + + public function testGetNetwork() + { + $this->addMockSubscriber($this->makeResponse('{"network":{"admin_state_up":true,"id":"4d4e772a-98e7-4409-8a3c-4fed4324da26","name":"sameer-3","shared":false,"status":"ACTIVE","subnets":[],"tenant_id":"546428"}}')); + + $network = $this->service->getNetwork('4d4e772a-98e7-4409-8a3c-4fed4324da26'); + $this->assertIsNetwork($network); + $this->assertEquals('sameer-3', $network->getName()); + } + + public function testCreateSubnet() + { + $this->assertIsSubnet($this->service->createSubnet()); + } + + public function testListSubnets() + { + $this->addMockSubscriber($this->makeResponse('{"subnets":[{"allocation_pools":[{"end":"192.168.9.254","start":"192.168.9.1"}],"cidr":"192.168.9.0/24","dns_nameservers":[],"enable_dhcp":false,"gateway_ip":null,"host_routes":[],"id":"f975defc-637d-4e2a-858b-c6cc4cec3951","ip_version":4,"name":"","network_id":"0ebf6a10-5fc1-4f13-aca9-be0a2a00b1ac","tenant_id":"123456"}]}')); + + $subnets = $this->service->listSubnets(); + $this->isCollection($subnets); + $this->assertIsSubnet($subnets->getElement(0)); + } + + public function testGetSubnet() + { + $this->addMockSubscriber($this->makeResponse('{"subnet":{"name":"my_subnet","enable_dhcp":false,"network_id":"d32019d3-bc6e-4319-9c1d-6722fc136a22","tenant_id":"4fd44f30292945e481c7b8a0c8908869","dns_nameservers":[],"allocation_pools":[{"start":"192.0.0.2","end":"192.255.255.254"}],"host_routes":[],"ip_version":4,"gateway_ip":"192.0.0.1","cidr":"192.0.0.0/8","id":"54d6f61d-db07-451c-9ab3-b9609b6b6f0b"}}')); + + $subnet = $this->service->getSubnet('54d6f61d-db07-451c-9ab3-b9609b6b6f0b'); + $this->assertIsSubnet($subnet); + $this->assertEquals('my_subnet', $subnet->getName()); + } + + public function testCreatePort() + { + $this->assertIsPort($this->service->createPort()); + } + + public function testListPorts() + { + $this->addMockSubscriber($this->makeResponse('{"ports":[{"admin_state_up":true,"device_id":"","device_owner":null,"fixed_ips":[{"ip_address":"192.168.3.11","subnet_id":"739ecc58-f9a0-4145-8a06-cd415e6e5c8d"}],"id":"10ba23f5-bb70-4fd7-a118-83f89b62e340","mac_address":"BE:CB:FE:00:00:EE","name":"port1","network_id":"6406ed30-193a-4958-aae5-7c05268d332b","security_groups":[],"status":"ACTIVE","tenant_id":"123456"}]}')); + + $ports = $this->service->listPorts(); + $this->isCollection($ports); + $this->assertIsPort($ports->getElement(0)); + } + + public function testGetPort() + { + $this->addMockSubscriber($this->makeResponse('{"port":{"admin_state_up":true,"device_id":"","device_owner":null,"fixed_ips":[{"ip_address":"192.168.3.11","subnet_id":"739ecc58-f9a0-4145-8a06-cd415e6e5c8d"}],"id":"10ba23f5-bb70-4fd7-a118-83f89b62e340","mac_address":"BE:CB:FE:00:00:EE","name":"port1","network_id":"6406ed30-193a-4958-aae5-7c05268d332b","security_groups":[],"status":"ACTIVE","tenant_id":"123456"}}')); + + $port = $this->service->getPort('10ba23f5-bb70-4fd7-a118-83f89b62e340'); + $this->assertIsPort($port); + $this->assertEquals('port1', $port->getName()); + } +} diff --git a/tests/OpenCloud/Tests/_response/Auth.resp b/tests/OpenCloud/Tests/_response/Auth.resp index ce1ea5efc..c5c1c146f 100644 --- a/tests/OpenCloud/Tests/_response/Auth.resp +++ b/tests/OpenCloud/Tests/_response/Auth.resp @@ -348,6 +348,22 @@ Front-End-Https: on ], "name": "cloudOrchestration", "type": "orchestration" + }, + { + "name": "cloudNetworks", + "endpoints": [ + { + "region": "IAD", + "tenantId": "123456", + "publicURL": "https://iad.networks.api.rackspacecloud.com/v2.0" + }, + { + "region": "DFW", + "tenantId": "123456", + "publicURL": "https://dfw.networks.api.rackspacecloud.com/v2.0" + } + ], + "type": "networks" } ], "token": { From 9db5e4e4e7dfd8034688f8e9a06c875a7da5ccc3 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 4 Nov 2014 15:31:03 -0800 Subject: [PATCH 04/32] Trivial whitespace lint fixes. --- lib/OpenCloud/OpenStack.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/OpenCloud/OpenStack.php b/lib/OpenCloud/OpenStack.php index 9d4dd3dff..495f31115 100644 --- a/lib/OpenCloud/OpenStack.php +++ b/lib/OpenCloud/OpenStack.php @@ -563,5 +563,4 @@ public function networkingService($name = null, $region = null, $urltype = null) 'urlType' => $urltype )); } - } From 3b9d2d0045b2a701d2d3a328243263189f2642b0 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 5 Nov 2014 06:18:32 -0800 Subject: [PATCH 05/32] Adding unit tests and implementation for bulk creation operations. --- lib/OpenCloud/Networking/Resource/Network.php | 10 ++ lib/OpenCloud/Networking/Resource/Port.php | 10 ++ lib/OpenCloud/Networking/Resource/Subnet.php | 10 ++ lib/OpenCloud/Networking/Service.php | 109 ++++++++++++++++++ .../Tests/Networking/ServiceTest.php | 52 ++++++++- 5 files changed, 190 insertions(+), 1 deletion(-) diff --git a/lib/OpenCloud/Networking/Resource/Network.php b/lib/OpenCloud/Networking/Resource/Network.php index fd9f621f8..934f151bd 100644 --- a/lib/OpenCloud/Networking/Resource/Network.php +++ b/lib/OpenCloud/Networking/Resource/Network.php @@ -57,4 +57,14 @@ class Network extends PersistentResource 'shared', 'tenantId' ); + + /** + * This method is inherited. The inherited method has protected scope + * but we are widening the scope to public so this method may be called + * from other classes such as OpenCloud\Networking\Service. + */ + public function createJson() + { + return parent::createJson(); + } } diff --git a/lib/OpenCloud/Networking/Resource/Port.php b/lib/OpenCloud/Networking/Resource/Port.php index aaf14fd87..77919131d 100644 --- a/lib/OpenCloud/Networking/Resource/Port.php +++ b/lib/OpenCloud/Networking/Resource/Port.php @@ -77,4 +77,14 @@ class Port extends PersistentResource 'cidr', 'tenantId' ); + + /** + * This method is inherited. The inherited method has protected scope + * but we are widening the scope to public so this method may be called + * from other classes such as OpenCloud\Networking\Service. + */ + public function createJson() + { + return parent::createJson(); + } } diff --git a/lib/OpenCloud/Networking/Resource/Subnet.php b/lib/OpenCloud/Networking/Resource/Subnet.php index ab8c313e4..cbbbc9e2e 100644 --- a/lib/OpenCloud/Networking/Resource/Subnet.php +++ b/lib/OpenCloud/Networking/Resource/Subnet.php @@ -77,4 +77,14 @@ class Subnet extends PersistentResource 'cidr', 'tenantId' ); + + /** + * This method is inherited. The inherited method has protected scope + * but we are widening the scope to public so this method may be called + * from other classes such as OpenCloud\Networking\Service. + */ + public function createJson() + { + return parent::createJson(); + } } diff --git a/lib/OpenCloud/Networking/Service.php b/lib/OpenCloud/Networking/Service.php index f18c4d0f4..cac03e122 100644 --- a/lib/OpenCloud/Networking/Service.php +++ b/lib/OpenCloud/Networking/Service.php @@ -18,6 +18,7 @@ namespace OpenCloud\Networking; use OpenCloud\Common\Service\CatalogService; +use OpenCloud\Common\Http\Message\Formatter; use OpenCloud\Networking\Resource\Network; use OpenCloud\Networking\Resource\Subnet; use OpenCloud\Networking\Resource\Port; @@ -59,6 +60,42 @@ public function createNetwork($params = array()) return $network; } + /** + * Creates multiple new Networks and returns their list. + * + * @param array $networksParams Array of network creation parameters' arrays + * @return \OpenCloud\Common\Collection\PaginatedIterator + */ + public function createNetworks($networksParams = array()) + { + // Form URL + $url = clone $this->getUrl(); + $url->addPath(Network::resourceName()); + + // Form JSON + $singleNetworkJsonName = Network::jsonName(); + $networksJsonCollectionName = Network::jsonCollectionName(); + $networks = array(); + foreach ($networksParams as $networkParams) { + $network = $this->network(); + $network->populate($networkParams); + $networks[] = $network->createJson()->$singleNetworkJsonName; + } + $json = json_encode(array( + $networksJsonCollectionName => $networks + )); + + // Call the API + $response = $this->getClient()->post($url, self::getJsonHeader(), $json)->send(); + + // Parse the response into a collection of created networks + $responseJson = Formatter::decode($response); + $createdNetworksJson = $responseJson->$networksJsonCollectionName; + + // Return collection of created networks + return $this->collection('Network', $url, $this, $createdNetworksJson); + } + /** * Returns a Network object associated with this Networking service * @@ -108,6 +145,42 @@ public function createSubnet($params = array()) return $subnet; } + /** + * Creates multiple new Subnets and returns their list. + * + * @param array $subnetsParams Array of subnet creation parameters' arrays + * @return \OpenCloud\Common\Collection\PaginatedIterator + */ + public function createSubnets($subnetsParams = array()) + { + // Form URL + $url = clone $this->getUrl(); + $url->addPath(Subnet::resourceName()); + + // Form JSON + $singleSubnetJsonName = Subnet::jsonName(); + $subnetsJsonCollectionName = Subnet::jsonCollectionName(); + $subnets = array(); + foreach ($subnetsParams as $subnetParams) { + $subnet = $this->subnet(); + $subnet->populate($subnetParams); + $subnets[] = $subnet->createJson()->$singleSubnetJsonName; + } + $json = json_encode(array( + $subnetsJsonCollectionName => $subnets + )); + + // Call the API + $response = $this->getClient()->post($url, self::getJsonHeader(), $json)->send(); + + // Parse the response into a collection of created subnets + $responseJson = Formatter::decode($response); + $createdSubnetsJson = $responseJson->$subnetsJsonCollectionName; + + // Return collection of created subnets + return $this->collection('Subnet', $url, $this, $createdSubnetsJson); + } + /** * Returns a Subnet object associated with this Networking service * @@ -157,6 +230,42 @@ public function createPort($params = array()) return $port; } + /** + * Creates multiple new Ports and returns their list. + * + * @param array $portsParams Array of port creation parameters' arrays + * @return \OpenCloud\Common\Collection\PaginatedIterator + */ + public function createPorts($portsParams = array()) + { + // Form URL + $url = clone $this->getUrl(); + $url->addPath(Port::resourceName()); + + // Form JSON + $singlePortJsonName = Port::jsonName(); + $portsJsonCollectionName = Port::jsonCollectionName(); + $ports = array(); + foreach ($portsParams as $portParams) { + $port = $this->port(); + $port->populate($portParams); + $ports[] = $port->createJson()->$singlePortJsonName; + } + $json = json_encode(array( + $portsJsonCollectionName => $ports + )); + + // Call the API + $response = $this->getClient()->post($url, self::getJsonHeader(), $json)->send(); + + // Parse the response into a collection of created ports + $responseJson = Formatter::decode($response); + $createdPortsJson = $responseJson->$portsJsonCollectionName; + + // Return collection of created ports + return $this->collection('Port', $url, $this, $createdPortsJson); + } + /** * Returns a Port object associated with this Networking service * diff --git a/tests/OpenCloud/Tests/Networking/ServiceTest.php b/tests/OpenCloud/Tests/Networking/ServiceTest.php index 85092cb2e..92b793e19 100644 --- a/tests/OpenCloud/Tests/Networking/ServiceTest.php +++ b/tests/OpenCloud/Tests/Networking/ServiceTest.php @@ -30,7 +30,25 @@ public function test__construct() public function testCreateNetwork() { - $this->assertIsNetwork($this->service->createNetwork()); + $this->assertIsNetwork($this->service->createNetwork(array( + 'name' => 'network1' + ))); + } + + public function testCreateNetworks() + { + $this->addMockSubscriber($this->makeResponse('{"networks":[{"admin_state_up":true,"id":"e6031bc2-901a-4c66-82da-f4c32ed89406","name":"sample_network_1","shared":false,"status":"ACTIVE","subnets":[],"tenant_id":"d19231fc08ec4bc4829b668040d34512"},{"admin_state_up":false,"id":"64239a54-dcc4-4b39-920b-b37c2144effa","name":"sample_network_2","shared":false,"status":"ACTIVE","subnets":[],"tenant_id":"d19231fc08ec4bc4829b668040d34512"}]}')); + + $createdNetworks = $this->service->createNetworks(array( + array( + 'name' => 'sample_network_1' + ), + array( + 'name' => 'sample_network_2' + ) + )); + $this->isCollection($createdNetworks); + $this->assertIsNetwork($createdNetworks->getElement(0)); } public function testListNetworks() @@ -56,6 +74,22 @@ public function testCreateSubnet() $this->assertIsSubnet($this->service->createSubnet()); } + public function testCreateSubnets() + { + $this->addMockSubscriber($this->makeResponse('{"subnets":[{"cidr":"192.168.199.0/24","ip_version":4,"network_id":"e6031bc2-901a-4c66-82da-f4c32ed89406"},{"cidr":"10.56.4.0/22","ip_version":4,"network_id":"64239a54-dcc4-4b39-920b-b37c2144effa"}]}')); + + $createdSubnets = $this->service->createSubnets(array( + array( + 'cidr' => '192.168.199.0/24' + ), + array( + 'cidr' => '10.56.4.0/22' + ) + )); + $this->isCollection($createdSubnets); + $this->assertIsSubnet($createdSubnets->getElement(0)); + } + public function testListSubnets() { $this->addMockSubscriber($this->makeResponse('{"subnets":[{"allocation_pools":[{"end":"192.168.9.254","start":"192.168.9.1"}],"cidr":"192.168.9.0/24","dns_nameservers":[],"enable_dhcp":false,"gateway_ip":null,"host_routes":[],"id":"f975defc-637d-4e2a-858b-c6cc4cec3951","ip_version":4,"name":"","network_id":"0ebf6a10-5fc1-4f13-aca9-be0a2a00b1ac","tenant_id":"123456"}]}')); @@ -79,6 +113,22 @@ public function testCreatePort() $this->assertIsPort($this->service->createPort()); } + public function testCreatePorts() + { + $this->addMockSubscriber($this->makeResponse('{"ports":[{"admin_state_up":true,"device_id":"24df1d04-d5cb-41e1-8de5-61ed77c558df","name":"port1","network_id":"64239a54-dcc4-4b39-920b-b37c2144effa","security_groups":["dbc107f4-afcd-4d5a-9352-f68f82241d5b"]},{"admin_state_up":false,"name":"port2","network_id":"e6031bc2-901a-4c66-82da-f4c32ed89406","security_groups":["8bf3f7cc-8471-40b1-815f-9da47e79775b","dbc107f4-afcd-4d5a-9352-f68f82241d5b"]}]}')); + + $createdPorts = $this->service->createPorts(array( + array( + 'name' => 'port1' + ), + array( + 'name' => 'port2' + ) + )); + $this->isCollection($createdPorts); + $this->assertIsPort($createdPorts->getElement(0)); + } + public function testListPorts() { $this->addMockSubscriber($this->makeResponse('{"ports":[{"admin_state_up":true,"device_id":"","device_owner":null,"fixed_ips":[{"ip_address":"192.168.3.11","subnet_id":"739ecc58-f9a0-4145-8a06-cd415e6e5c8d"}],"id":"10ba23f5-bb70-4fd7-a118-83f89b62e340","mac_address":"BE:CB:FE:00:00:EE","name":"port1","network_id":"6406ed30-193a-4958-aae5-7c05268d332b","security_groups":[],"status":"ACTIVE","tenant_id":"123456"}]}')); From eb30f3810e16e4dcf429def332d789eff36511cd Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 5 Nov 2014 16:17:28 -0800 Subject: [PATCH 06/32] Adding smoke tests. --- tests/OpenCloud/Smoke/Runner.php | 1 + tests/OpenCloud/Smoke/Unit/Networking.php | 273 ++++++++++++++++++++++ 2 files changed, 274 insertions(+) create mode 100644 tests/OpenCloud/Smoke/Unit/Networking.php diff --git a/tests/OpenCloud/Smoke/Runner.php b/tests/OpenCloud/Smoke/Runner.php index 073e1c376..d1925ba83 100644 --- a/tests/OpenCloud/Smoke/Runner.php +++ b/tests/OpenCloud/Smoke/Runner.php @@ -41,6 +41,7 @@ class Runner 'Database', 'Identity', 'LoadBalancer', + 'Networking', 'ObjectStore', 'Orchestration', 'Queues', diff --git a/tests/OpenCloud/Smoke/Unit/Networking.php b/tests/OpenCloud/Smoke/Unit/Networking.php new file mode 100644 index 000000000..c2dda80c3 --- /dev/null +++ b/tests/OpenCloud/Smoke/Unit/Networking.php @@ -0,0 +1,273 @@ +getConnection()->networkingService('cloudNetworks', Utils::getRegion()); + return $this->getConnection()->networkingService('cloudNetworksPreprod', Utils::getRegion()); + } + + public function main() + { + $this->testNetworkOperations(); + $this->testSubnetOperations(); + $this->testPortOperations(); + } + + protected function testNetworkOperations() + { + $this->step('Create network'); + $createdNetwork = $this->getService()->createNetwork(array( + 'name' => 'test_network' + )); + $this->stepInfo('Network ID: ' . $createdNetwork->getId()); + $this->stepInfo('Network Name: ' . $createdNetwork->getName()); + $this->cleanupNetworkIds[] = $createdNetwork->getId(); + + // The next operation is commented out (for now) because the Rackspace + // Networking API does not support bulk operations (for now). When that + // changes in the future, please uncomment this operation. + // $this->step('Create networks'); + // $createdNetworks = $this->getService()->createNetworks(array( + // array( 'name' => 'test_network_1' ), + // array( 'name' => 'test_network_2' ), + // array( 'name' => 'test_network_3' ), + // )); + // $this->stepInfo('%-40s | %s', 'Network ID', 'Network name'); + // $this->stepInfo('%-40s | %s', str_repeat('-', 40), str_repeat('-', 40)); + // foreach ($createdNetworks as $network) { + // $this->stepInfo('%-40s | %s', $network->getId(), $network->getName()); + // $this->cleanupNetworkIds[] = $network->getId(); + // } + + $this->step('List networks'); + $networks = $this->getService()->listNetworks(); + $this->stepInfo('%-40s | %s', 'Network ID', 'Network name'); + $this->stepInfo('%-40s | %s', str_repeat('-', 40), str_repeat('-', 40)); + foreach ($networks as $network) { + $this->stepInfo('%-40s | %s', $network->getId(), $network->getName()); + } + + $this->step('Get network'); + $network = $this->getService()->getNetwork($createdNetwork->getId()); + $this->stepInfo('Network ID: ' . $network->getId()); + $this->stepInfo('Network Name: ' . $network->getName()); + + $this->step('Update network'); + $network->update(array( + 'name' => 'updated_test_network' + )); + } + + protected function testSubnetOperations() + { + $network1 = $this->getService()->createNetwork(array( + 'name' => 'test_network_for_test_subnet' + )); + $this->cleanupNetworkIds[] = $network1->getId(); + + $this->step('Create subnet'); + $subnet = $this->getService()->createSubnet(array( + 'cidr' => '192.168.199.0/24', + 'networkId' => $network1->getId(), + 'ipVersion' => 4, + 'name' => 'test_subnet' + )); + $this->stepInfo('Subnet ID: ' . $subnet->getId()); + $this->stepInfo('Subnet Name: ' . $subnet->getName()); + $this->cleanupSubnetIds[] = $subnet->getId(); + + $network2 = $this->getService()->createNetwork(array( + 'name' => 'test_network_for_test_subnet_w_gateway' + )); + $this->cleanupNetworkIds[] = $network2->getId(); + + $this->step('Create subnet with gateway IP'); + $subnet = $this->getService()->createSubnet(array( + 'cidr' => '192.168.62.0/25', + 'networkId' => $network2->getId(), + 'ipVersion' => 4, + 'name' => 'test_subnet_with_gateway_ip', + 'gatewayIp' => '192.168.62.128' + )); + $this->stepInfo('Subnet ID: ' . $subnet->getId()); + $this->stepInfo('Subnet Name: ' . $subnet->getName()); + $this->cleanupSubnetIds[] = $subnet->getId(); + + $network3 = $this->getService()->createNetwork(array( + 'name' => 'test_network_for_test_subnet_w_host_rt' + )); + $this->cleanupNetworkIds[] = $network3->getId(); + + $this->step('Create subnet with host routes'); + $subnet = $this->getService()->createSubnet(array( + 'cidr' => '192.168.62.0/25', + 'networkId' => $network3->getId(), + 'ipVersion' => 4, + 'name' => 'test_subnet_with_host_routes', + 'hostRoutes' => array( + array( + 'destination' => '1.1.1.0/24', + 'nexthop' => '192.168.19.20' + ) + ) + )); + $this->stepInfo('Subnet ID: ' . $subnet->getId()); + $this->stepInfo('Subnet Name: ' . $subnet->getName()); + $this->cleanupSubnetIds[] = $subnet->getId(); + + // The next operation is commented out (for now) because the Rackspace + // Networking API does not support bulk operations (for now). When that + // changes in the future, please uncomment this operation. + // $this->step('Create subnets'); + // $subnets = $this->getService()->createSubnets(array( + // array( + // 'cidr' => '192.168.199.0/24', + // 'networkId' => $network->getId(), + // 'ipVersion' => 4, + // 'name' => 'test_subnet_1' + // ) + // )); + // $this->stepInfo('%-40s | %s', 'Subnet ID', 'Subnet name'); + // $this->stepInfo('%-40s | %s', str_repeat('-', 40), str_repeat('-', 40)); + // foreach ($subnets as $subnet) { + // $this->stepInfo('%-40s | %s', $subnet->getId(), $subnet->getName()); + // $this->cleanupSubnetIds[] = $subnet->getId(); + // } + + $this->step('List subnets'); + $subnets = $this->getService()->listSubnets(); + $this->stepInfo('%-40s | %s', 'Subnet ID', 'Subnet name'); + $this->stepInfo('%-40s | %s', str_repeat('-', 40), str_repeat('-', 40)); + foreach ($subnets as $subnet) { + $this->stepInfo('%-40s | %s', $subnet->getId(), $subnet->getName()); + } + + $this->step('Get subnet'); + $subnet = $this->getService()->getSubnet($subnet->getId()); + $this->stepInfo('Subnet ID: ' . $subnet->getId()); + $this->stepInfo('Subnet Name: ' . $subnet->getName()); + + $this->step('Update subnet'); + $subnet->update(array( + 'name' => 'updated_test_subnet', + 'hostRoutes' => array( + array( + 'destination' => '1.1.1.0/24', + 'nexthop' => '192.168.17.19' + ) + ), + 'gatewayIp' => '192.168.62.155' + )); + } + + protected function testPortOperations() + { + $network1 = $this->getService()->createNetwork(array( + 'name' => 'test_network_for_test_port' + )); + $this->cleanupNetworkIds[] = $network1->getId(); + + $subnet1 = $this->getService()->createSubnet(array( + 'cidr' => '192.168.62.0/25', + 'networkId' => $network1->getId(), + 'ipVersion' => 4, + 'name' => 'test_subnet_for_test_port' + )); + $this->cleanupSubnetIds[] = $subnet1->getId(); + + $this->step('Create port'); + $port = $this->getService()->createPort(array( + 'networkId' => $network1->getId(), + 'name' => 'test_port' + )); + $this->stepInfo('Port ID: ' . $port->getId()); + $this->stepInfo('Port Name: ' . $port->getName()); + $this->cleanupPortIds[] = $port->getId(); + + // The next operation is commented out (for now) because the Rackspace + // Networking API does not support bulk operations (for now). When that + // changes in the future, please uncomment this operation. + // $this->step('Create ports'); + // $ports = $this->getService()->createPorts(array( + // )); + // $this->stepInfo('%-40s | %s', 'Port ID', 'Port name'); + // $this->stepInfo('%-40s | %s', str_repeat('-', 40), str_repeat('-', 40)); + // foreach ($ports as $port) { + // $this->stepInfo('%-40s | %s', $port->getId(), $port->getName()); + // $this->cleanupPortIds[] = $port->getId(); + // } + + $this->step('List ports'); + $ports = $this->getService()->listPorts(); + $this->stepInfo('%-40s | %s', 'Port ID', 'Port name'); + $this->stepInfo('%-40s | %s', str_repeat('-', 40), str_repeat('-', 40)); + foreach ($ports as $port) { + $this->stepInfo('%-40s | %s', $port->getId(), $port->getName()); + } + + $this->step('Get port'); + $port = $this->getService()->getPort($port->getId()); + $this->stepInfo('Port ID: ' . $port->getId()); + $this->stepInfo('Port Name: ' . $port->getName()); + + $this->step('Update port'); + $port->update(array( + 'name' => 'updated_test_port', + 'fixedIps' => array( + array( + 'subnet_id' => $subnet1->getId(), + 'ip_address' => '192.168.62.17' + ) + ) + )); + } + + public function teardown() + { + foreach ($this->cleanupPortIds as $portId) { + $port = $this->getService()->getPort($portId); + $port->delete(); + } + + foreach ($this->cleanupSubnetIds as $subnetId) { + $subnet = $this->getService()->getSubnet($subnetId); + $subnet->delete(); + } + + foreach ($this->cleanupNetworkIds as $networkId) { + $network = $this->getService()->getNetwork($networkId); + $network->delete(); + } + + } +} From bc2c93acac28de4889029cbb51681035b8ff8ace Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 5 Nov 2014 16:17:38 -0800 Subject: [PATCH 07/32] Fixing update-able attributes based on empirical evidence. --- lib/OpenCloud/Networking/Resource/Network.php | 3 +-- lib/OpenCloud/Networking/Resource/Port.php | 25 ++++++++----------- lib/OpenCloud/Networking/Resource/Subnet.php | 7 +----- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/lib/OpenCloud/Networking/Resource/Network.php b/lib/OpenCloud/Networking/Resource/Network.php index 934f151bd..2f75a2592 100644 --- a/lib/OpenCloud/Networking/Resource/Network.php +++ b/lib/OpenCloud/Networking/Resource/Network.php @@ -54,8 +54,7 @@ class Network extends PersistentResource protected $updateKeys = array( 'adminStateUp', 'name', - 'shared', - 'tenantId' + 'shared' ); /** diff --git a/lib/OpenCloud/Networking/Resource/Port.php b/lib/OpenCloud/Networking/Resource/Port.php index 77919131d..63a92dc2c 100644 --- a/lib/OpenCloud/Networking/Resource/Port.php +++ b/lib/OpenCloud/Networking/Resource/Port.php @@ -56,26 +56,23 @@ class Port extends PersistentResource protected $createKeys = array( 'name', - 'enableDhcp', + 'adminStateUp', 'networkId', - 'allocationPools', - 'hostRoutes', - 'ipVersion', - 'gatewayIp', - 'cidr', + 'deviceId', + 'deviceOwner', + 'fixedIps', + 'macAddress', + 'securityGroups', 'tenantId' ); protected $updateKeys = array( 'name', - 'enableDhcp', - 'networkId', - 'allocationPools', - 'hostRoutes', - 'ipVersion', - 'gatewayIp', - 'cidr', - 'tenantId' + 'adminStateUp', + 'deviceId', + 'deviceOwner', + 'fixedIps', + 'securityGroups' ); /** diff --git a/lib/OpenCloud/Networking/Resource/Subnet.php b/lib/OpenCloud/Networking/Resource/Subnet.php index cbbbc9e2e..b51727d0b 100644 --- a/lib/OpenCloud/Networking/Resource/Subnet.php +++ b/lib/OpenCloud/Networking/Resource/Subnet.php @@ -69,13 +69,8 @@ class Subnet extends PersistentResource protected $updateKeys = array( 'name', 'enableDhcp', - 'networkId', - 'allocationPools', 'hostRoutes', - 'ipVersion', - 'gatewayIp', - 'cidr', - 'tenantId' + 'gatewayIp' ); /** From ee8a9a335eb5b483f9e792f3ff684510ed746f8c Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 5 Nov 2014 17:52:46 -0800 Subject: [PATCH 08/32] Recursively alias properties. --- .../Common/Resource/PersistentResource.php | 28 ++++- .../Resource/PersistentResourceTest.php | 109 ++++++++++++++++++ 2 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index e87d46323..76977758a 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -217,7 +217,7 @@ protected function createJson() foreach ($this->createKeys as $key) { if (null !== ($property = $this->getProperty($key))) { - $element->{$this->getAlias($key)} = $property; + $element->{$this->getAlias($key)} = $this->recursivelyAliasPropertyValue($property); } } @@ -244,6 +244,30 @@ protected function getAlias($key) return $key; } + protected function recursivelyAliasPropertyValue($propertyValue) + { + if (is_array($propertyValue)) { + foreach ($propertyValue as $key => $subValue) { + $aliasedSubValue = $this->recursivelyAliasPropertyValue($subValue); + if (is_numeric($key)) { + $propertyValue[$key] = $aliasedSubValue; + } else { + unset($propertyValue[$key]); + $propertyValue[$this->getAlias($key)] = $aliasedSubValue; + } + } + } + + elseif (is_object($propertyValue) && ($propertyValue instanceOf \stdClass)) { + foreach ($propertyValue as $key => $subValue) { + unset($propertyValue->$key); + $propertyValue->{$this->getAlias($key)} = $this->recursivelyAliasPropertyValue($subValue); + } + } + + return $propertyValue; + } + /** * Provides JSON for update request body */ @@ -260,7 +284,7 @@ protected function updateJson($params = array()) foreach ($this->updateKeys as $key) { if (null !== ($property = $this->getProperty($key))) { - $element->{$this->getAlias($key)} = $property; + $element->{$this->getAlias($key)} = $this->recursivelyAliasPropertyValue($property); } } diff --git a/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php b/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php new file mode 100644 index 000000000..cd81b93ab --- /dev/null +++ b/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php @@ -0,0 +1,109 @@ + 'fooBar' + ); + + public function recursivelyAliasPropertyValue($propertyValue) + { + return parent::recursivelyAliasPropertyValue($propertyValue); + } +} + +class PersistentResourceTest extends OpenCloudTestCase +{ + private $persistentResource; + + public function setupObjects() + { + $service = IdentityService::factory($this->client); + $this->persistentResource = new PublicPersistentResource($service); + } + + public function testRecursivelyAliasPropertyValueWithScalars() + { + $this->assertEquals(11, + $this->persistentResource->recursivelyAliasPropertyValue(11)); + $this->assertEquals("foobar", + $this->persistentResource->recursivelyAliasPropertyValue("foobar")); + $this->assertEquals("fooBar", + $this->persistentResource->recursivelyAliasPropertyValue("fooBar")); + $this->assertEquals(false, + $this->persistentResource->recursivelyAliasPropertyValue(false)); + } + + public function testRecursivelyAliasPropertyValueWithIndexedArrays() + { + $this->assertEquals(array(18), + $this->persistentResource->recursivelyAliasPropertyValue(array(18))); + $this->assertEquals(array("foobar"), + $this->persistentResource->recursivelyAliasPropertyValue(array("foobar"))); + $this->assertEquals(array("fooBar"), + $this->persistentResource->recursivelyAliasPropertyValue(array("fooBar"))); + } + + public function testRecursivelyAliasPropertyValueWithAssociativeArrays() + { + $this->assertEquals(array("foobar" => "baz"), + $this->persistentResource->recursivelyAliasPropertyValue(array("foobar" => "baz"))); + $this->assertEquals(array("foo_bar" => "baz"), + $this->persistentResource->recursivelyAliasPropertyValue(array("fooBar" => "baz"))); + $this->assertEquals(array("qux" => array("foo_bar" => "baz")), + $this->persistentResource->recursivelyAliasPropertyValue(array("qux" => array("fooBar" => "baz")))); + } + + public function testRecursivelyAliasPropertyValueWithObjects() + { + $obj1 = new \stdClass(); + $obj1->foobar = "baz"; + + $obj1Expected = new \stdClass(); + $obj1Expected->foobar = "baz"; + + $this->assertEquals($obj1Expected, + $this->persistentResource->recursivelyAliasPropertyValue($obj1)); + + $obj2 = new \stdClass(); + $obj2->fooBar = "baz"; + + $obj2Expected = new \stdClass(); + $obj2Expected->foo_bar = "baz"; + + $this->assertEquals($obj2Expected, + $this->persistentResource->recursivelyAliasPropertyValue($obj2)); + + $obj3 = new \stdClass(); + $obj3->qux = new \stdClass(); + $obj3->qux->fooBar = "baz"; + + $obj3Expected = new \stdClass(); + $obj3Expected->qux = new \stdClass(); + $obj3Expected->qux->foo_bar = "baz"; + + $this->assertEquals($obj3Expected, + $this->persistentResource->recursivelyAliasPropertyValue($obj3)); + } +} From 72e3d10aef11f150e85adbe1e23daab18f7c3158 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 5 Nov 2014 17:53:34 -0800 Subject: [PATCH 09/32] Adding aliases for sub-properties. --- lib/OpenCloud/Networking/Resource/Port.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/OpenCloud/Networking/Resource/Port.php b/lib/OpenCloud/Networking/Resource/Port.php index 63a92dc2c..072edb850 100644 --- a/lib/OpenCloud/Networking/Resource/Port.php +++ b/lib/OpenCloud/Networking/Resource/Port.php @@ -51,7 +51,9 @@ class Port extends PersistentResource 'fixed_ips' => 'fixedIps', 'mac_address' => 'macAddress', 'security_groups' => 'securityGroups', - 'tenant_id' => 'tenantId' + 'tenant_id' => 'tenantId', + 'subnet_id' => 'subnetId', + 'ip_address' => 'ipAddress' ); protected $createKeys = array( From 07c045694e2cd7f4c2ae53e706f5ca17f6e2b3ec Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 5 Nov 2014 17:54:06 -0800 Subject: [PATCH 10/32] Using camelCase sub-properties. --- tests/OpenCloud/Smoke/Unit/Networking.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/OpenCloud/Smoke/Unit/Networking.php b/tests/OpenCloud/Smoke/Unit/Networking.php index c2dda80c3..988a37591 100644 --- a/tests/OpenCloud/Smoke/Unit/Networking.php +++ b/tests/OpenCloud/Smoke/Unit/Networking.php @@ -242,11 +242,11 @@ protected function testPortOperations() $this->step('Update port'); $port->update(array( - 'name' => 'updated_test_port', + 'name' => 'updated_test_port', 'fixedIps' => array( array( - 'subnet_id' => $subnet1->getId(), - 'ip_address' => '192.168.62.17' + 'subnetId' => $subnet1->getId(), + 'ipAddress' => '192.168.62.17' ) ) )); From f436fb93be8a2979b9d5e80d49af4987d655b569 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 5 Nov 2014 17:54:34 -0800 Subject: [PATCH 11/32] Fleshing out update examples. --- samples/Networking/update-port.php | 14 +++++++++++--- samples/Networking/update-subnet.php | 9 ++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/samples/Networking/update-port.php b/samples/Networking/update-port.php index b4c4db186..59e174856 100644 --- a/samples/Networking/update-port.php +++ b/samples/Networking/update-port.php @@ -21,8 +21,10 @@ // * OS_AUTH_URL: Your OpenStack Cloud Authentication URL, // * OS_USERNAME: Your OpenStack Cloud Account Username, // * OS_PASSWORD: Your OpenStack Cloud Account Password, -// * OS_REGION_NAME: The OpenStack Cloud region you want to use, and -// * PORT_ID: ID of port +// * OS_REGION_NAME: The OpenStack Cloud region you want to use, +// * PORT_ID: ID of port, +// * SUBNET_ID: ID of subnet for new fixed IP, and +// * IP_ADDRESS: IP address for new fixed IP // require __DIR__ . '/../../vendor/autoload.php'; @@ -43,5 +45,11 @@ // 4. Update port. $port->update(array( - 'name' => 'My updated port' + 'name' => 'My updated port', + 'fixedIps' => array( + array( + 'subnetId' => getenv('SUBNET_ID'), + 'ipAddress' => getenv('IP_ADDRESS') + ) + ) )); diff --git a/samples/Networking/update-subnet.php b/samples/Networking/update-subnet.php index 46f8b5d1a..6f74f9ffa 100644 --- a/samples/Networking/update-subnet.php +++ b/samples/Networking/update-subnet.php @@ -43,5 +43,12 @@ // 4. Update subnet. $subnet->update(array( - 'name' => 'My updated subnet' + 'name' => 'My updated subnet', + 'hostRoutes' => array( + array( + 'destination' => '1.1.1.0/24', + 'nexthop' => '192.168.17.19' + ) + ), + 'gatewayIp' => '192.168.62.155' )); From 6f61eb869620fb39a5a733bba6d0e679b13ee1f3 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 5 Nov 2014 17:55:02 -0800 Subject: [PATCH 12/32] Adding more nuanced create subnet samples. --- .../create-subnet-with-gateway-ip.php | 49 +++++++++++++++++ .../create-subnet-with-host-routes.php | 54 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 samples/Networking/create-subnet-with-gateway-ip.php create mode 100644 samples/Networking/create-subnet-with-host-routes.php diff --git a/samples/Networking/create-subnet-with-gateway-ip.php b/samples/Networking/create-subnet-with-gateway-ip.php new file mode 100644 index 000000000..512f49e49 --- /dev/null +++ b/samples/Networking/create-subnet-with-gateway-ip.php @@ -0,0 +1,49 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Create a subnet. +$subnet = $networkingService->createSubnet(array( + 'name' => 'My subnet', + 'networkId' => getenv('NETWORK_ID'), + 'ipVersion' => 4, + 'cidr' => '192.168.199.0/25', + 'gatewayIp' => '192.168.199.128' +)); +/** @var $subnet OpenCloud\Networking\Resource\Subnet **/ diff --git a/samples/Networking/create-subnet-with-host-routes.php b/samples/Networking/create-subnet-with-host-routes.php new file mode 100644 index 000000000..2e20e7b87 --- /dev/null +++ b/samples/Networking/create-subnet-with-host-routes.php @@ -0,0 +1,54 @@ + getenv('OS_USERNAME'), + 'password' => getenv('OS_PASSWORD') +)); + +// 2. Obtain an Networking service object from the client. +$region = getenv('OS_REGION_NAME'); +$networkingService = $client->networkingService(null, $region); + +// 3. Create a subnet. +$subnet = $networkingService->createSubnet(array( + 'name' => 'My subnet', + 'networkId' => getenv('NETWORK_ID'), + 'ipVersion' => 4, + 'cidr' => '192.168.199.0/24', + 'hostRoutes' => array( + array( + 'destination' => '1.1.1.0/24', + 'nexthop' => '192.168.19.20' + ) + ) +)); +/** @var $subnet OpenCloud\Networking\Resource\Subnet **/ From f3a8f4be4d0d421124850ded5886cba526a41a64 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 5 Nov 2014 18:02:44 -0800 Subject: [PATCH 13/32] Make the PSR-2 checker happy. --- lib/OpenCloud/Common/Resource/PersistentResource.php | 4 +--- tests/OpenCloud/Smoke/Unit/Networking.php | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index 76977758a..583eeba41 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -256,9 +256,7 @@ protected function recursivelyAliasPropertyValue($propertyValue) $propertyValue[$this->getAlias($key)] = $aliasedSubValue; } } - } - - elseif (is_object($propertyValue) && ($propertyValue instanceOf \stdClass)) { + } elseif (is_object($propertyValue) && ($propertyValue instanceof \stdClass)) { foreach ($propertyValue as $key => $subValue) { unset($propertyValue->$key); $propertyValue->{$this->getAlias($key)} = $this->recursivelyAliasPropertyValue($subValue); diff --git a/tests/OpenCloud/Smoke/Unit/Networking.php b/tests/OpenCloud/Smoke/Unit/Networking.php index 988a37591..a2753e071 100644 --- a/tests/OpenCloud/Smoke/Unit/Networking.php +++ b/tests/OpenCloud/Smoke/Unit/Networking.php @@ -25,14 +25,14 @@ * @link */ class Networking extends AbstractUnit implements UnitInterface -{ +{ protected $cleanupNetworkIds = array(); protected $cleanupSubnetIds = array(); protected $cleanupPortIds = array(); public function setupService() { -// return $this->getConnection()->networkingService('cloudNetworks', Utils::getRegion()); + // return $this->getConnection()->networkingService('cloudNetworks', Utils::getRegion()); return $this->getConnection()->networkingService('cloudNetworksPreprod', Utils::getRegion()); } @@ -268,6 +268,5 @@ public function teardown() $network = $this->getService()->getNetwork($networkId); $network->delete(); } - } } From 1f7cfaa9de1bc8063e7c973b97f5eead3259d220 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 06:20:48 -0800 Subject: [PATCH 14/32] Adding previously-MIA header comment. --- lib/OpenCloud/Common/Resource/PersistentResource.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index 583eeba41..c012b8e76 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -244,6 +244,14 @@ protected function getAlias($key) return $key; } + /** + * Returns the given property value's alias, if configured; Else, the + * unchanged property value is returned. If the given property value + * is an array or an instance of \stdClass, it is aliases recursively. + * + * @param mixed $propertyValue Array or \stdClass instance to alias + * @return mixed Property value, aliased recursively + */ protected function recursivelyAliasPropertyValue($propertyValue) { if (is_array($propertyValue)) { From 149d5cef8a06c4e5c5a91e914b5a7ee427ae2b18 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 06:28:58 -0800 Subject: [PATCH 15/32] Referencing class using @see annotation. --- lib/OpenCloud/Networking/Resource/Network.php | 2 +- lib/OpenCloud/Networking/Resource/Port.php | 2 +- lib/OpenCloud/Networking/Resource/Subnet.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OpenCloud/Networking/Resource/Network.php b/lib/OpenCloud/Networking/Resource/Network.php index 2f75a2592..596ea6d83 100644 --- a/lib/OpenCloud/Networking/Resource/Network.php +++ b/lib/OpenCloud/Networking/Resource/Network.php @@ -60,7 +60,7 @@ class Network extends PersistentResource /** * This method is inherited. The inherited method has protected scope * but we are widening the scope to public so this method may be called - * from other classes such as OpenCloud\Networking\Service. + * from other classes such as {@see OpenCloud\Networking\Service}. */ public function createJson() { diff --git a/lib/OpenCloud/Networking/Resource/Port.php b/lib/OpenCloud/Networking/Resource/Port.php index 072edb850..6689bbb98 100644 --- a/lib/OpenCloud/Networking/Resource/Port.php +++ b/lib/OpenCloud/Networking/Resource/Port.php @@ -80,7 +80,7 @@ class Port extends PersistentResource /** * This method is inherited. The inherited method has protected scope * but we are widening the scope to public so this method may be called - * from other classes such as OpenCloud\Networking\Service. + * from other classes such as {@see OpenCloud\Networking\Service}. */ public function createJson() { diff --git a/lib/OpenCloud/Networking/Resource/Subnet.php b/lib/OpenCloud/Networking/Resource/Subnet.php index b51727d0b..bd454753d 100644 --- a/lib/OpenCloud/Networking/Resource/Subnet.php +++ b/lib/OpenCloud/Networking/Resource/Subnet.php @@ -76,7 +76,7 @@ class Subnet extends PersistentResource /** * This method is inherited. The inherited method has protected scope * but we are widening the scope to public so this method may be called - * from other classes such as OpenCloud\Networking\Service. + * from other classes such as {@see OpenCloud\Networking\Service}. */ public function createJson() { From 96e8b80e0fac9886698cb65cc8d4f10a21adf316 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 06:30:58 -0800 Subject: [PATCH 16/32] Removing unnecessary annotation. --- lib/OpenCloud/Networking/Service.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/OpenCloud/Networking/Service.php b/lib/OpenCloud/Networking/Service.php index cac03e122..596b9fd2b 100644 --- a/lib/OpenCloud/Networking/Service.php +++ b/lib/OpenCloud/Networking/Service.php @@ -28,8 +28,6 @@ * * Neutron is a service that provides networking between devices managed by other * OpenNetwork services (e.g. Compute). - * - * @codeCoverageIgnore */ class Service extends CatalogService { From 9603d494fafe30672c9ce298a1c5e00ff1b409b6 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 06:37:12 -0800 Subject: [PATCH 17/32] Using FQCNs in method docblocks. --- lib/OpenCloud/Networking/Service.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/OpenCloud/Networking/Service.php b/lib/OpenCloud/Networking/Service.php index 596b9fd2b..8f160491b 100644 --- a/lib/OpenCloud/Networking/Service.php +++ b/lib/OpenCloud/Networking/Service.php @@ -38,7 +38,7 @@ class Service extends CatalogService * Returns a Network object associated with this Networking service * * @param string $id ID of network to retrieve - * @return Network object + * @return \OpenCloud\Networking\Resource\Network object */ public function network($id = null) { @@ -49,7 +49,7 @@ public function network($id = null) * Creates a new Network and returns it. * * @param array $params Network creation parameters - * @return Network Object representing created network + * @return \OpenCloud\Networking\Resource\Network Object representing created network */ public function createNetwork($params = array()) { @@ -98,7 +98,7 @@ public function createNetworks($networksParams = array()) * Returns a Network object associated with this Networking service * * @param string $id ID of network to retrieve - * @return Network object + * @return \OpenCloud\Networking\Resource\Network object */ public function getNetwork($id) { @@ -123,7 +123,7 @@ public function listNetworks(array $params = array()) * Returns a Subnet object associated with this Networking service * * @param string $id ID of subnet to retrieve - * @return Subnet object + * @return \OpenCloud\Networking\Resource\Subnet object */ public function subnet($id = null) { @@ -134,7 +134,7 @@ public function subnet($id = null) * Creates a new Subnet and returns it. * * @param array $params Subnet creation parameters - * @return Subnet Object representing created subnet + * @return \OpenCloud\Networking\Resource\Subnet Object representing created subnet */ public function createSubnet($params = array()) { @@ -183,7 +183,7 @@ public function createSubnets($subnetsParams = array()) * Returns a Subnet object associated with this Networking service * * @param string $id ID of subnet to retrieve - * @return Subnet object + * @return \OpenCloud\Networking\Resource\Subnet object */ public function getSubnet($id) { @@ -208,7 +208,7 @@ public function listSubnets(array $params = array()) * Returns a Port object associated with this Networking service * * @param string $id ID of port to retrieve - * @return Port object + * @return \OpenCloud\Networking\Resource\Port object */ public function port($id = null) { @@ -219,7 +219,7 @@ public function port($id = null) * Creates a new Port and returns it. * * @param array $params Port creation parameters - * @return Port Object representing created port + * @return \OpenCloud\Networking\Resource\Port Object representing created port */ public function createPort($params = array()) { @@ -268,7 +268,7 @@ public function createPorts($portsParams = array()) * Returns a Port object associated with this Networking service * * @param string $id ID of port to retrieve - * @return Port object + * @return \OpenCloud\Networking\Resource\Port object */ public function getPort($id) { From d4f4132dd552386a6c3af017b40c829aa6aea3f7 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 06:43:04 -0800 Subject: [PATCH 18/32] Type hinting array method parameters. --- lib/OpenCloud/Networking/Service.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/OpenCloud/Networking/Service.php b/lib/OpenCloud/Networking/Service.php index 8f160491b..527e75f28 100644 --- a/lib/OpenCloud/Networking/Service.php +++ b/lib/OpenCloud/Networking/Service.php @@ -51,7 +51,7 @@ public function network($id = null) * @param array $params Network creation parameters * @return \OpenCloud\Networking\Resource\Network Object representing created network */ - public function createNetwork($params = array()) + public function createNetwork(array $params = array()) { $network = $this->network(); $network->create($params); @@ -64,7 +64,7 @@ public function createNetwork($params = array()) * @param array $networksParams Array of network creation parameters' arrays * @return \OpenCloud\Common\Collection\PaginatedIterator */ - public function createNetworks($networksParams = array()) + public function createNetworks(array $networksParams = array()) { // Form URL $url = clone $this->getUrl(); @@ -136,7 +136,7 @@ public function subnet($id = null) * @param array $params Subnet creation parameters * @return \OpenCloud\Networking\Resource\Subnet Object representing created subnet */ - public function createSubnet($params = array()) + public function createSubnet(array $params = array()) { $subnet = $this->subnet(); $subnet->create($params); @@ -149,7 +149,7 @@ public function createSubnet($params = array()) * @param array $subnetsParams Array of subnet creation parameters' arrays * @return \OpenCloud\Common\Collection\PaginatedIterator */ - public function createSubnets($subnetsParams = array()) + public function createSubnets(array $subnetsParams = array()) { // Form URL $url = clone $this->getUrl(); @@ -221,7 +221,7 @@ public function port($id = null) * @param array $params Port creation parameters * @return \OpenCloud\Networking\Resource\Port Object representing created port */ - public function createPort($params = array()) + public function createPort(array $params = array()) { $port = $this->port(); $port->create($params); @@ -234,7 +234,7 @@ public function createPort($params = array()) * @param array $portsParams Array of port creation parameters' arrays * @return \OpenCloud\Common\Collection\PaginatedIterator */ - public function createPorts($portsParams = array()) + public function createPorts(array $portsParams = array()) { // Form URL $url = clone $this->getUrl(); From 52a2b9ecf07ff1da5dd901609f7eff1b4ed2e444 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 06:44:04 -0800 Subject: [PATCH 19/32] Clearly delimiting variable used to determine object property name. --- lib/OpenCloud/Networking/Service.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/OpenCloud/Networking/Service.php b/lib/OpenCloud/Networking/Service.php index 527e75f28..ee961af04 100644 --- a/lib/OpenCloud/Networking/Service.php +++ b/lib/OpenCloud/Networking/Service.php @@ -77,7 +77,7 @@ public function createNetworks(array $networksParams = array()) foreach ($networksParams as $networkParams) { $network = $this->network(); $network->populate($networkParams); - $networks[] = $network->createJson()->$singleNetworkJsonName; + $networks[] = $network->createJson()->{$singleNetworkJsonName}; } $json = json_encode(array( $networksJsonCollectionName => $networks @@ -88,7 +88,7 @@ public function createNetworks(array $networksParams = array()) // Parse the response into a collection of created networks $responseJson = Formatter::decode($response); - $createdNetworksJson = $responseJson->$networksJsonCollectionName; + $createdNetworksJson = $responseJson->{$networksJsonCollectionName}; // Return collection of created networks return $this->collection('Network', $url, $this, $createdNetworksJson); @@ -162,7 +162,7 @@ public function createSubnets(array $subnetsParams = array()) foreach ($subnetsParams as $subnetParams) { $subnet = $this->subnet(); $subnet->populate($subnetParams); - $subnets[] = $subnet->createJson()->$singleSubnetJsonName; + $subnets[] = $subnet->createJson()->{$singleSubnetJsonName}; } $json = json_encode(array( $subnetsJsonCollectionName => $subnets @@ -173,7 +173,7 @@ public function createSubnets(array $subnetsParams = array()) // Parse the response into a collection of created subnets $responseJson = Formatter::decode($response); - $createdSubnetsJson = $responseJson->$subnetsJsonCollectionName; + $createdSubnetsJson = $responseJson->{$subnetsJsonCollectionName}; // Return collection of created subnets return $this->collection('Subnet', $url, $this, $createdSubnetsJson); @@ -247,7 +247,7 @@ public function createPorts(array $portsParams = array()) foreach ($portsParams as $portParams) { $port = $this->port(); $port->populate($portParams); - $ports[] = $port->createJson()->$singlePortJsonName; + $ports[] = $port->createJson()->{$singlePortJsonName}; } $json = json_encode(array( $portsJsonCollectionName => $ports @@ -258,7 +258,7 @@ public function createPorts(array $portsParams = array()) // Parse the response into a collection of created ports $responseJson = Formatter::decode($response); - $createdPortsJson = $responseJson->$portsJsonCollectionName; + $createdPortsJson = $responseJson->{$portsJsonCollectionName}; // Return collection of created ports return $this->collection('Port', $url, $this, $createdPortsJson); From 9c87db0b2a649868857c8aa79aa390215ea628df Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 07:06:40 -0800 Subject: [PATCH 20/32] Fleshing out class header comments for Networking resources. --- lib/OpenCloud/Networking/Resource/Network.php | 7 ++++++- lib/OpenCloud/Networking/Resource/Port.php | 10 +++++++++- lib/OpenCloud/Networking/Resource/Subnet.php | 6 +++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/OpenCloud/Networking/Resource/Network.php b/lib/OpenCloud/Networking/Resource/Network.php index 596ea6d83..4aedc52c1 100644 --- a/lib/OpenCloud/Networking/Resource/Network.php +++ b/lib/OpenCloud/Networking/Resource/Network.php @@ -20,7 +20,12 @@ use OpenCloud\Common\Resource\PersistentResource; /** - * Class that represents a network. + * A network is an isolated virtual layer-2 broadcast domain that is typically + * reserved for the tenant who created it unless you configure the network to be + * shared. The network is the main entity in the Networking service. Ports ({@see + * \OpenCloud\Networking\Resource\Port}) and subnets ({@see + * \OpenCloud\Networking\Resource\Subnet}) are always associated with a network. + * * @see http://docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html#Network * * @package OpenCloud\Networking\Resource diff --git a/lib/OpenCloud/Networking/Resource/Port.php b/lib/OpenCloud/Networking/Resource/Port.php index 6689bbb98..c3c1bf243 100644 --- a/lib/OpenCloud/Networking/Resource/Port.php +++ b/lib/OpenCloud/Networking/Resource/Port.php @@ -20,7 +20,15 @@ use OpenCloud\Common\Resource\PersistentResource; /** - * Class that represents a port. + * A port represents a virtual switch port on a logical network switch, represented + * by {@see \OpenCloud\Networking\Resource\Network}. Virtual instances (such as + * servers created using the {@see \OpenCloud\Compute\Service}) attach their + * interfaces into ports. The port also defines the MAC address and the IP + * address(es) to be assigned to the interfaces plugged into them. When IP addresses + * are associated to a port, this also implies the port is associated with a {@see + * \OpenCloud\Networking\Resource\Subnet}, as the IP address is taken from the + * allocation pool for a specific subnet. + * * @see http://docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html#Port * * @package OpenCloud\Networking\Resource diff --git a/lib/OpenCloud/Networking/Resource/Subnet.php b/lib/OpenCloud/Networking/Resource/Subnet.php index bd454753d..8e52cc28a 100644 --- a/lib/OpenCloud/Networking/Resource/Subnet.php +++ b/lib/OpenCloud/Networking/Resource/Subnet.php @@ -20,7 +20,11 @@ use OpenCloud\Common\Resource\PersistentResource; /** - * Class that represents a subnet. + * A subnet represents an IP address block that can be used to assign IP + * addresses to virtual instances (such as servers created using the {@see + * \OpenCloud\Compute\Service}. Each subnet must have a CIDR and must be + * associated with a network. + * * @see http://docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html#Subnet * * @package OpenCloud\Networking\Resource From b30e306352006351572ca0e4ffe64bdff018b296 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 14:39:26 -0800 Subject: [PATCH 21/32] Start of Networking user guide. --- docs/userguide/Networking/USERGUIDE.md | 105 +++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 docs/userguide/Networking/USERGUIDE.md diff --git a/docs/userguide/Networking/USERGUIDE.md b/docs/userguide/Networking/USERGUIDE.md new file mode 100644 index 000000000..1530757bf --- /dev/null +++ b/docs/userguide/Networking/USERGUIDE.md @@ -0,0 +1,105 @@ +# Complete User Guide for the Networking Service + +Networking is a service that you can use to create virtual networks and attach cloud devices +such as servers to these networks. + +This user guide will introduce you the entities in the Networking service — networks, subnets, and ports — as well as show you how to create and manage these entities. + +## Concepts + +To use the Networking service effectively, you should understand the following key concepts: + +* **Network**: A network is an isolated virtual layer-2 broadcast domain that is typically reserved for the tenant who created it unless you configure the network to be shared. The network is the main entity in the Networking service. Ports and subnets are always associated with a network. + +* **Subnet**: A subnet represents an IP address block that can be used to assign IP addresses to virtual instances (such as servers created using the Compute service). Each subnet must have a CIDR and must be associated with a network. + +* **Port**: A port represents a virtual switch port on a logical network switch. Virtual instances (such as servers created using the Compute service) attach their interfaces into ports. The port also defines the MAC address and the IP address(es) to be assigned to the interfaces plugged into them. When IP addresses are associated to a port, this also implies the port is associated with a subet, as the IP address is taken from the allocation pool for a specific subnet. + +## Prerequisites + +### Client +To use the Networking service, you must first instantiate a `OpenStack` or `Rackspace` client object. + +* If you are working with an OpenStack cloud, instantiate an `OpenCloud\OpenStack` client as follows: + + ```php + use OpenCloud\OpenStack; + + $client = new OpenStack('', array( + 'username' => '', + 'password' => '' + )); + ``` + +* If you are working with the Rackspace cloud, instantiate a `OpenCloud\Rackspace` client as follows: + + ```php + use OpenCloud\Rackspace; + + $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array( + 'username' => '', + 'apiKey' => '' + )); + ``` + +### Networking service + +All Networking operations are done via a _networking service object_. To +instantiate this object, call the `networkingService` method on the `$client` +object. This method takes two arguments: + +| Position | Description | Data type | Required? | Default value | Example value | +| -------- | ----------- | ----------| --------- | ------------- | ------------- | +| 1 | Name of the service, as it appears in the service catalog | String | No | `null`; automatically determined when possible | `cloudNetworks` | +| 2 | Cloud region | String | Yes | - | `DFW` | + + +```php +$region = ''; +$networkingService = $client->networkingService(null, $region); +``` + +Any networks, subnets, and ports created with this `$networkingService` instance will +be stored in the cloud region specified by `$region`. + +## Networks + +### Create a network + +### Create multiple networks + +### List networks + +### Get network + +### Update network + +### Delete network + +## Subnets + +### Create a subnet + +### Create multiple subnets + +### List subnets + +### Get subnet + +### Update subnet + +### Delete subnet + +## Ports + +### Create a port + +### Create multiple ports + +### List ports + +### Get port + +### Update port + +### Delete port \ No newline at end of file From 344ba57966fc6f5d01c2db94338517ad37149aaa Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 14:42:51 -0800 Subject: [PATCH 22/32] Adding TOC. --- docs/userguide/Networking/USERGUIDE.md | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/userguide/Networking/USERGUIDE.md b/docs/userguide/Networking/USERGUIDE.md index 1530757bf..489d5471b 100644 --- a/docs/userguide/Networking/USERGUIDE.md +++ b/docs/userguide/Networking/USERGUIDE.md @@ -5,6 +5,33 @@ such as servers to these networks. This user guide will introduce you the entities in the Networking service — networks, subnets, and ports — as well as show you how to create and manage these entities. +## Table of Contents + * [Concepts](#concepts) + * [Prerequisites](#prerequisites) + * [Client](#client) + * [Networking service](#networking-service) + * [Networks](#networks) + * [Create a network](#create-a-network) + * [Create multiple networks](#create-multiple-networks) + * [List networks](#list-networks) + * [Get network](#get-network) + * [Update network](#update-network) + * [Delete network](#delete-network) + * [Subnets](#subnets) + * [Create a subnet](#create-a-subnet) + * [Create multiple subnets](#create-multiple-subnets) + * [List subnets](#list-subnets) + * [Get subnet](#get-subnet) + * [Update subnet](#update-subnet) + * [Delete subnet](#delete-subnet) + * [Ports](#ports) + * [Create a port](#create-a-port) + * [Create multiple ports](#create-multiple-ports) + * [List ports](#list-ports) + * [Get port](#get-port) + * [Update port](#update-port) + * [Delete port](#delete-port) + ## Concepts To use the Networking service effectively, you should understand the following key concepts: From e4b6ec7c05051e9168bfb0e378a4638a2efb49fd Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 16:30:29 -0800 Subject: [PATCH 23/32] Fixing network name to avoid confusion with VPN. --- samples/Networking/create-network.php | 2 +- samples/Networking/create-networks.php | 4 ++-- samples/Networking/update-network.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/Networking/create-network.php b/samples/Networking/create-network.php index b5dc0a931..02592bfb0 100644 --- a/samples/Networking/create-network.php +++ b/samples/Networking/create-network.php @@ -39,6 +39,6 @@ // 3. Create a network. $network = $networkingService->createNetwork(array( - 'name' => 'My virtual private network' + 'name' => 'My private backend network' )); /** @var $network OpenCloud\Networking\Resource\Network **/ diff --git a/samples/Networking/create-networks.php b/samples/Networking/create-networks.php index f452db2ee..6db031be0 100644 --- a/samples/Networking/create-networks.php +++ b/samples/Networking/create-networks.php @@ -40,10 +40,10 @@ // 3. Create multiple networks. $networks = $networkingService->createNetworks(array( array( - 'name' => 'My virtual private network #1' + 'name' => 'My private backend network #1' ), array( - 'name' => 'My virtual private network #2' + 'name' => 'My private backend network #2' ) )); diff --git a/samples/Networking/update-network.php b/samples/Networking/update-network.php index 7650be384..ec0a2ee50 100644 --- a/samples/Networking/update-network.php +++ b/samples/Networking/update-network.php @@ -43,5 +43,5 @@ // 4. Update network. $network->update(array( - 'name' => 'My updated virtual private network' + 'name' => 'My updated private backend network' )); From 8682a2c3854725587845a8430fb7cd63f1d6af24 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 17:09:53 -0800 Subject: [PATCH 24/32] Fleshing out user guide for Networks. --- docs/userguide/Networking/USERGUIDE.md | 90 ++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/docs/userguide/Networking/USERGUIDE.md b/docs/userguide/Networking/USERGUIDE.md index 489d5471b..b55783b56 100644 --- a/docs/userguide/Networking/USERGUIDE.md +++ b/docs/userguide/Networking/USERGUIDE.md @@ -91,18 +91,108 @@ be stored in the cloud region specified by `$region`. ## Networks +A network is an isolated virtual layer-2 broadcast domain that is typically reserved for the tenant who created it unless you configure the network to be shared. The network is the main entity in the Networking service. Ports and subnets are always associated with a network. + ### Create a network +This operation takes one parameter, an associative array, with the following keys: + +| Name | Description | Data type | Required? | Default value | Example value | +| ---- | ----------- | --------- | --------- | ------------- | ------------- | +| `name` | Human-readable name for the network. Might not be unique. | String | No | `null` | `backend_network` | +| `adminStateUp` | The administrative state of network. If `false` (down), the network does not forward packets. | Boolean | No | `true` | `true` | +| `shared` | Specifies whether the network resource can be accessed by any tenant or not. | Boolean | No | `false` | `false` | +| `tenantId` | Owner of network. Only admin users can specify a tenant ID other than their own. | String | No | Same as tenant creating the network | `123456` | + +You can create a network as shown in the following example: + +```php +$network = $networkingService->createNetwork(array( + 'name' => 'My private backend network' +)); +/** @var $network OpenCloud\Networking\Resource\Network **/ +``` + +[ [Get the executable PHP script for this example](/samples/Networking/create-network.php) ] + ### Create multiple networks +This operation takes one parameter, an indexed array. Each element of this array must +be an associative array with the keys shown in [the table above](#create-a-network). + +You can create multiple networks as shown in the following example: + +```php +$networks = $networkingService->createNetworks(array( + array( + 'name' => 'My private backend network #1' + ), + array( + 'name' => 'My private backend network #2' + ) +)); + +foreach ($networks as $network) { + /** @var $network OpenCloud\Networking\Resource\Network **/ +} +``` + +[ [Get the executable PHP script for this example](/samples/Networking/create-networks.php) ] + ### List networks +You can list all the networks to which you have access as shown in the following example: + +```php +$networks = $networkingService->listNetworks(); +foreach ($networks as $network) { + /** @var $network OpenCloud\Networking\Resource\Network **/ +} +``` + +[ [Get the executable PHP script for this example](/samples/Networking/list-networks.php) ] + ### Get network +You can retrieve a specific network by using that network's ID, as shown in the following example: + +```php +$network = $networkingService->getNetwork(getenv('NETWORK_ID')); +/** @var $network OpenCloud\Networking\Resource\Network **/ +``` + +[ [Get the executable PHP script for this example](/samples/Networking/get-network.php) ] + ### Update network +This operation takes one parameter, an associative array, with the following keys: + +| Name | Description | Data type | Required? | Default value | Example value | +| ---- | ----------- | --------- | --------- | ------------- | ------------- | +| `name` | Human-readable name for the network. Might not be unique. | String | No | `null` | `backend_network` | +| `adminStateUp` | The administrative state of network. If `false` (down), the network does not forward packets. | Boolean | No | `true` | `true` | +| `shared` | Specifies whether the network resource can be accessed by any tenant or not. | Boolean | No | `false` | `false` | + +You can update a network as shown in the following example: + +```php +$network->update(array( + 'name' => 'My updated private backend network' +)); +``` + +[ [Get the executable PHP script for this example](/samples/Networking/update-network.php) ] + ### Delete network +You can delete a network as shown in the following example: + +```php +$network->delete(); +``` + +[ [Get the executable PHP script for this example](/samples/Networking/delete-network.php) ] + ## Subnets ### Create a subnet From 2c6c25aa6dac41b2843b8cc83bc914501c3badb5 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 17:58:43 -0800 Subject: [PATCH 25/32] Using better sample names and IDs. --- docs/userguide/Networking/USERGUIDE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/userguide/Networking/USERGUIDE.md b/docs/userguide/Networking/USERGUIDE.md index b55783b56..8716c3c3e 100644 --- a/docs/userguide/Networking/USERGUIDE.md +++ b/docs/userguide/Networking/USERGUIDE.md @@ -99,7 +99,7 @@ This operation takes one parameter, an associative array, with the following key | Name | Description | Data type | Required? | Default value | Example value | | ---- | ----------- | --------- | --------- | ------------- | ------------- | -| `name` | Human-readable name for the network. Might not be unique. | String | No | `null` | `backend_network` | +| `name` | Human-readable name for the network. Might not be unique. | String | No | `null` | `My private backend network` | | `adminStateUp` | The administrative state of network. If `false` (down), the network does not forward packets. | Boolean | No | `true` | `true` | | `shared` | Specifies whether the network resource can be accessed by any tenant or not. | Boolean | No | `false` | `false` | | `tenantId` | Owner of network. Only admin users can specify a tenant ID other than their own. | String | No | Same as tenant creating the network | `123456` | @@ -157,7 +157,7 @@ foreach ($networks as $network) { You can retrieve a specific network by using that network's ID, as shown in the following example: ```php -$network = $networkingService->getNetwork(getenv('NETWORK_ID')); +$network = $networkingService->getNetwork('eb60583c-57ea-41b9-8d5c-8fab2d22224c'); /** @var $network OpenCloud\Networking\Resource\Network **/ ``` @@ -169,7 +169,7 @@ This operation takes one parameter, an associative array, with the following key | Name | Description | Data type | Required? | Default value | Example value | | ---- | ----------- | --------- | --------- | ------------- | ------------- | -| `name` | Human-readable name for the network. Might not be unique. | String | No | `null` | `backend_network` | +| `name` | Human-readable name for the network. Might not be unique. | String | No | `null` | `My updated private backend network` | | `adminStateUp` | The administrative state of network. If `false` (down), the network does not forward packets. | Boolean | No | `true` | `true` | | `shared` | Specifies whether the network resource can be accessed by any tenant or not. | Boolean | No | `false` | `false` | From 37b24dbb74cfd9fd2b05a807e827ea03103efbbb Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 17:59:15 -0800 Subject: [PATCH 26/32] Fleshing out user guide section on Subnets. --- docs/userguide/Networking/USERGUIDE.md | 101 +++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/docs/userguide/Networking/USERGUIDE.md b/docs/userguide/Networking/USERGUIDE.md index 8716c3c3e..af7d310aa 100644 --- a/docs/userguide/Networking/USERGUIDE.md +++ b/docs/userguide/Networking/USERGUIDE.md @@ -195,18 +195,119 @@ $network->delete(); ## Subnets +A subnet represents an IP address block that can be used to assign IP addresses to virtual instances (such as servers created using the Compute service). Each subnet must have a CIDR and must be associated with a network. + ### Create a subnet +This operation takes one parameter, an associative array, with the following keys: + +| Name | Description | Data type | Required? | Default value | Example value | +| ---- | ----------- | --------- | --------- | ------------- | ------------- | +| `networkId` | Network this subnet is associated with | String | Yes | - | `eb60583c-57ea-41b9-8d5c-8fab2d22224c` | +| `ipVersion` | IP version | Integer (`4` or `6`) | Yes | - | `4` | +| `cidr` | CIDR representing IP range for this subnet | String (CIDR) | Yes | - | `192.168.199.0/25` | +| `name` | Human-readable name for the subnet. Might not be unique. | String | No | `null` | `My subnet` | +| `gatewayIp` | IP address of the default gateway used by devices on this subnet | String (IP address) | No | First IP address in CIDR | `192.168.199.128` | +| `dnsNameservers` | DNS nameservers used by hosts in this subnet | Indexed array of strings | No | Empty array | `array('4.4.4.4', '8.8.8.8')` | +| `allocationPools` | Sub-ranges of CIDR available for dynamic allocation to ports | Indexed array of associative arrays | No | Every IP address in CIDR, excluding gateway IP address if configured | `array(array('start' => '192.168.199.2', 'end' => '192.168.199.127'))` | +| `hostRoutes` | Routes that should be used by devices with IPs from this subnet (not including local subnet route) | Indexed array of associative arrays | No | Empty array | `array(array('destination' => '1.1.1.0/24', 'nexthop' => '192.168.19.20'))` | +| `enableDhcp` | Specifies whether DHCP is enabled for this subnet or not | Boolean | No | `true` | `false` | +| `tenantId` | Owner of subnet. Only admin users can specify a tenant ID other than their own. | String | No | Same as tenant creating the subnet | `123456` | + +You can create a subnet as shown in the following example: + +```php +$subnet = $networkingService->createSubnet(array( + 'name' => 'My subnet', + 'networkId' => 'eb60583c-57ea-41b9-8d5c-8fab2d22224c', + 'ipVersion' => 4, + 'cidr' => '192.168.199.0/25' +)); +/** @var $subnet OpenCloud\Networking\Resource\Subnet **/ +``` + +[ [Get the executable PHP script for this example](/samples/Networking/create-subnet.php) ] + ### Create multiple subnets +This operation takes one parameter, an indexed array. Each element of this array must +be an associative array with the keys shown in [the table above](#create-a-subnet). + +You can create multiple subnets as shown in the following example: + +```php +$subnets = $networkingService->createSubnets(array( + array( + 'name' => 'My subnet #1' + ), + array( + 'name' => 'My subnet #2' + ) +)); + +foreach ($subnets as $subnet) { + /** @var $subnet OpenCloud\Networking\Resource\Subnet **/ +} +``` + +[ [Get the executable PHP script for this example](/samples/Networking/create-subnets.php) ] + ### List subnets +You can list all the subnets to which you have access as shown in the following example: + +```php +$subnets = $networkingService->listSubnets(); +foreach ($subnets as $subnet) { + /** @var $subnet OpenCloud\Networking\Resource\Subnet **/ +} +``` + +[ [Get the executable PHP script for this example](/samples/Networking/list-subnets.php) ] + ### Get subnet +You can retrieve a specific subnet by using that subnet's ID, as shown in the following example: + +```php +$subnet = $networkingService->getSubnet('d3f15879-fb11-49bd-a30b-7704fb98ab1e'); +/** @var $subnet OpenCloud\Networking\Resource\Subnet **/ +``` + +[ [Get the executable PHP script for this example](/samples/Networking/get-subnet.php) ] + ### Update subnet +This operation takes one parameter, an associative array, with the following keys: + +| Name | Description | Data type | Required? | Default value | Example value | +| ---- | ----------- | --------- | --------- | ------------- | ------------- | +| `name` | Human-readable name for the subnet. Might not be unique. | String | No | `null` | `My subnet` | +| `gatewayIp` | IP address of the default gateway used by devices on this subnet | String (IP address) | No | First IP address in CIDR | `192.168.199.128` | +| `dnsNameservers` | DNS nameservers used by hosts in this subnet | Indexed array of strings | No | Empty array | `array('4.4.4.4', '8.8.8.8')` | +| `hostRoutes` | Routes that should be used by devices with IPs from this subnet (not including local subnet route) | Indexed array of associative arrays | No | Empty array | `array(array('destination' => '1.1.1.0/24', 'nexthop' => '192.168.19.20'))` | +| `enableDhcp` | Specifies whether DHCP is enabled for this subnet or not | Boolean | No | `true` | `false` | + +You can update a subnet as shown in the following example: + +```php +$subnet->update(array( + 'name' => 'My updated private backend subnet' +)); +``` + +[ [Get the executable PHP script for this example](/samples/Networking/update-subnet.php) ] + ### Delete subnet +You can delete a subnet as shown in the following example: + +```php +$subnet->delete(); +``` + +[ [Get the executable PHP script for this example](/samples/Networking/delete-subnet.php) ] + ## Ports ### Create a port From b756939550cf3011747fd21143b5dba6bd0efb6e Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 18:04:24 -0800 Subject: [PATCH 27/32] Trivial whitespace lint fixes. --- lib/OpenCloud/Networking/Resource/Network.php | 6 +++--- lib/OpenCloud/Networking/Resource/Port.php | 8 ++++---- lib/OpenCloud/Networking/Resource/Subnet.php | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/OpenCloud/Networking/Resource/Network.php b/lib/OpenCloud/Networking/Resource/Network.php index 4aedc52c1..8363b4d89 100644 --- a/lib/OpenCloud/Networking/Resource/Network.php +++ b/lib/OpenCloud/Networking/Resource/Network.php @@ -20,12 +20,12 @@ use OpenCloud\Common\Resource\PersistentResource; /** - * A network is an isolated virtual layer-2 broadcast domain that is typically - * reserved for the tenant who created it unless you configure the network to be + * A network is an isolated virtual layer-2 broadcast domain that is typically + * reserved for the tenant who created it unless you configure the network to be * shared. The network is the main entity in the Networking service. Ports ({@see * \OpenCloud\Networking\Resource\Port}) and subnets ({@see * \OpenCloud\Networking\Resource\Subnet}) are always associated with a network. - * + * * @see http://docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html#Network * * @package OpenCloud\Networking\Resource diff --git a/lib/OpenCloud/Networking/Resource/Port.php b/lib/OpenCloud/Networking/Resource/Port.php index c3c1bf243..484de675e 100644 --- a/lib/OpenCloud/Networking/Resource/Port.php +++ b/lib/OpenCloud/Networking/Resource/Port.php @@ -22,11 +22,11 @@ /** * A port represents a virtual switch port on a logical network switch, represented * by {@see \OpenCloud\Networking\Resource\Network}. Virtual instances (such as - * servers created using the {@see \OpenCloud\Compute\Service}) attach their - * interfaces into ports. The port also defines the MAC address and the IP + * servers created using the {@see \OpenCloud\Compute\Service}) attach their + * interfaces into ports. The port also defines the MAC address and the IP * address(es) to be assigned to the interfaces plugged into them. When IP addresses - * are associated to a port, this also implies the port is associated with a {@see - * \OpenCloud\Networking\Resource\Subnet}, as the IP address is taken from the + * are associated to a port, this also implies the port is associated with a {@see + * \OpenCloud\Networking\Resource\Subnet}, as the IP address is taken from the * allocation pool for a specific subnet. * * @see http://docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html#Port diff --git a/lib/OpenCloud/Networking/Resource/Subnet.php b/lib/OpenCloud/Networking/Resource/Subnet.php index 8e52cc28a..5b15220f9 100644 --- a/lib/OpenCloud/Networking/Resource/Subnet.php +++ b/lib/OpenCloud/Networking/Resource/Subnet.php @@ -20,8 +20,8 @@ use OpenCloud\Common\Resource\PersistentResource; /** - * A subnet represents an IP address block that can be used to assign IP - * addresses to virtual instances (such as servers created using the {@see + * A subnet represents an IP address block that can be used to assign IP + * addresses to virtual instances (such as servers created using the {@see * \OpenCloud\Compute\Service}. Each subnet must have a CIDR and must be * associated with a network. * From cba317a75cdbdc2f6fa652e40a1c9a592e89e8b3 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 18:28:25 -0800 Subject: [PATCH 28/32] Making examples values in subnet parameters table consistent with sample code. --- docs/userguide/Networking/USERGUIDE.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/userguide/Networking/USERGUIDE.md b/docs/userguide/Networking/USERGUIDE.md index af7d310aa..bd5b8151c 100644 --- a/docs/userguide/Networking/USERGUIDE.md +++ b/docs/userguide/Networking/USERGUIDE.md @@ -282,17 +282,24 @@ This operation takes one parameter, an associative array, with the following key | Name | Description | Data type | Required? | Default value | Example value | | ---- | ----------- | --------- | --------- | ------------- | ------------- | -| `name` | Human-readable name for the subnet. Might not be unique. | String | No | `null` | `My subnet` | -| `gatewayIp` | IP address of the default gateway used by devices on this subnet | String (IP address) | No | First IP address in CIDR | `192.168.199.128` | +| `name` | Human-readable name for the subnet. Might not be unique. | String | No | `null` | `My updated subnet` | +| `gatewayIp` | IP address of the default gateway used by devices on this subnet | String (IP address) | No | First IP address in CIDR | `192.168.62.155` | | `dnsNameservers` | DNS nameservers used by hosts in this subnet | Indexed array of strings | No | Empty array | `array('4.4.4.4', '8.8.8.8')` | -| `hostRoutes` | Routes that should be used by devices with IPs from this subnet (not including local subnet route) | Indexed array of associative arrays | No | Empty array | `array(array('destination' => '1.1.1.0/24', 'nexthop' => '192.168.19.20'))` | +| `hostRoutes` | Routes that should be used by devices with IPs from this subnet (not including local subnet route) | Indexed array of associative arrays | No | Empty array | `array(array('destination' => '1.1.1.0/24', 'nexthop' => '192.168.17.19'))` | | `enableDhcp` | Specifies whether DHCP is enabled for this subnet or not | Boolean | No | `true` | `false` | You can update a subnet as shown in the following example: ```php $subnet->update(array( - 'name' => 'My updated private backend subnet' + 'name' => 'My updated subnet', + 'hostRoutes' => array( + array( + 'destination' => '1.1.1.0/24', + 'nexthop' => '192.168.17.19' + ) + ), + 'gatewayIp' => '192.168.62.155' )); ``` From b8c4aeec82c8f2186704287049e3302f5125e34e Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 18:29:21 -0800 Subject: [PATCH 29/32] Fleshing out user guide section on Ports. --- docs/userguide/Networking/USERGUIDE.md | 108 ++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/docs/userguide/Networking/USERGUIDE.md b/docs/userguide/Networking/USERGUIDE.md index bd5b8151c..559eefc5b 100644 --- a/docs/userguide/Networking/USERGUIDE.md +++ b/docs/userguide/Networking/USERGUIDE.md @@ -317,14 +317,120 @@ $subnet->delete(); ## Ports +A port represents a virtual switch port on a logical network switch. Virtual instances (such as servers created using the Compute service) attach their interfaces into ports. The port also defines the MAC address and the IP address(es) to be assigned to the interfaces plugged into them. When IP addresses are associated to a port, this also implies the port is associated with a subet, as the IP address is taken from the allocation pool for a specific subnet. + ### Create a port +This operation takes one parameter, an associative array, with the following keys: + +| Name | Description | Data type | Required? | Default value | Example value | +| ---- | ----------- | --------- | --------- | ------------- | ------------- | +| `networkId` | Network this port is associated with | String | Yes | - | `eb60583c-57ea-41b9-8d5c-8fab2d22224c` | +| `name` | Human-readable name for the port. Might not be unique. | String | No | `null` | `My port` | +| `adminStateUp` | The administrative state of port. If `false` (down), the port does not forward packets. | Boolean | No | `true` | `true` | +| `macAddress` | MAC address to use on this port | String (MAC address in 6-octet form separated by colons) | No | Generated | `0F:5A:6F:70:E9:5C` | +| `fixedIps` | IP addresses for this port | Indexed array of associative arrays | No | Automatically allocated from pool | `array(array('subnetId' => '75906d20-6625-11e4-9803-0800200c9a66', 'ipAddress' => '192.168.199.17'))` | +| `deviceId` | Identifies the device (e.g. virtual server) using this port | String | No | `null` | `5e3898d7-11be-483e-9732-b2f5eccd2b2e` | +| `deviceOwner` | Identifies the entity (e.g. DHCP agent) using this port | String | No | `null` | `network:router_interface` | +| `securityGroups` | Specifies the IDs of any security groups associated with this port | Indexed array of strings | No | Empty array | `array('f0ac4394-7e4a-4409-9701-ba8be283dbc3')` | +| `tenantId` | Owner of port. Only admin users can specify a tenant ID other than their own. | String | No | Same as tenant creating the port | `123456` | + +You can create a port as shown in the following example: + +```php +$port = $networkingService->createPort(array( + 'name' => 'My port', + 'networkId' => 'eb60583c-57ea-41b9-8d5c-8fab2d22224c' +)); +/** @var $port OpenCloud\Networking\Resource\Port **/ +``` + +[ [Get the executable PHP script for this example](/samples/Networking/create-port.php) ] + ### Create multiple ports +This operation takes one parameter, an indexed array. Each element of this array must +be an associative array with the keys shown in [the table above](#create-a-port). + +You can create multiple ports as shown in the following example: + +```php +$ports = $networkingService->createPorts(array( + array( + 'name' => 'My port #1', + 'networkId' => 'eb60583c-57ea-41b9-8d5c-8fab2d22224c' + ), + array( + 'name' => 'My port #2', + 'networkId' => 'eb60583c-57ea-41b9-8d5c-8fab2d22224c' + ) +)); + +foreach ($ports as $port) { + /** @var $port OpenCloud\Networking\Resource\Port **/ +} +``` + +[ [Get the executable PHP script for this example](/samples/Networking/create-ports.php) ] + ### List ports +You can list all the ports to which you have access as shown in the following example: + +```php +$ports = $networkingService->listPorts(); +foreach ($ports as $port) { + /** @var $port OpenCloud\Networking\Resource\Port **/ +} +``` + +[ [Get the executable PHP script for this example](/samples/Networking/list-ports.php) ] + ### Get port +You can retrieve a specific port by using that port's ID, as shown in the following example: + +```php +$port = $networkingService->getPort('75906d20-6625-11e4-9803-0800200c9a66'); +/** @var $port OpenCloud\Networking\Resource\Port **/ +``` + +[ [Get the executable PHP script for this example](/samples/Networking/get-port.php) ] + ### Update port -### Delete port \ No newline at end of file +This operation takes one parameter, an associative array, with the following keys: + +| Name | Description | Data type | Required? | Default value | Example value | +| ---- | ----------- | --------- | --------- | ------------- | ------------- | +| `name` | Human-readable name for the port. Might not be unique. | String | No | `null` | `My port` | +| `adminStateUp` | The administrative state of port. If `false` (down), the port does not forward packets. | Boolean | No | `true` | `true` | +| `fixedIps` | IP addresses for this port | Indexed array of associative arrays | No | Automatically allocated from pool | `array(array('subnetId' => '75906d20-6625-11e4-9803-0800200c9a66', 'ipAddress' => '192.168.199.59'))` | +| `deviceId` | Identifies the device (e.g. virtual server) using this port | String | No | `null` | `5e3898d7-11be-483e-9732-b2f5eccd2b2e` | +| `deviceOwner` | Identifies the entity (e.g. DHCP agent) using this port | String | No | `null` | `network:router_interface` | +| `securityGroups` | Specifies the IDs of any security groups associated with this port | Indexed array of strings | No | Empty array | `array('f0ac4394-7e4a-4409-9701-ba8be283dbc3')` | + +You can update a port as shown in the following example: + +```php +$port->update(array( + 'fixedIps' => array( + array( + 'subnetId' => '75906d20-6625-11e4-9803-0800200c9a66', + 'ipAddress' => '192.168.199.59' + ) + ) +)); +``` + +[ [Get the executable PHP script for this example](/samples/Networking/update-port.php) ] + +### Delete port + +You can delete a port as shown in the following example: + +```php +$port->delete(); +``` + +[ [Get the executable PHP script for this example](/samples/Networking/delete-port.php) ] From 8d501424dbbd60887e0f7f299cd814fdfa8a4cdb Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 18:33:40 -0800 Subject: [PATCH 30/32] Trivial whitespace fix. --- docs/userguide/Networking/USERGUIDE.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/userguide/Networking/USERGUIDE.md b/docs/userguide/Networking/USERGUIDE.md index 559eefc5b..bea5ea173 100644 --- a/docs/userguide/Networking/USERGUIDE.md +++ b/docs/userguide/Networking/USERGUIDE.md @@ -1,7 +1,6 @@ # Complete User Guide for the Networking Service -Networking is a service that you can use to create virtual networks and attach cloud devices -such as servers to these networks. +Networking is a service that you can use to create virtual networks and attach cloud devices such as servers to these networks. This user guide will introduce you the entities in the Networking service — networks, subnets, and ports — as well as show you how to create and manage these entities. From 915a5794b65d536f15b2a994c950eb71f69a3b30 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 18:33:59 -0800 Subject: [PATCH 31/32] Adding quickstart README. --- docs/userguide/Networking/README.md | 76 +++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 docs/userguide/Networking/README.md diff --git a/docs/userguide/Networking/README.md b/docs/userguide/Networking/README.md new file mode 100644 index 000000000..ee1de981e --- /dev/null +++ b/docs/userguide/Networking/README.md @@ -0,0 +1,76 @@ +# Networking + +**Networking** is a service that you can use to create virtual networks and attach cloud devices such as servers to these networks. + +## Concepts + +## Concepts + +To use the Networking service effectively, you should understand the following key concepts: + +* **Network**: A network is an isolated virtual layer-2 broadcast domain that is typically reserved for the tenant who created it unless you configure the network to be shared. The network is the main entity in the Networking service. Ports and subnets are always associated with a network. + +* **Subnet**: A subnet represents an IP address block that can be used to assign IP addresses to virtual instances (such as servers created using the Compute service). Each subnet must have a CIDR and must be associated with a network. + +* **Port**: A port represents a virtual switch port on a logical network switch. Virtual instances (such as servers created using the Compute service) attach their interfaces into ports. The port also defines the MAC address and the IP address(es) to be assigned to the interfaces plugged into them. When IP addresses are associated to a port, this also implies the port is associated with a subet, as the IP address is taken from the allocation pool for a specific subnet. + + +## Getting started + +### 1. Instantiate an OpenStack or Rackspace client. + +To use the Networking service, you must first instantiate a `OpenStack` or `Rackspace` client object. + +* If you are working with an OpenStack cloud, instantiate an `OpenCloud\OpenStack` client as follows: + + ```php + use OpenCloud\OpenStack; + + $client = new OpenStack('', array( + 'username' => '', + 'password' => '' + )); + ``` + +* If you are working with the Rackspace cloud, instantiate a `OpenCloud\Rackspace` client as follows: + + ```php + use OpenCloud\Rackspace; + + $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array( + 'username' => '', + 'apiKey' => '' + )); + ``` + +### 2. Obtain an Networking service object from the client. +All Networking operations are done via an _networking service object_. To +instantiate this object, call the `networkingService` method on the `$client` +object. This method takes two arguments: + +| Position | Description | Data type | Required? | Default value | Example value | +| -------- | ----------- | ----------| --------- | ------------- | ------------- | +| 1 | Name of the service, as it appears in the service catalog | String | No | `null`; automatically determined when possible | `cloudNetworks` | +| 2 | Cloud region | String | Yes | - | `DFW` | + + +```php +$region = ''; +$networkingService = $client->networkingService(null, $region); +``` + +Any networks, subnets, and ports created with this `$networkingService` instance will +be stored in the cloud region specified by `$region`. + +### 3. Create a network. +```php +$network = $networkingService->createNetwork(array( + 'name' => 'My private backend network' +)); +``` + +[ [Get the executable PHP script for this example](/samples/Networking/create-network.php) ] + +## Next steps + +Once you have created a network, there is more you can do with it. See [complete user guide for networking](USERGUIDE.md). From 63d2e7222525f479241cd884bc7c8d88d7a32155 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 6 Nov 2014 18:48:40 -0800 Subject: [PATCH 32/32] Adding links to creation parameters' docs. --- lib/OpenCloud/Networking/Service.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/OpenCloud/Networking/Service.php b/lib/OpenCloud/Networking/Service.php index ee961af04..118ba4bde 100644 --- a/lib/OpenCloud/Networking/Service.php +++ b/lib/OpenCloud/Networking/Service.php @@ -48,7 +48,7 @@ public function network($id = null) /** * Creates a new Network and returns it. * - * @param array $params Network creation parameters + * @param array $params Network creation parameters. @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/Networking/USERGUIDE.md#create-a-network * @return \OpenCloud\Networking\Resource\Network Object representing created network */ public function createNetwork(array $params = array()) @@ -133,7 +133,7 @@ public function subnet($id = null) /** * Creates a new Subnet and returns it. * - * @param array $params Subnet creation parameters + * @param array $params Subnet creation parameters. @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/Networking/USERGUIDE.md#create-a-subnet * @return \OpenCloud\Networking\Resource\Subnet Object representing created subnet */ public function createSubnet(array $params = array()) @@ -218,7 +218,7 @@ public function port($id = null) /** * Creates a new Port and returns it. * - * @param array $params Port creation parameters + * @param array $params Port creation parameters. @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/Networking/USERGUIDE.md#create-a-port * @return \OpenCloud\Networking\Resource\Port Object representing created port */ public function createPort(array $params = array())