Overview

Namespaces

  • None
  • OpenCloud
    • Autoscale
      • Resource
    • CloudMonitoring
      • Exception
      • Resource
    • Common
      • Exceptions
      • Log
      • Request
        • Response
    • Compute
    • Database
    • DNS
    • LoadBalancer
      • Resources
    • ObjectStore
      • Resource
    • Orchestration
    • Volume
  • PHP

Classes

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