本文整理汇总了PHP中DBServer::LoadByPropertyValue方法的典型用法代码示例。如果您正苦于以下问题:PHP DBServer::LoadByPropertyValue方法的具体用法?PHP DBServer::LoadByPropertyValue怎么用?PHP DBServer::LoadByPropertyValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBServer
的用法示例。
在下文中一共展示了DBServer::LoadByPropertyValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xCreateAction
public function xCreateAction()
{
$this->request->defineParams(array('volumeId', 'cloudLocation'));
$aws = $this->getEnvironment()->aws($this->getParam('cloudLocation'));
$snapshot = $aws->ec2->snapshot->create($this->getParam('volumeId'));
if (isset($snapshot->snapshotId)) {
/* @var $volume \Scalr\Service\Aws\Ec2\DataType\VolumeData */
$volume = $aws->ec2->volume->describe($snapshot->volumeId)->get(0);
if (count($volume->attachmentSet) && !empty($volume->attachmentSet[0]->instanceId)) {
$instanceId = $volume->attachmentSet[0]->instanceId;
try {
$dBServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $instanceId);
$dBFarm = $dBServer->GetFarmObject();
} catch (Exception $e) {
}
if (isset($dBServer) && isset($dBFarm)) {
$comment = sprintf(_("Created on farm '%s', server '%s' (Instance ID: %s)"), $dBFarm->Name, $dBServer->serverId, $instanceId);
}
} else {
$comment = '';
}
$this->db->Execute("\n INSERT INTO ebs_snaps_info\n SET snapid = ?,\n comment = ?,\n dtcreated = NOW(),\n region = ?\n ", array($snapshot->snapshotId, $comment, $this->getParam('cloudLocation')));
$this->response->data(array('data' => array('snapshotId' => $snapshot->snapshotId)));
} else {
throw new Exception("Unable to create snapshot. Please try again later.");
}
}
示例2: xListVolumesAction
public function xListVolumesAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'volumeId', 'direction' => 'ASC')), 'volumeId'));
$csClient = Scalr_Service_Cloud_Cloudstack::newCloudstack($this->environment->getPlatformConfigValue(Modules_Platforms_Cloudstack::API_URL), $this->environment->getPlatformConfigValue(Modules_Platforms_Cloudstack::API_KEY), $this->environment->getPlatformConfigValue(Modules_Platforms_Cloudstack::SECRET_KEY));
$volumes = $csClient->listVolumes($this->getParam('cloudLocation'));
$vols = array();
foreach ($volumes as $pk => $pv) {
if ($this->getParam('volumeId') && $this->getParam('volumeId') != $pv->id) {
continue;
}
$item = array('volumeId' => $pv->id, 'size' => round($pv->size / 1024 / 1024 / 1024, 2), 'status' => $pv->state, 'attachmentStatus' => $pv->virtualmachineid ? 'attached' : 'available', 'device' => $pv->deviceid, 'instanceId' => $pv->virtualmachineid, 'type' => $pv->type . " ({$pv->storagetype})", 'storage' => $pv->storage);
$item['autoSnaps'] = $this->db->GetOne("SELECT id FROM autosnap_settings WHERE objectid=? AND object_type=?", array($pv->id, AUTOSNAPSHOT_TYPE::CSVOL)) ? true : false;
if ($item['instanceId']) {
try {
$dbServer = DBServer::LoadByPropertyValue(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $item['instanceId']);
$item['farmId'] = $dbServer->farmId;
$item['farmRoleId'] = $dbServer->farmRoleId;
$item['serverIndex'] = $dbServer->index;
$item['serverId'] = $dbServer->serverId;
$item['farmName'] = $dbServer->GetFarmObject()->Name;
$item['mountStatus'] = false;
$item['roleName'] = $dbServer->GetFarmRoleObject()->GetRoleObject()->name;
} catch (Exception $e) {
}
}
$vols[] = $item;
}
$response = $this->buildResponseFromData($vols, array('serverId', 'volumeId', 'farmId', 'farmRoleId', 'storage'));
$this->response->data($response);
}
示例3: xListVolumesAction
public function xListVolumesAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'volumeId', 'direction' => 'ASC')), 'volumeId'));
$platformName = $this->getParam('platform');
if (!$platformName) {
throw new Exception("Cloud should be specified");
}
$client = $this->environment->openstack($platformName, $this->getParam('cloudLocation'));
$volumes = $client->volume->listVolumes(true);
$vols = array();
foreach ($volumes as $pk => $pv) {
if ($this->getParam('volumeId') && $this->getParam('volumeId') != $pv->id) {
continue;
}
$item = array('volumeId' => $pv->id, 'size' => $pv->size, 'status' => $pv->status, 'attachmentStatus' => isset($pv->attachments[0]) ? 'attached' : 'available', 'device' => isset($pv->attachments[0]) ? $pv->attachments[0]->device : "", 'instanceId' => isset($pv->attachments[0]) ? $pv->attachments[0]->server_id : "", 'type' => $pv->volume_type, 'availability_zone' => $pv->availability_zone);
if ($item['instanceId']) {
try {
$dbServer = DBServer::LoadByPropertyValue(OPENSTACK_SERVER_PROPERTIES::SERVER_ID, $item['instanceId']);
$item['farmId'] = $dbServer->farmId;
$item['farmRoleId'] = $dbServer->farmRoleId;
$item['serverIndex'] = $dbServer->index;
$item['serverId'] = $dbServer->serverId;
$item['farmName'] = $dbServer->GetFarmObject()->Name;
$item['mountStatus'] = false;
$item['roleName'] = $dbServer->GetFarmRoleObject()->GetRoleObject()->name;
} catch (Exception $e) {
}
}
$vols[] = $item;
}
$response = $this->buildResponseFromData($vols, array('serverId', 'volumeId', 'farmId', 'farmRoleId'));
$this->response->data($response);
}
示例4: xCreateAction
public function xCreateAction()
{
$this->request->defineParams(array('volumeId', 'cloudLocation'));
$amazonEC2Client = Scalr_Service_Cloud_Aws::newEc2($this->getParam('cloudLocation'), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
$res = $amazonEC2Client->CreateSnapshot($this->getParam('volumeId'));
if ($res->snapshotId) {
$r = $amazonEC2Client->DescribeVolumes($res->volumeId);
$info = $r->volumeSet->item;
if ($info->attachmentSet->item->instanceId) {
try {
$dBServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, (string) $info->attachmentSet->item->instanceId);
$dBFarm = $dBServer->GetFarmObject();
} catch (Exception $e) {
}
if ($dBServer && $dBFarm) {
$comment = sprintf(_("Created on farm '%s', server '%s' (Instance ID: %s)"), $dBFarm->Name, $dBServer->serverId, (string) $info->attachmentSet->item->instanceId);
}
} else {
$comment = "";
}
$this->db->Execute("INSERT INTO ebs_snaps_info SET snapid=?, comment=?, dtcreated=NOW(), region=?", array($res->snapshotId, $comment, $this->getParam('cloudLocation')));
$this->response->data(array('data' => array('snapshotId' => $res->snapshotId)));
} else {
throw new Exception("Scalr unable to create snapshot. Please try again later.");
}
}
示例5: xListIpsAction
public function xListIpsAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'ipId', 'direction' => 'ASC')), 'ipId'));
$platformName = $this->getParam('platform');
if (!$platformName) {
throw new Exception("Cloud should be specified");
}
$platform = PlatformFactory::NewPlatform($platformName);
$cs = $this->environment->cloudstack($platformName);
$ccProps = $this->environment->cloudCredentials($platformName)->properties;
$accountName = $ccProps[\Scalr\Model\Entity\CloudCredentialsProperty::CLOUDSTACK_ACCOUNT_NAME];
$domainId = $ccProps[\Scalr\Model\Entity\CloudCredentialsProperty::CLOUDSTACK_DOMAIN_ID];
$requestData = new ListIpAddressesData();
$requestData->account = $accountName;
$requestData->domainid = $domainId;
$requestData->zoneid = $this->getParam('cloudLocation');
$ipAddresses = $cs->listPublicIpAddresses($requestData);
$systemIp = $ccProps[\Scalr\Model\Entity\CloudCredentialsProperty::CLOUDSTACK_SHARED_IP . ".{$this->getParam('cloudLocation')}"];
$ips = array();
if (!empty($ipAddresses)) {
foreach ($ipAddresses as $pk => $pv) {
if ($this->getParam('ipId') && $this->getParam('ipId') != $pv->id) {
continue;
}
if ($pv->ipaddress == $systemIp) {
$pv->purpose = 'ScalrShared';
}
if ($pv->isstaticnat && !$pv->issystem) {
$pv->purpose = 'ElasticIP';
}
if ($pv->isstaticnat && $pv->issystem) {
$pv->purpose = 'PublicIP';
}
$item = array('ipId' => $pv->id, 'dtAllocated' => $pv->allocated, 'networkName' => $pv->associatednetworkname, 'purpose' => $pv->purpose ? $pv->purpose : "Not used", 'ip' => $pv->ipaddress, 'state' => $pv->state, 'instanceId' => $pv->virtualmachineid, 'fullinfo' => $pv, 'farmId' => false);
if ($item['instanceId']) {
try {
$dbServer = DBServer::LoadByPropertyValue(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $item['instanceId']);
$item['farmId'] = $dbServer->farmId;
$item['farmRoleId'] = $dbServer->farmRoleId;
$item['serverIndex'] = $dbServer->index;
$item['serverId'] = $dbServer->serverId;
$item['farmName'] = $dbServer->GetFarmObject()->Name;
$item['roleName'] = $dbServer->GetFarmRoleObject()->GetRoleObject()->name;
} catch (Exception $e) {
}
}
$ips[] = $item;
}
}
$response = $this->buildResponseFromData($ips, array('serverId', 'ipId', 'ip', 'farmId', 'farmRoleId'));
$this->response->data($response);
}
示例6: xListIpsAction
public function xListIpsAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'ipId', 'direction' => 'ASC')), 'ipId'));
$platformName = $this->getParam('platform');
if (!$platformName) {
throw new Exception("Cloud should be specified");
}
//$platform = PlatformFactory::NewPlatform($platformName);
//$networkType = $platform->getConfigVariable(OpenstackPlatformModule::NETWORK_TYPE, $this->environment, false);
$openstack = $this->environment->openstack($platformName, $this->getParam('cloudLocation'));
//!FIXME dicsydel remove debug
if ($openstack->hasService(OpenStack::SERVICE_NETWORK)) {
var_dump($openstack->network->floatingIps->list()->toArray());
}
var_dump($openstack->servers->floatingIps->list()->toArray());
var_dump($openstack->servers->listFloatingIpPools()->toArray());
var_dump($openstack->network->listNetworks()->toArray());
exit;
$ips = array();
foreach ($ipAddresses->publicipaddress as $pk => $pv) {
if ($this->getParam('ipId') && $this->getParam('ipId') != $pv->id) {
continue;
}
//!FIXME $systemIp variable has not been defined
if ($pv->ipaddress == $systemIp) {
$pv->purpose = 'ScalrShared';
}
if ($pv->isstaticnat && !$pv->issystem) {
$pv->purpose = 'ElasticIP';
}
if ($pv->isstaticnat && $pv->issystem) {
$pv->purpose = 'PublicIP';
}
$item = array('ipId' => $pv->id, 'dtAllocated' => $pv->allocated, 'networkName' => $pv->associatednetworkname, 'purpose' => $pv->purpose ? $pv->purpose : "Not used", 'ip' => $pv->ipaddress, 'state' => $pv->state, 'instanceId' => $pv->virtualmachineid, 'fullinfo' => $pv, 'farmId' => false);
if ($item['instanceId']) {
try {
$dbServer = DBServer::LoadByPropertyValue(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $item['instanceId']);
$item['farmId'] = $dbServer->farmId;
$item['farmRoleId'] = $dbServer->farmRoleId;
$item['serverIndex'] = $dbServer->index;
$item['serverId'] = $dbServer->serverId;
$item['farmName'] = $dbServer->GetFarmObject()->Name;
$item['roleName'] = $dbServer->GetFarmRoleObject()->GetRoleObject()->name;
} catch (Exception $e) {
}
}
$ips[] = $item;
}
$response = $this->buildResponseFromData($ips, array('serverId', 'ipId', 'ip', 'farmId', 'farmRoleId'));
$this->response->data($response);
}
示例7: ValidateRequestByFarmHash
protected function ValidateRequestByFarmHash($farmid, $instanceid, $authhash)
{
try {
$DBFarm = DBFarm::LoadByID($farmid);
$DBServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $instanceid);
} catch (Exception $e) {
if (!$DBServer) {
throw new Exception(sprintf(_("Cannot verify the instance you are making request from. Make sure that farmid, instance-id and auth-hash parameters are specified.")));
}
}
if ($DBFarm->Hash != $authhash || $DBFarm->ID != $DBServer->farmId) {
throw new Exception(sprintf(_("Cannot verify the instance you are making request from. Make sure that farmid (%s), instance-id (%s) and auth-hash (%s) parameters are valid."), $farmid, $instanceid, $authhash));
}
return $DBServer;
}
示例8: xListEipsAction
public function xListEipsAction()
{
$amazonEC2Client = Scalr_Service_Cloud_Aws::newEc2($this->getParam('cloudLocation'), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
// Rows
$aws_response = $amazonEC2Client->DescribeAddresses();
$rowz = $aws_response->addressesSet->item;
if ($rowz instanceof stdClass) {
$rowz = array($rowz);
}
foreach ($rowz as &$pv) {
$item = array('ipaddress' => $pv->publicIp, 'instance_id' => $pv->instanceId);
$info = $this->db->GetRow("SELECT * FROM elastic_ips WHERE ipaddress=?", array($pv->publicIp));
if ($info) {
$item['farm_id'] = $info['farmid'];
$item['farm_roleid'] = $info['farm_roleid'];
$item['server_id'] = $info['server_id'];
$item['indb'] = true;
$item['server_index'] = $info['instance_index'];
//WORKAROUND: EIPS not imported correclty from 1.2 to 2.0
if (!$item['server_id'] && $info['state'] == 1) {
try {
$DBServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $item['instance_id']);
$item['server_id'] = $DBServer->serverId;
} catch (Exception $e) {
}
}
if ($item['farm_roleid']) {
try {
$DBFarmRole = DBFarmRole::LoadByID($item['farm_roleid']);
$item['role_name'] = $DBFarmRole->GetRoleObject()->name;
$item['farm_name'] = $DBFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
}
} else {
try {
$DBServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $pv->instanceId);
$item['server_id'] = $DBServer->serverId;
$item['farm_id'] = $DBServer->farmId;
} catch (Exception $e) {
}
}
$pv = $item;
}
$response = $this->buildResponseFromData($rowz);
$this->response->data($response);
}
示例9: xListIpsAction
public function xListIpsAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'ipId', 'direction' => 'ASC')), 'ipId'));
$platformName = $this->getParam('platform');
if (!$platformName) {
throw new Exception("Cloud should be specified");
}
$platform = PlatformFactory::NewPlatform($platformName);
$cs = Scalr_Service_Cloud_Cloudstack::newCloudstack($platform->getConfigVariable(Modules_Platforms_Cloudstack::API_URL, $this->environment), $platform->getConfigVariable(Modules_Platforms_Cloudstack::API_KEY, $this->environment), $platform->getConfigVariable(Modules_Platforms_Cloudstack::SECRET_KEY, $this->environment), $platformName);
$accountName = $platform->getConfigVariable(Modules_Platforms_Cloudstack::ACCOUNT_NAME, $this->getEnvironment(), false);
$domainId = $platform->getConfigVariable(Modules_Platforms_Cloudstack::DOMAIN_ID, $this->getEnvironment(), false);
$ipAddresses = $cs->listPublicIpAddresses(null, $accountName, null, $domainId, null, null, null, null, null, null, $this->getParam('cloudLocation'));
$systemIp = $platform->getConfigVariable(Modules_Platforms_Cloudstack::SHARED_IP . "." . $this->getParam('cloudLocation'), $this->environment);
$ips = array();
foreach ($ipAddresses->publicipaddress as $pk => $pv) {
if ($this->getParam('ipId') && $this->getParam('ipId') != $pv->id) {
continue;
}
if ($pv->ipaddress == $systemIp) {
$pv->purpose = 'ScalrShared';
}
if ($pv->isstaticnat && !$pv->issystem) {
$pv->purpose = 'ElasticIP';
}
if ($pv->isstaticnat && $pv->issystem) {
$pv->purpose = 'PublicIP';
}
$item = array('ipId' => $pv->id, 'dtAllocated' => $pv->allocated, 'networkName' => $pv->associatednetworkname, 'purpose' => $pv->purpose ? $pv->purpose : "Not used", 'ip' => $pv->ipaddress, 'state' => $pv->state, 'instanceId' => $pv->virtualmachineid, 'fullinfo' => $pv, 'farmId' => false);
if ($item['instanceId']) {
try {
$dbServer = DBServer::LoadByPropertyValue(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $item['instanceId']);
$item['farmId'] = $dbServer->farmId;
$item['farmRoleId'] = $dbServer->farmRoleId;
$item['serverIndex'] = $dbServer->index;
$item['serverId'] = $dbServer->serverId;
$item['farmName'] = $dbServer->GetFarmObject()->Name;
$item['roleName'] = $dbServer->GetFarmRoleObject()->GetRoleObject()->name;
} catch (Exception $e) {
}
}
$ips[] = $item;
}
$response = $this->buildResponseFromData($ips, array('serverId', 'ipId', 'ip', 'farmId', 'farmRoleId'));
$this->response->data($response);
}
示例10: xListEipsAction
public function xListEipsAction()
{
$aws = $this->environment->aws($this->getParam('cloudLocation'));
$addressList = $aws->ec2->address->describe();
$rowz = array();
/* @var $address Ec2DataType\AddressData */
foreach ($addressList as $address) {
$item = array('ipaddress' => $address->publicIp, 'allocation_id' => $address->allocationId, 'domain' => $address->domain, 'instance_id' => $address->instanceId === null ? '' : $address->instanceId);
$info = $this->db->GetRow("SELECT * FROM elastic_ips WHERE ipaddress=? LIMIT 1", array($address->publicIp));
if ($info) {
$item['farm_id'] = $info['farmid'];
$item['farm_roleid'] = $info['farm_roleid'];
$item['server_id'] = $info['server_id'];
$item['indb'] = true;
$item['server_index'] = $info['instance_index'];
//WORKAROUND: EIPS not imported correclty from 1.2 to 2.0
if (!$item['server_id'] && $info['state'] == 1) {
try {
$DBServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $item['instance_id']);
$item['server_id'] = $DBServer->serverId;
} catch (Exception $e) {
}
}
if ($item['farm_roleid']) {
try {
$DBFarmRole = DBFarmRole::LoadByID($item['farm_roleid']);
$item['role_name'] = $DBFarmRole->GetRoleObject()->name;
$item['farm_name'] = $DBFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
}
} else {
try {
$DBServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $address->instanceId);
$item['server_id'] = $DBServer->serverId;
$item['farm_id'] = $DBServer->farmId;
} catch (Exception $e) {
}
}
$rowz[] = $item;
}
$response = $this->buildResponseFromData($rowz);
$this->response->data($response);
}
示例11: xCreateAction
public function xCreateAction()
{
$this->request->restrictAccess(Acl::RESOURCE_AWS_SNAPSHOTS, Acl::PERM_AWS_SNAPSHOTS_MANAGE);
$this->request->defineParams(array('volumeId', 'cloudLocation', 'description'));
$aws = $this->getEnvironment()->aws($this->getParam('cloudLocation'));
$snapshot = $aws->ec2->snapshot->create($this->getParam('volumeId'), $this->getParam('description'));
if (isset($snapshot->snapshotId)) {
/* @var $volume \Scalr\Service\Aws\Ec2\DataType\VolumeData */
$volume = $aws->ec2->volume->describe($snapshot->volumeId)->get(0);
if (!empty($volume->tagSet) && $volume->tagSet->count()) {
try {
//We need to do sleep due to eventual consistency on EC2
sleep(2);
//Set tags (copy them from the original EBS volume)
$snapshot->createTags($volume->tagSet);
} catch (Exception $e) {
//We want to hear from the cases when it cannot set tag to snapshot
trigger_error(sprintf("Cound not set tag to snapshot: %s", $e->getMessage()), E_USER_WARNING);
}
}
if (count($volume->attachmentSet) && !empty($volume->attachmentSet[0]->instanceId)) {
$instanceId = $volume->attachmentSet[0]->instanceId;
try {
$dBServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $instanceId);
$dBFarm = $dBServer->GetFarmObject();
} catch (Exception $e) {
}
if (isset($dBServer) && isset($dBFarm)) {
$comment = sprintf(_("Created on farm '%s', server '%s' (Instance ID: %s)"), $dBFarm->Name, $dBServer->serverId, $instanceId);
}
} else {
$comment = '';
}
$this->db->Execute("\n INSERT INTO ebs_snaps_info\n SET snapid = ?,\n comment = ?,\n dtcreated = NOW(),\n region = ?\n ", array($snapshot->snapshotId, $comment, $this->getParam('cloudLocation')));
$this->response->data(array('data' => array('snapshotId' => $snapshot->snapshotId)));
} else {
throw new Exception("Unable to create snapshot. Please try again later.");
}
}
示例12: xListVolumesAction
public function xListVolumesAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'volumeId', 'direction' => 'ASC')), 'volumeId'));
$platformName = $this->getParam('platform');
if (!$platformName) {
throw new Exception("Cloud should be specified");
}
$cs = $this->environment->cloudstack($platformName);
$requestData = new ListVolumesData();
$requestData->zoneid = $this->getParam('cloudLocation');
$requestData->listall = true;
$volumes = $cs->volume->describe($requestData);
$vols = array();
if (!empty($volumes)) {
foreach ($volumes as $pk => $pv) {
if ($this->getParam('volumeId') && $this->getParam('volumeId') != $pv->id) {
continue;
}
$item = array('volumeId' => $pv->id, 'size' => round($pv->size / 1024 / 1024 / 1024, 2), 'status' => $pv->state, 'attachmentStatus' => $pv->virtualmachineid ? 'attached' : 'available', 'device' => $pv->deviceid, 'instanceId' => $pv->virtualmachineid, 'type' => $pv->type . " ({$pv->storagetype})", 'storage' => $pv->storage);
$item['autoSnaps'] = $this->db->GetOne("SELECT id FROM autosnap_settings WHERE objectid=? AND object_type=? LIMIT 1", array($pv->id, AUTOSNAPSHOT_TYPE::CSVOL)) ? true : false;
if ($item['instanceId']) {
try {
$dbServer = DBServer::LoadByPropertyValue(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $item['instanceId']);
$item['farmId'] = $dbServer->farmId;
$item['farmRoleId'] = $dbServer->farmRoleId;
$item['serverIndex'] = $dbServer->index;
$item['serverId'] = $dbServer->serverId;
$item['farmName'] = $dbServer->GetFarmObject()->Name;
$item['mountStatus'] = false;
$item['roleName'] = $dbServer->GetFarmRoleObject()->GetRoleObject()->name;
} catch (Exception $e) {
}
}
$vols[] = $item;
}
}
$response = $this->buildResponseFromData($vols, array('serverId', 'volumeId', 'farmId', 'farmRoleId', 'storage'));
$this->response->data($response);
}
示例13: xGetCloudServersListAction
public function xGetCloudServersListAction()
{
$this->request->defineParams(array('platform', 'cloudLocation'));
if (!$this->environment->isPlatformEnabled($this->getParam('platform'))) {
throw new Exception(sprintf('Cloud %s is not enabled for current environment', $this->getParam('platform')));
}
$results = array();
$platform = PlatformFactory::NewPlatform($this->getParam('platform'));
//TODO: Added support for GCE
if ($this->getParam('platform') == SERVER_PLATFORMS::GCE) {
$gce = $platform->getClient($this->environment, $this->getParam('cloudLocation'));
$result = $gce->instances->listInstances($this->environment->getPlatformConfigValue(GoogleCEPlatformModule::PROJECT_ID), $this->getParam('cloudLocation'), array());
if (is_array($result->items)) {
foreach ($result->items as $server) {
if ($server->status != 'RUNNING') {
continue;
}
$ips = $platform->determineServerIps($gce, $server);
$itm = array('id' => $server->name, 'localIp' => $ips['localIp'], 'publicIp' => $ips['remoteIp'], 'zone' => $this->getParam('cloudLocation'), 'isImporting' => false, 'isManaged' => false);
//Check is instance already importing
try {
$dbServer = DBServer::LoadByPropertyValue(GCE_SERVER_PROPERTIES::SERVER_NAME, $server->name);
if ($dbServer && $dbServer->status != SERVER_STATUS::TERMINATED) {
if ($dbServer->status == SERVER_STATUS::IMPORTING) {
$itm['isImporting'] = true;
} else {
$itm['isManaged'] = true;
}
$itm['serverId'] = $dbServer->serverId;
}
} catch (Exception $e) {
}
$results[] = $itm;
}
}
} elseif (PlatformFactory::isOpenstack($this->getParam('platform'))) {
$client = $this->environment->openstack($this->getParam('platform'), $this->getParam('cloudLocation'));
$r = $client->servers->list(true);
do {
foreach ($r as $server) {
if ($server->status != 'ACTIVE') {
continue;
}
$ips = $platform->determineServerIps($client, $server);
$itm = array('id' => $server->id, 'localIp' => $ips['localIp'], 'publicIp' => $ips['remoteIp'], 'zone' => $this->getParam('cloudLocation'), 'isImporting' => false, 'isManaged' => false);
//Check is instance already importing
try {
$dbServer = DBServer::LoadByPropertyValue(OPENSTACK_SERVER_PROPERTIES::SERVER_ID, $server->id);
if ($dbServer && $dbServer->status != SERVER_STATUS::TERMINATED) {
if ($dbServer->status == SERVER_STATUS::IMPORTING) {
$itm['isImporting'] = true;
} else {
$itm['isManaged'] = true;
}
$itm['serverId'] = $dbServer->serverId;
}
} catch (Exception $e) {
}
$results[] = $itm;
}
} while (false !== ($r = $r->getNextPage()));
} elseif (PlatformFactory::isCloudstack($this->getParam('platform'))) {
$client = $this->environment->cloudstack($this->getParam('platform'));
$platform = PlatformFactory::NewPlatform($this->getParam('platform'));
$r = $client->instance->describe(array('zoneid' => $this->getParam('cloudLocation')));
if (count($r) > 0) {
foreach ($r as $server) {
$ips = $platform->determineServerIps($client, $server);
$itm = array('id' => $server->id, 'localIp' => $ips['localIp'], 'publicIp' => $ips['remoteIp'], 'zone' => $this->getParam('cloudLocation'), 'isImporting' => false, 'isManaged' => false);
//Check is instance already importing
try {
$dbServer = DBServer::LoadByPropertyValue(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID, $server->id);
if ($dbServer && $dbServer->status != SERVER_STATUS::TERMINATED) {
if ($dbServer->status == SERVER_STATUS::IMPORTING) {
$itm['isImporting'] = true;
} else {
$itm['isManaged'] = true;
}
$itm['serverId'] = $dbServer->serverId;
}
} catch (Exception $e) {
}
$results[] = $itm;
}
}
} elseif ($this->getParam('platform') == SERVER_PLATFORMS::EC2) {
$client = $this->environment->aws($this->getParam('cloudLocation'))->ec2;
$nextToken = null;
do {
if (isset($r)) {
$nextToken = $r->getNextToken();
}
$r = $client->instance->describe(null, null, $nextToken);
if (count($r)) {
foreach ($r as $reservation) {
/* @var $reservation Scalr\Service\Aws\Ec2\DataType\ReservationData */
foreach ($reservation->instancesSet as $instance) {
/* @var $instance Scalr\Service\Aws\Ec2\DataType\InstanceData */
if ($instance->instanceState->name != 'running') {
continue;
//.........这里部分代码省略.........
示例14: xListVolumesAction
public function xListVolumesAction()
{
$aws = $this->getEnvironment()->aws($this->getParam('cloudLocation'));
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'volumeId', 'direction' => 'DESC')), 'volumeId'));
if ($this->getParam('volumeId')) {
$filter = array(array('name' => VolumeFilterNameType::volumeId(), 'value' => $this->getParam('volumeId')));
} else {
$filter = null;
}
// Rows
$volumeList = $aws->ec2->volume->describe(null, $filter);
$vols = array();
/* @var $pv VolumeData */
foreach ($volumeList as $pv) {
/* @var $att AttachmentSetResponseData */
if (count($pv->attachmentSet)) {
$att = $pv->attachmentSet[0];
} else {
$att = null;
}
$tags = array();
foreach ($pv->tagSet as $tag) {
/* @var $tag ResourceTagSetData */
$tg = "{$tag->key}";
if ($tag->value) {
$tg .= "={$tag->value}";
}
$tags[] = $tg;
}
$item = array('volumeId' => $pv->volumeId, 'size' => (int) $pv->size, 'snapshotId' => $pv->snapshotId, 'availZone' => $pv->availabilityZone, 'type' => $pv->volumeType, 'status' => $pv->status, 'attachmentStatus' => $att !== null ? $att->status : null, 'device' => $att !== null ? $att->device : null, 'instanceId' => $att !== null ? $att->instanceId : null, 'tags' => implode(',', $tags));
$item['autoSnaps'] = $this->db->GetOne("SELECT id FROM autosnap_settings WHERE objectid=? AND object_type=? LIMIT 1", array($pv->volumeId, AUTOSNAPSHOT_TYPE::EBSSnap)) ? true : false;
if (!empty($item['instanceId'])) {
try {
$dbServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $item['instanceId']);
if ($dbServer) {
$item['farmId'] = $dbServer->farmId;
$item['farmRoleId'] = $dbServer->farmRoleId;
$item['serverIndex'] = $dbServer->index;
$item['serverId'] = $dbServer->serverId;
$item['farmName'] = $dbServer->GetFarmObject()->Name;
$item['mountStatus'] = false;
$item['roleName'] = $dbServer->GetFarmRoleObject()->GetRoleObject()->name;
/* Waiting for bugfix on scalarizr side
if ($dbServer->IsSupported('2.5.4')) {
$item['mounts'] = $dbServer->scalarizr->system->mounts();
}
*/
}
} catch (\Exception $e) {
}
}
$vols[] = $item;
}
$response = $this->buildResponseFromData($vols, array('instanceId', 'volumeId', 'snapshotId', 'farmId', 'farmRoleId', 'availZone', 'type'));
$this->response->data($response);
}
示例15: xListVolumesAction
public function xListVolumesAction()
{
$aws = $this->getEnvironment()->aws($this->getParam('cloudLocation'));
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'volumeId', 'direction' => 'DESC')), 'volumeId'));
if ($this->getParam('volumeId')) {
$filter = array(array('name' => VolumeFilterNameType::volumeId(), 'value' => $this->getParam('volumeId')));
} else {
$filter = null;
}
// Rows
$volumeList = $aws->ec2->volume->describe(null, $filter);
$vols = array();
/* @var $pv VolumeData */
foreach ($volumeList as $pv) {
/* @var $att AttachmentSetResponseData */
if (count($pv->attachmentSet)) {
$att = $pv->attachmentSet[0];
} else {
$att = null;
}
$item = array('volumeId' => $pv->volumeId, 'size' => (int) $pv->size, 'snapshotId' => $pv->snapshotId, 'availZone' => $pv->availabilityZone, 'type' => $pv->volumeType, 'status' => $pv->status, 'attachmentStatus' => $att !== null ? $att->status : null, 'device' => $att !== null ? $att->device : null, 'instanceId' => $att !== null ? $att->instanceId : null);
$item['autoSnaps'] = $this->db->GetOne("SELECT id FROM autosnap_settings WHERE objectid=? AND object_type=? LIMIT 1", array($pv->volumeId, AUTOSNAPSHOT_TYPE::EBSSnap)) ? true : false;
$dbEbsVolume = false;
try {
$dbEbsVolume = DBEBSVolume::loadByVolumeId($pv->volumeId);
$item['farmId'] = $dbEbsVolume->farmId;
$item['farmRoleId'] = $dbEbsVolume->farmRoleId;
$item['serverIndex'] = $dbEbsVolume->serverIndex;
$item['serverId'] = $dbEbsVolume->serverId;
$item['mountStatus'] = $dbEbsVolume->mountStatus;
$item['farmName'] = DBFarm::LoadByID($dbEbsVolume->farmId)->Name;
$item['roleName'] = DBFarmRole::LoadByID($dbEbsVolume->farmRoleId)->GetRoleObject()->name;
$item['autoAttach'] = true;
} catch (\Exception $e) {
}
if (!$dbEbsVolume && !empty($item['instanceId'])) {
try {
$dbServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $item['instanceId']);
$item['farmId'] = $dbServer->farmId;
$item['farmRoleId'] = $dbServer->farmRoleId;
$item['serverIndex'] = $dbServer->index;
$item['serverId'] = $dbServer->serverId;
$item['farmName'] = $dbServer->GetFarmObject()->Name;
$item['mountStatus'] = false;
$item['roleName'] = $dbServer->GetFarmRoleObject()->GetRoleObject()->name;
} catch (\Exception $e) {
}
}
$vols[] = $item;
}
$response = $this->buildResponseFromData($vols, array('instanceId', 'volumeId', 'snapshotId', 'farmId', 'farmRoleId', 'availZone', 'type'));
$this->response->data($response);
}