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 Stephen Sugden <openstack@stephensugden.com>
8: */
9:
10: namespace OpenCloud\Orchestration;
11:
12: use OpenCloud\AbstractClass\PersistentObject;
13:
14: /**
15: * @codeCoverageIgnore
16: */
17: class Resource extends PersistentObject
18: {
19:
20: protected $links;
21: protected $logical_resource_id;
22: protected $physical_resource_id;
23: protected $resource_status;
24: protected $resource_status_reason;
25: protected $resource_type;
26: protected $updated_time;
27:
28: protected static $url_resource = 'resources';
29: protected static $json_name = 'resource';
30:
31: public function create($info = null)
32: {
33: $this->noCreate();
34: }
35:
36: public function id()
37: {
38: return $this->physical_resource_id;
39: }
40:
41: protected function primaryKeyField()
42: {
43: return 'physical_resource_id';
44: }
45:
46: public function name()
47: {
48: return $this->logical_resource_id;
49: }
50:
51: public function type()
52: {
53: return $this->resource_type;
54: }
55:
56: public function status()
57: {
58: return $this->resource_status;
59: }
60:
61: public function get()
62: {
63: $service = $this->getParent()->getService();
64:
65: switch ($this->resource_type) {
66: case 'AWS::EC2::Instance':
67: $objSvc = 'Compute';
68: $method = 'Server';
69: $name = 'nova';
70: break;
71: default:
72: throw new Exception(sprintf(
73: 'Unknown resource type: %s',
74: $this->resource_type
75: ));
76: }
77:
78: return $service->connection()->$objSvc($name, $service->region())->$method($this->id());
79: }
80: }
81: