Blame view

sources/3rdparty/rackspace/php-opencloud/docs/userguide/Compute/Keypair.md 2.02 KB
6d9380f96   Cédric Dupont   Update sources OC...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  # Keypairs
  
  ## Generate new keypair
  
  This operation creates a new keypair under a provided name; the public key value is automatically generated for you.
  
  ```php
  $keypair = $service->keypair();
  
  $keypair->create(array(
     'name' => 'jamie_keypair_1'
  ));
  
  echo $keypair->getPublicKey();
  ```
  
  ## Upload existing keypair
  
  This operation creates a new keypair under a provided name using a provided public key value. This public key will probably exist on your local filesystem, and so provide easy access to your server when uploaded.
  
  ```php
  $keypair = $service->keypair();
  
  $key = <<<EOT
  ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Example public key
  EOT;
  
  $keypair->create(array(
     'name'      => 'jamie_macbook',
     'publicKey' => $key
  ));
  
  ```
  
  ## List keypairs
  
  To list all existing keypairs:
  
  ```php
  $keys = $service->listKeypairs();
  
  foreach ($keys as $key) {
     // ...
  }
  ```
  
  For more information about iterators, please see [the docs](../Iterators.md).
  
  ## Delete keypairs
  
  To delete a specific keypair:
  
  ```php
  $keypair->delete();
  ```
  
  ## Creating a server with a keypair
  
  In order to spawn an instance with a saved keypair (allowing you to SSH in without passwords), you create your server
  using the same operation as usual, with one extra parameter:
  
  ```php
  use Guzzle\Http\Exception\BadResponseException;
  use OpenCloud\Compute\Constants\Network;
  
  $server = $compute->server();
  
  try {
      $response = $server->create(array(
          'name'     => 'New server',
          'image'    => $ubuntuImage,
          'flavor'   => $twoGbFlavor,
          'networks' => array(
              $compute->network(Network::RAX_PUBLIC),
              $compute->network(Network::RAX_PRIVATE)
          ),
          'keypair' => 'jamie_macbook'
      ));
  } catch (BadResponseException $e) {
     // error...
  }
  ```
  
  So, as you can see, you specify the **name** of an existing keypair that you previously created on the API.