Linode   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 58
c 1
b 0
f 0
dl 0
loc 72
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __get() 0 10 1
1
<?php
2
3
// ---------------------------------------------------------------------
4
//
5
//  Copyright (C) 2018-2024 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <https://opensource.org/licenses/MIT>.
9
//
10
// ---------------------------------------------------------------------
11
12
namespace Linode\LinodeInstances;
13
14
use Linode\Entity;
15
use Linode\LinodeInstances\Repository\BackupRepository;
16
use Linode\LinodeInstances\Repository\DiskRepository;
17
use Linode\LinodeInstances\Repository\LinodeConfigRepository;
18
19
/**
20
 * A Linode instance.
21
 *
22
 * @property int                             $id               This Linode's ID which must be provided for all operations impacting this Linode.
23
 * @property string                          $label            The Linode's label is for display purposes only. If no label is provided for a
24
 *                                                             Linode,
25
 *                                                             a default will be assigned.
26
 *                                                             Linode labels have the following constraints:
27
 *                                                             * Must begin and end with an alphanumeric character.
28
 *                                                             * May only consist of alphanumeric characters, hyphens (`-`), underscores (`_`)
29
 *                                                             or periods (`.`).
30
 *                                                             * Cannot have two hyphens (`--`), underscores (`__`) or periods (`..`) in a row.
31
 * @property string                          $region           This is the Region where the Linode was deployed. A Linode's region can only be
32
 *                                                             changed by initiating a cross data center migration.
33
 * @property string                          $type             This is the Linode Type that this Linode was deployed with.
34
 *                                                             To change a Linode's Type, use POST /linode/instances/{linodeId}/resize.
35
 * @property null|string                     $image            An Image ID to deploy the Disk from. Official Linode Images start with `linode/ `,
36
 *                                                             while your Images start with `private/`.
37
 * @property string                          $status           A brief description of this Linode's current state. This field may change without
38
 *                                                             direct action from you. For example, when a Linode goes into maintenance mode its
39
 *                                                             status will display "stopped".
40
 * @property string[]                        $ipv4             This Linode's IPv4 Addresses. Each Linode is assigned a single public IPv4 address
41
 *                                                             upon creation, and may get a single private IPv4 address if needed. You may need
42
 *                                                             to
43
 *                                                             open a support ticket
44
 *                                                             to get additional IPv4 addresses.
45
 *                                                             IPv4 addresses may be reassigned between your Linodes, or shared with other
46
 *                                                             Linodes.
47
 *                                                             See the /networking endpoints for details.
48
 * @property null|string                     $ipv6             This Linode's IPv6 SLAAC address. This address is specific to a Linode, and may
49
 *                                                             not be shared. If the Linode has not been assigned an IPv6 address, the return
50
 *                                                             value will be `null`.
51
 * @property string                          $group            A deprecated property denoting a group label for this Linode.
52
 * @property string[]                        $tags             An array of tags applied to this object. Tags are for organizational purposes
53
 *                                                             only.
54
 * @property string                          $hypervisor       The virtualization software powering this Linode.
55
 * @property bool                            $watchdog_enabled The watchdog, named Lassie, is a Shutdown Watchdog that monitors your Linode and
56
 *                                                             will reboot it if it powers off unexpectedly. It works by issuing a boot job when
57
 *                                                             your Linode powers off without a shutdown job being responsible.
58
 *                                                             To prevent a loop, Lassie will give up if there have been more than 5 boot jobs
59
 *                                                             issued within 15 minutes.
60
 * @property string                          $created          When this Linode was created.
61
 * @property string                          $updated          When this Linode was last updated.
62
 * @property LinodeSpecs                     $specs            Information about the resources available to this Linode.
63
 * @property LinodeAlerts                    $alerts           Information about this Linode's notification thresholds.
64
 * @property LinodeBackups                   $backups          Information about this Linode's backups status. For information about available
65
 *                                                             backups, see /linode/instances/{linodeId}/backups.
66
 * @property string                          $host_uuid        The Linode's host machine, as a UUID.
67
 * @property bool                            $has_user_data    Whether this compute instance was provisioned utilizing `user_data` provided via
68
 *                                                             the Metadata service. See the Linode Create description for more information on
69
 *                                                             Metadata.
70
 * @property BackupRepositoryInterface       $linodeBackups    Linode backups.
71
 * @property DiskRepositoryInterface         $linodeDisks      Linode disks.
72
 * @property LinodeConfigRepositoryInterface $linodeConfigs    Linode configs.
73
 */
74
class Linode extends Entity
75
{
76
    // Available fields.
77
    public const FIELD_ID               = 'id';
78
    public const FIELD_LABEL            = 'label';
79
    public const FIELD_REGION           = 'region';
80
    public const FIELD_TYPE             = 'type';
81
    public const FIELD_IMAGE            = 'image';
82
    public const FIELD_STATUS           = 'status';
83
    public const FIELD_IPV4             = 'ipv4';
84
    public const FIELD_IPV6             = 'ipv6';
85
    public const FIELD_GROUP            = 'group';
86
    public const FIELD_TAGS             = 'tags';
87
    public const FIELD_HYPERVISOR       = 'hypervisor';
88
    public const FIELD_WATCHDOG_ENABLED = 'watchdog_enabled';
89
    public const FIELD_CREATED          = 'created';
90
    public const FIELD_UPDATED          = 'updated';
91
    public const FIELD_SPECS            = 'specs';
92
    public const FIELD_ALERTS           = 'alerts';
93
    public const FIELD_BACKUPS          = 'backups';
94
    public const FIELD_HOST_UUID        = 'host_uuid';
95
    public const FIELD_HAS_USER_DATA    = 'has_user_data';
96
97
    // Extra fields for POST/PUT requests.
98
    public const FIELD_ALLOW_AUTO_DISK_RESIZE = 'allow_auto_disk_resize';
99
    public const FIELD_BACKUPS_ENABLED        = 'backups_enabled';
100
    public const FIELD_BOOTED                 = 'booted';
101
    public const FIELD_PRIVATE_IP             = 'private_ip';
102
    public const FIELD_ROOT_PASS              = 'root_pass';
103
    public const FIELD_SWAP_SIZE              = 'swap_size';
104
    public const FIELD_AUTHORIZED_KEYS        = 'authorized_keys';
105
    public const FIELD_AUTHORIZED_USERS       = 'authorized_users';
106
    public const FIELD_STACKSCRIPT_ID         = 'stackscript_id';
107
    public const FIELD_STACKSCRIPT_DATA       = 'stackscript_data';
108
    public const FIELD_BACKUP_ID              = 'backup_id';
109
    public const FIELD_CONFIG_ID              = 'config_id';
110
    public const FIELD_LINODE_ID              = 'linode_id';
111
    public const FIELD_CONFIGS                = 'configs';
112
    public const FIELD_DEVICES                = 'devices';
113
    public const FIELD_DISKS                  = 'disks';
114
115
    // `FIELD_STATUS` values.
116
    public const STATUS_RUNNING            = 'running';
117
    public const STATUS_OFFLINE            = 'offline';
118
    public const STATUS_BOOTING            = 'booting';
119
    public const STATUS_REBOOTING          = 'rebooting';
120
    public const STATUS_SHUTTING_DOWN      = 'shutting_down';
121
    public const STATUS_PROVISIONING       = 'provisioning';
122
    public const STATUS_DELETING           = 'deleting';
123
    public const STATUS_MIGRATING          = 'migrating';
124
    public const STATUS_REBUILDING         = 'rebuilding';
125
    public const STATUS_CLONING            = 'cloning';
126
    public const STATUS_RESTORING          = 'restoring';
127
    public const STATUS_STOPPED            = 'stopped';
128
    public const STATUS_BILLING_SUSPENSION = 'billing_suspension';
129
130
    // `FIELD_HYPERVISOR` values.
131
    public const HYPERVISOR_KVM = 'kvm';
132
133
    /**
134
     * @codeCoverageIgnore This method was autogenerated.
135
     */
136
    public function __get(string $name): mixed
137
    {
138
        return match ($name) {
139
            self::FIELD_SPECS   => new LinodeSpecs($this->client, $this->data[$name]),
140
            self::FIELD_ALERTS  => new LinodeAlerts($this->client, $this->data[$name]),
141
            self::FIELD_BACKUPS => new LinodeBackups($this->client, $this->data[$name]),
142
            'linodeBackups'     => new BackupRepository($this->client, $this->id),
143
            'linodeDisks'       => new DiskRepository($this->client, $this->id),
144
            'linodeConfigs'     => new LinodeConfigRepository($this->client, $this->id),
145
            default             => parent::__get($name),
146
        };
147
    }
148
}
149