LibCloud\Compute\Providers\Rackspace\RackspaceProvider::updateNode PHP Метод

updateNode() публичный Метод

public updateNode ( Node $node, Symfony\Component\HttpFoundation\ParameterBag $parameters ) : Guzzle\Http\Message\Response
$node LibCloud\Compute\Model\Node
$parameters Symfony\Component\HttpFoundation\ParameterBag
Результат Guzzle\Http\Message\Response
    public function updateNode(Node $node, ParameterBag $parameters)
    {
        $allowableParamKeys = array('name', 'accessIPv4', 'accessIPv6');
        $requestedParamKeys = $parameters->keys();
        if (0 == sizeof($requestedParamKeys)) {
            throw new \UnexpectedValueException(sprintf('Expected values for any of the following properties, but got none: "%s".', implode(', ', $allowableParamKeys)));
        }
        $permittedKeys = array_intersect($requestedParamKeys, $allowableParamKeys);
        $prohibitedKeys = array_diff($requestedParamKeys, $permittedKeys);
        if (sizeof($prohibitedKeys)) {
            throw new \UnexpectedValueException(sprintf('Expected values for any of the following properties "%s". ' . 'The following requested properties are not allowed: "%s".', implode(', ', $allowableParamKeys), implode(', ', $prohibitedKeys)));
        }
        $updates = array();
        foreach ($permittedKeys as $k) {
            $updates[$k] = $parameters->get($k);
        }
        $response = $this->toServer($node)->update($updates);
        # It would be nice to have an updateNodeFromServer so that the caller
        # gets the updates (which $server now has) for their Node. For now, just
        # send some more API requests...
        $nodes = $this->listNodes($node->getId());
        # and update the few properties that might have changed
        $node->setName($nodes[0]->getName());
        $node->setPublicIps($nodes[0]->getPublicIps());
        $node->setState($nodes[0]->getState());
        $node->setExtra($nodes[0]->getExtra());
        return $response;
    }

Usage Example

 /**
  * @depends testListNodesWithId
  */
 public function testUpdateNodeWithAllowedProperties($node)
 {
     $this->addMockSubscriber($this->getTestFilePath('Server'));
     $this->addMockSubscriber($this->getTestFilePath('Server_Meta'));
     $this->addMockSubscriber($this->getTestFilePath('Server_Update'));
     $this->addMockSubscriber($this->getTestFilePath('Server_Update'));
     $this->addMockSubscriber($this->getTestFilePath('Server_Meta'));
     $r = $this->provider->updateNode($node, new ParameterBag(array('name' => 'test-2-sauuucy', 'accessIPv4' => '203.0.113.187', 'accessIPv6' => '2001:DB8:dead:bea7:dead:900d:dead:1337')));
     $this->assertSame(200, $r->getStatusCode(), 'updateNode returns the API response for the successful update operation');
     $properties = json_decode($r->getBody(true));
     $this->assertSame('test-2-sauuucy', $node->getName(), 'updateNode successfully updated the Node name');
     $this->assertEquals(array(array('version' => 4, 'addr' => '203.0.113.187'), array('version' => 6, 'addr' => '2001:DB8:dead:bea7:dead:900d:dead:1337')), $node->getPublicIps(), 'updateNode successfully updated the Node publicIps');
 }