public function CreateServerSnapshot(BundleTask $BundleTask) { $DBServer = DBServer::LoadByID($BundleTask->serverId); $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::CSTACK_DEF; $msg = new Scalr_Messaging_Msg_Rebundle($BundleTask->id, $BundleTask->roleName, array()); if (!$DBServer->SendMessage($msg)) { $BundleTask->SnapshotCreationFailed("Cannot send rebundle message to server. Please check event log for more details."); return; } else { $BundleTask->Log(sprintf(_("Snapshot creating initialized (MessageID: %s). Bundle task status changed to: %s"), $msg->messageId, $BundleTask->status)); } $BundleTask->setDate('started'); $BundleTask->Save(); }
public function CreateServerSnapshot(BundleTask $BundleTask) { $DBServer = DBServer::LoadByID($BundleTask->serverId); $RDSClient = $this->getRdsClient($DBServer->GetEnvironmentObject(), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION)); try { $RDSClient->CreateDBSnapshot($BundleTask->roleName, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::INSTANCE_ID)); $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::RDS_SPT; $BundleTask->snapshotId = $BundleTask->roleName; $BundleTask->Log(sprintf(_("Snapshot creation initialized. SnapshotID: %s"), $BundleTask->snapshotId)); $BundleTask->setDate('started'); $BundleTask->Save(); } catch (Exception $e) { $BundleTask->SnapshotCreationFailed($e->getMessage()); } }
public function CreateServerSnapshot(BundleTask $BundleTask) { $DBServer = DBServer::LoadByID($BundleTask->serverId); $euca = $DBServer->GetEnvironmentObject()->eucalyptus($DBServer); if (!$BundleTask->prototypeRoleId) { $protoImageId = $DBServer->GetProperty(EUCA_SERVER_PROPERTIES::EMIID); } else { $protoImageId = DBRole::loadById($BundleTask->prototypeRoleId)->getImageId(SERVER_PLATFORMS::EUCALYPTUS, $DBServer->GetProperty(EUCA_SERVER_PROPERTIES::REGION)); } $ami = $euca->ec2->image->describe($protoImageId)->get(0); $platfrom = $ami->platform; $rootDeviceType = $ami->rootDeviceType; if ($rootDeviceType == 'ebs') { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EUCA_EBS; $BundleTask->Log(sprintf(_("Selected platfrom snapshoting type: %s"), $BundleTask->bundleType)); $BundleTask->SnapshotCreationFailed("Not supported yet"); return; } else { if ($platfrom == 'windows') { //TODO: Windows platfrom is not supported yet. $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EUCA_WIN; $BundleTask->Log(sprintf(_("Selected platfrom snapshoting type: %s"), $BundleTask->bundleType)); $BundleTask->SnapshotCreationFailed("Not supported yet"); return; } else { $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EUCA_WSI; $BundleTask->Save(); $BundleTask->Log(sprintf(_("Selected platfrom snapshoting type: %s"), $BundleTask->bundleType)); $msg = new Scalr_Messaging_Msg_Rebundle($BundleTask->id, $BundleTask->roleName, array()); if (!$DBServer->SendMessage($msg)) { $BundleTask->SnapshotCreationFailed("Cannot send rebundle message to server. Please check event log for more details."); return; } else { $BundleTask->Log(sprintf(_("Snapshot creation started (MessageID: %s). Bundle task status changed to: %s"), $msg->messageId, $BundleTask->status)); } } } $BundleTask->setDate('started'); $BundleTask->Save(); }
public function CreateServerSnapshot(BundleTask $BundleTask) { $DBServer = DBServer::LoadByID($BundleTask->serverId); if ($BundleTask->osFamily == 'windows' || $DBServer->osType == 'windows') { if ($BundleTask->status == SERVER_SNAPSHOT_CREATION_STATUS::PENDING) { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::OSTACK_WINDOWS; $BundleTask->Log(sprintf(_("Selected platfrom snapshoting type: %s"), $BundleTask->bundleType)); $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::PREPARING; $BundleTask->Save(); try { $msg = $DBServer->SendMessage(new Scalr_Messaging_Msg_Win_PrepareBundle($BundleTask->id), false, true); if ($msg) { $BundleTask->Log(sprintf(_("PrepareBundle message sent. MessageID: %s. Bundle task status changed to: %s"), $msg->messageId, $BundleTask->status)); } else { throw new Exception("Cannot send message"); } } catch (Exception $e) { $BundleTask->SnapshotCreationFailed("Cannot send PrepareBundle message to server."); return false; } } elseif ($BundleTask->status == SERVER_SNAPSHOT_CREATION_STATUS::PREPARING) { $BundleTask->Log(sprintf(_("Selected platform snapshot type: %s"), $BundleTask->bundleType)); $createImage = true; } } else { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::OSTACK_LINUX; $createImage = false; $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; $msg = new Scalr_Messaging_Msg_Rebundle($BundleTask->id, $BundleTask->roleName, array()); if (!$DBServer->SendMessage($msg)) { $BundleTask->SnapshotCreationFailed("Cannot send rebundle message to server. Please check event log for more details."); return; } else { $BundleTask->Log(sprintf(_("Snapshot creating initialized (MessageID: %s). Bundle task status changed to: %s"), $msg->messageId, $BundleTask->status)); } $BundleTask->setDate('started'); $BundleTask->Save(); } if ($createImage) { try { $client = $this->getOsClient($DBServer->GetEnvironmentObject(), $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION)); $imageId = $client->servers->createImage($DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::SERVER_ID), $BundleTask->roleName . "-" . date("YmdHi")); $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; $BundleTask->snapshotId = $imageId; $BundleTask->Log(sprintf(_("Snapshot creating initialized (ImageID: %s). Bundle task status changed to: %s"), $BundleTask->snapshotId, $BundleTask->status)); $BundleTask->setDate('started'); $BundleTask->Save(); } catch (Exception $e) { $BundleTask->SnapshotCreationFailed($e->getMessage()); return; } } return true; }
public function CreateServerSnapshot(BundleTask $BundleTask) { $DBServer = DBServer::LoadByID($BundleTask->serverId); $EC2Client = Scalr_Service_Cloud_Aws::newEc2($DBServer->GetProperty(EC2_SERVER_PROPERTIES::REGION), $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::PRIVATE_KEY), $DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::CERTIFICATE)); if (!$BundleTask->prototypeRoleId) { $proto_image_id = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::AMIID); } else { $proto_image_id = DBRole::loadById($BundleTask->prototypeRoleId)->getImageId(SERVER_PLATFORMS::EC2, $DBServer->GetProperty(EC2_SERVER_PROPERTIES::REGION)); } $DescribeImagesType = new DescribeImagesType(); $DescribeImagesType->imagesSet->item[] = array("imageId" => $proto_image_id); $ami_info = $EC2Client->DescribeImages($DescribeImagesType); $platfrom = (string) $ami_info->imagesSet->item->platform; if ($platfrom == 'windows') { if ((string) $ami_info->imagesSet->item->rootDeviceType != 'ebs') { $BundleTask->SnapshotCreationFailed("Only EBS root filesystem supported for Windows servers."); return; } if ($BundleTask->status == SERVER_SNAPSHOT_CREATION_STATUS::PENDING) { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_WIN200X; $BundleTask->Log(sprintf(_("Selected platfrom snapshoting type: %s"), $BundleTask->bundleType)); $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::PREPARING; try { $msg = $DBServer->SendMessage(new Scalr_Messaging_Msg_Win_PrepareBundle($BundleTask->id)); if ($msg) { $BundleTask->Log(sprintf(_("PrepareBundle message sent. MessageID: %s. Bundle task status changed to: %s"), $msg->messageId, $BundleTask->status)); } else { throw new Exception("Cannot send message"); } } catch (Exception $e) { $BundleTask->SnapshotCreationFailed("Cannot send PrepareBundle message to server."); return false; } } elseif ($BundleTask->status == SERVER_SNAPSHOT_CREATION_STATUS::PREPARING) { $BundleTask->Log(sprintf(_("Selected platform snapshot type: %s"), $BundleTask->bundleType)); try { $CreateImageType = new CreateImageType($DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $BundleTask->roleName . "-" . date("YmdHi"), $BundleTask->roleName, false); $result = $EC2Client->CreateImage($CreateImageType); $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; $BundleTask->snapshotId = $result->imageId; $BundleTask->Log(sprintf(_("Snapshot creating initialized (AMIID: %s). Bundle task status changed to: %s"), $BundleTask->snapshotId, $BundleTask->status)); } catch (Exception $e) { $BundleTask->SnapshotCreationFailed($e->getMessage()); return; } } } else { $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; if ((string) $ami_info->imagesSet->item->rootDeviceType == 'ebs') { if ((string) $ami_info->imagesSet->item->virtualizationType == 'hvm') { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM; } else { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS; } } else { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_S3I; } $BundleTask->Save(); $BundleTask->Log(sprintf(_("Selected platfrom snapshoting type: %s"), $BundleTask->bundleType)); if ($BundleTask->bundleType == SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM) { try { $CreateImageType = new CreateImageType($DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $BundleTask->roleName . "-" . date("YmdHi"), $BundleTask->roleName, false); $result = $EC2Client->CreateImage($CreateImageType); $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; $BundleTask->snapshotId = $result->imageId; $BundleTask->Log(sprintf(_("Snapshot creating initialized (AMIID: %s). Bundle task status changed to: %s"), $BundleTask->snapshotId, $BundleTask->status)); } catch (Exception $e) { $BundleTask->SnapshotCreationFailed($e->getMessage()); return; } } else { $msg = new Scalr_Messaging_Msg_Rebundle($BundleTask->id, $BundleTask->roleName, array()); $metaData = $BundleTask->getSnapshotDetails(); if ($metaData['rootVolumeSize']) { $msg->volumeSize = $metaData['rootVolumeSize']; } if (!$DBServer->SendMessage($msg)) { $BundleTask->SnapshotCreationFailed("Cannot send rebundle message to server. Please check event log for more details."); return; } else { $BundleTask->Log(sprintf(_("Snapshot creation started (MessageID: %s). Bundle task status changed to: %s"), $msg->messageId, $BundleTask->status)); } } } $BundleTask->setDate('started'); $BundleTask->Save(); }
/** * {@inheritdoc} * @see IPlatformModule::CreateServerSnapshot() */ public function CreateServerSnapshot(BundleTask $BundleTask) { $DBServer = DBServer::LoadByID($BundleTask->serverId); $aws = $DBServer->GetEnvironmentObject()->aws($DBServer); if (!$BundleTask->prototypeRoleId) { $proto_image_id = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::AMIID); } else { $protoRole = DBRole::loadById($BundleTask->prototypeRoleId); $proto_image_id = $protoRole->getImageId(SERVER_PLATFORMS::EC2, $DBServer->GetProperty(EC2_SERVER_PROPERTIES::REGION)); $details = $protoRole->getImageDetails(SERVER_PLATFORMS::EC2, $DBServer->GetProperty(EC2_SERVER_PROPERTIES::REGION)); if (in_array($details['os_family'], array('oel', 'redhat', 'scientific'))) { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM; } } $ami = $aws->ec2->image->describe($proto_image_id)->get(0); $platfrom = $ami->platform; if ($platfrom == 'windows') { if ($ami->rootDeviceType != 'ebs') { $BundleTask->SnapshotCreationFailed("Only EBS root filesystem supported for Windows servers."); return; } if ($BundleTask->status == SERVER_SNAPSHOT_CREATION_STATUS::PENDING) { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_WIN200X; $BundleTask->Log(sprintf(_("Selected platfrom snapshoting type: %s"), $BundleTask->bundleType)); $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::PREPARING; try { $msg = $DBServer->SendMessage(new Scalr_Messaging_Msg_Win_PrepareBundle($BundleTask->id)); if ($msg) { $BundleTask->Log(sprintf(_("PrepareBundle message sent. MessageID: %s. Bundle task status changed to: %s"), $msg->messageId, $BundleTask->status)); } else { throw new Exception("Cannot send message"); } } catch (Exception $e) { $BundleTask->SnapshotCreationFailed("Cannot send PrepareBundle message to server."); return false; } } elseif ($BundleTask->status == SERVER_SNAPSHOT_CREATION_STATUS::PREPARING) { $BundleTask->Log(sprintf(_("Selected platform snapshot type: %s"), $BundleTask->bundleType)); try { $request = new CreateImageRequestData($DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $BundleTask->roleName . "-" . date("YmdHi")); $request->description = $BundleTask->roleName; $request->noReboot = false; $imageId = $aws->ec2->image->create($request); $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; $BundleTask->snapshotId = $imageId; $BundleTask->Log(sprintf(_("Snapshot creating initialized (AMIID: %s). Bundle task status changed to: %s"), $BundleTask->snapshotId, $BundleTask->status)); } catch (Exception $e) { $BundleTask->SnapshotCreationFailed($e->getMessage()); return; } } } else { $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; if (!$BundleTask->bundleType) { if ($ami->rootDeviceType == 'ebs') { if ($ami->virtualizationType == 'hvm') { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM; } else { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS; } } else { $BundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_S3I; } } $BundleTask->Save(); $BundleTask->Log(sprintf(_("Selected platfrom snapshoting type: %s"), $BundleTask->bundleType)); if ($BundleTask->bundleType == SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM) { try { $request = new CreateImageRequestData($DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $BundleTask->roleName . "-" . date("YmdHi")); $request->description = $BundleTask->roleName; $request->noReboot = false; $imageId = $aws->ec2->image->create($request); $BundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::IN_PROGRESS; $BundleTask->snapshotId = $imageId; $BundleTask->Log(sprintf(_("Snapshot creating initialized (AMIID: %s). Bundle task status changed to: %s"), $BundleTask->snapshotId, $BundleTask->status)); } catch (Exception $e) { $BundleTask->SnapshotCreationFailed($e->getMessage()); return; } } else { $msg = new Scalr_Messaging_Msg_Rebundle($BundleTask->id, $BundleTask->roleName, array()); $metaData = $BundleTask->getSnapshotDetails(); if ($metaData['rootVolumeSize']) { $msg->volumeSize = $metaData['rootVolumeSize']; } if (!$DBServer->SendMessage($msg)) { $BundleTask->SnapshotCreationFailed("Cannot send rebundle message to server. Please check event log for more details."); return; } else { $BundleTask->Log(sprintf(_("Snapshot creation started (MessageID: %s). Bundle task status changed to: %s"), $msg->messageId, $BundleTask->status)); } } } $BundleTask->setDate('started'); $BundleTask->Save(); }