Overview

Namespaces

  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Collection
      • Constants
      • Exceptions
      • Http
        • Message
      • Identity
      • Log
      • Service
    • Compute
      • Constants
      • Exception
      • Resource
    • Database
      • Resource
    • DNS
      • Resource
    • LoadBalancer
      • Resource
    • ObjectStore
      • Constants
      • Exception
      • Resource
      • Upload
    • Orchestration
    • Queues
      • Exception
      • Resource
    • Volume
      • Resource
  • PHP

Classes

  • Flavor
  • Image
  • KeyPair
  • Network
  • Server
  • ServerMetadata
  • VolumeAttachment
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
  1: <?php
  2: /**
  3:  * PHP OpenCloud library.
  4:  * 
  5:  * @copyright 2013 Rackspace Hosting, Inc. See LICENSE for information.
  6:  * @license   https://www.apache.org/licenses/LICENSE-2.0
  7:  * @author    Glen Campbell <glen.campbell@rackspace.com>
  8:  * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
  9:  */
 10: 
 11: namespace OpenCloud\Compute\Resource;
 12: 
 13: use OpenCloud\Common\PersistentObject;
 14: use OpenCloud\Common\Lang;
 15: use OpenCloud\Common\Exceptions;
 16: use OpenCloud\Compute\Service;
 17: use OpenCloud\Compute\Constants\Network as NetworkConst;
 18: 
 19: /**
 20:  * The Network class represents a single virtual network
 21:  */
 22: class Network extends PersistentObject 
 23: {
 24: 
 25:     public $id;
 26:     public $label;
 27:     public $cidr;
 28:     
 29:     protected static $json_name = 'network';
 30:     protected static $url_resource = 'os-networksv2';
 31: 
 32:     /**
 33:      * Creates a new isolated Network object
 34:      *
 35:      * NOTE: contains hacks to recognize the Rackspace public and private
 36:      * networks. These are not really networks, but they show up in lists.
 37:      *
 38:      * @param \OpenCloud\Compute $service The compute service associated with
 39:      *      the network
 40:      * @param string $id The ID of the network (this handles the pseudo-networks
 41:      *      Network::RAX_PUBLIC and Network::RAX_PRIVATE
 42:      * @return void
 43:      */
 44:     public function __construct(Service $service, $id = null) 
 45:     {
 46:         $this->id = $id;
 47: 
 48:         switch ($id) {
 49:             case NetworkConst::RAX_PUBLIC:
 50:                 $this->label = 'public';
 51:                 $this->cidr = 'NA';
 52:                 break;
 53:             case NetworkConst::RAX_PRIVATE:
 54:                 $this->label = 'private';
 55:                 $this->cidr = 'NA';
 56:                 break;
 57:             default:
 58:                 return parent::__construct($service, $id);
 59:         }
 60:         
 61:         return;
 62:     }
 63: 
 64:     /**
 65:      * Always throws an error; updates are not permitted
 66:      *
 67:      * @throws NetworkUpdateError always
 68:      */
 69:     public function update($params = array()) 
 70:     {
 71:         throw new Exceptions\NetworkUpdateError('Isolated networks cannot be updated');
 72:     }
 73: 
 74:     /**
 75:      * Deletes an isolated network
 76:      *
 77:      * @api
 78:      * @return \OpenCloud\HttpResponse
 79:      * @throws NetworkDeleteError if HTTP status is not Success
 80:      */
 81:     public function delete() 
 82:     {
 83:         switch ($this->id) {
 84:             case NetworkConst::RAX_PUBLIC:
 85:             case NetworkConst::RAX_PRIVATE:
 86:                 throw new Exceptions\DeleteError('Network may not be deleted');
 87:             default:
 88:                 return parent::delete();
 89:         }
 90:     }
 91:     
 92:     /**
 93:      * returns the visible name (label) of the network
 94:      *
 95:      * @api
 96:      * @return string
 97:      */
 98:     public function name() 
 99:     {
100:         return $this->label;
101:     }
102: 
103:     /**
104:      * Creates the JSON object for the Create() method
105:      */
106:     protected function createJson() 
107:     {
108:         return (object) array(
109:             'network' => (object) array(
110:                 'cidr'  => $this->cidr,
111:                 'label' => $this->label
112:             )
113:         );
114:     }
115: 
116: }
117: 
PHP OpenCloud API API documentation generated by ApiGen 2.8.0