DNS.php
3.38 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* PHP OpenCloud library.
*
* @copyright 2014 Rackspace Hosting, Inc. See LICENSE for information.
* @license https://www.apache.org/licenses/LICENSE-2.0
* @author Jamie Hannaford <jamie.hannaford@rackspace.com>
*/
namespace OpenCloud\Smoke\Unit;
use OpenCloud\Smoke\Enum;
class DNS extends AbstractUnit implements UnitInterface
{
public function setupService()
{
return $this->getConnection()->dnsService();
}
public function main()
{
$domainName = 'domain-' . time() . '.com';
// Add a domain
$this->step('Try to add a domain %s', $domainName);
$domain = $this->getService()->domain();
$domain->addRecord($domain->record(array(
'ttl' => 5771,
'name' => 'foo.' . $domainName,
'type' => 'A',
'data' => '192.0.2.8'
)));
$asyncResponse = $domain->create(array(
'name' => $domainName,
'emailAddress' => 'jamie.hannaford@rackspace.com',
'ttl' => 3600
));
$asyncResponse->waitFor('COMPLETED', 300, $this->getWaiterCallback(), 1);
if ($asyncResponse->Status() == 'ERROR') {
$this->stepInfo(
'Error: [%d] %s - %s',
$asyncResponse->error->code,
$asyncResponse->error->message,
$asyncResponse->error->details
);
}
// Add a CNAME
$this->step("Adding a CNAME record www.%s", $domainName);
$domains = $this->getService()->domainList(array('name' => $domainName));
$domain = $domains->getElement(0);
$record = $domain->record();
$asyncResponse = $record->create(array(
'type' => 'CNAME',
'ttl' => 600,
'name' => 'www.'. $domainName,
'data' => 'developer.rackspace.com'
));
$asyncResponse->waitFor('COMPLETED', 300, $this->getWaiterCallback(), 1);
if ($asyncResponse->status() == 'ERROR') {
$this->stepInfo(
'Error: [%d] $s - %s',
$asyncResponse->error->code,
$asyncResponse->error->message,
$asyncResponse->error->details
);
}
$records = $domain->recordList();
foreach ($records as $record) {
$record->update(array('name' => 'something-else.com'));
}
// List everything
$this->step('List domains and records');
$domains = $this->getService()->domainList();
$domains->setOption('limit.total', Enum::DISPLAY_ITER_LIMIT);
foreach ($domains as $domain) {
$this->stepInfo('%s [%s]', $domain->name(), $domain->emailAddress);
$step = $this->stepInfo('Domain Records:');
$records = $domain->recordList();
foreach ($records as $record) {
$step->stepInfo(
'- %s %d %s %s',
$record->type,
$record->ttl,
$record->name(),
$record->data
);
}
}
}
public function teardown()
{
$domains = $this->getService()->domainList();
foreach ($domains as $domain) {
if ($this->shouldDelete($domain->name())) {
$domain->delete();
}
}
}
}