private $product_id; //声明品牌ID
//给$product_id 赋值 全局调用
public function __construct($product_id){
$this->product_id = $product_id;
}
syncLines 方法,主要用于同步线路数据
public function syncLines(){
// 获取线路数据
$lines = (new QcloudApi())-syncLines();
//失败
if(){
//写入接口日志
Log::saveApiSendLog('', '弹性云', '腾讯云', '线路同步','','0',json_encode($region),'',2, UID);
return ['result' => false, 'text' => '线路同步失败'];
}
//数据解析
$list = [];
foreach($lines as $key=>$item){
$list[] = [
'name' => $item['RegionName'],
'line_no' => $item['Region'],
'line_status' => 1,
'defense_status' => 0,
'install_status' => 1,
];
}
return ['result' => true, 'list' => $list];
}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
name | string | 线路名称 |
line_no | string | 线路编号 |
line_status | int | 线路状态 1:启用 0:禁用 |
defense_status | int | 防御状态 1:启用 0:禁用 |
defense_status | int | 重装状态 1:liunx与windows允许互装 2:禁止互装 |
createGroupVpc 方法,主要用于同步创建安全组、VPC数据
示例:
/**
*安全组、VPC创建及同步
* @param int $product_id 品牌id
**/
//如果无需创建同步安全组、VPC,可以不用定义此方法
public function createGroupVpc($product_id){
// dosomeing
return ['result' => true];
}
syncZones 方法,主要用于同步可用区数据
/**
*可用区同步
* @param array $lines 该品牌线路数据列表
**/
public function syncZones(array $lines){
$list = [];
foreach($lines as $item){
$line_id = $item['id']; //线路id
$zones = (new QcloudApi())->syncZones($item['line_no']);
//失败
if(){
//写入接口日志
Log::saveApiSendLog('', '弹性云', '腾讯云', '可用区同步','','0',json_encode($zones),'',2, UID);
return ['result' => false, 'text' => '可用区同步失败'];
}
foreach($zones as $key=>$item){
$list[] = [
'line_id' => $line_id,
'name' => $item['ZoneName'],
'area_no' => $item['Zone'],
'status' => 1,
];
}
}
return ['result' => true, 'list' => $list];
}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
line_id | int | 线路ID |
name | string | 可用区名称 |
area_no | string | 可用区编号 |
status | int | 可用区状态 1:启用 0:禁用 |
createVswitch 方法,用于创建、同步子网数据
/**
*创建、同步子网
* @param int $product_id 品牌id
**/
//如果无需创建、同步子网,可以不用定义此方法
public function createVswitch($product_id){
//dosomeing
return ['result' => true];
}
syncSpecGroups 方法, 主要用于同步规格组数据
/**
*规格组同步
* @param array $zones 该品牌可用区数据列表
**/
public function syncSpecGroups(array $zones = []){
//获取规格组
$spec_groups = (new QcloudApi())->syncSpecGroups();
//失败
if(){
//写入接口日志
Log::saveApiSendLog('', '弹性云', '腾讯云', '规格组同步','','0',json_encode($spec_groups),'',2, UID);
return ['result' => false, 'text' => '规格组同步失败'];
}
$list = [];
foreach($spec_groups as $item){
$list[] = [
'group_id' => $item['InstanceFamily'],
'name' => $item['InstanceFamilyName'],
'status' => 1,
];
}
return ['result' => true, 'list' => $list];
}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
group_id | string | 规格组id(编号) |
name | string | 规格组名称 |
status | int | 规格组状态 1:启用 0:禁用 |
/**
*规格列表同步
* @param array $spec_groups 规格类型数据
** @param array $zones 可用区数据
**/
public function syncSpecs(array $spec_groups, array $zones){
$group_ids = array_column($spec_groups,'group_id');
$allList = [];
foreach($zones as $item){
//查询可用区下 所有规格列表
$specs = (new QcloudApi())->syncSpecs($item['line_no'],$item['area_no']);
//失败
if(){
//写入接口日志
Log::saveApiSendLog('', '弹性云', '腾讯云', '规格同步','','0',json_encode($specs),'',2, UID);
return ['result' => false, 'text' => '规格列表同步失败'];
}
$allList = array_merge($allList,$specs);
}
//去重
$arr = [];
foreach($allList as $k => $item){
$flag = false;
foreach($arr as $v){
if($item['InstanceType'] == $v['InstanceType']){//规格类型
$flag = true;
break;
}
}
if(!$flag){
$arr[]=$item;
}
}
foreach($arr as $val){
$family = $val['InstanceFamily'];
//无此规格组类型 跳出循环
if(!in_array($family,$group_ids)){
continue;
}
$k = array_search($family,$group_ids);
$list[] = [
'group_id' => $spec_groups[$k]['id'],
'name' => $spec_groups[$k]['name'],
'spec_no' => $val['InstanceType'],
'cpu' => $val['CPU'],
'memory' => $val['Memory'],
];
}
return ['result' => true, 'list' => $list];
}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
group_id | string | 规格组id |
name | string | 规格名称 |
spec_no | string | 规格编号 |
cpu | int | cpu |
memory | int | 内存 |
/**
*可用区关联规格
* @param array $zones 可用区数据
* @param array $specs 规格数组
**/
public function syncAreaSpecs(array $zones, array $specs){
$list = [];
foreach($zones as $item){
// 调用查询规格接口
$syncSpecs = (new QcloudApi())->syncSpecs($item['line_no'],$item['area_no']);
//失败
if(){
//写入接口日志
Log::saveApiSendLog('', '弹性云', '腾讯云', '可用区关联规格','','0',json_encode($syncSpecs),'',2, UID);
continue;
}
$spec_no_list = array_column($specs, 'spec_no');
foreach($syncSpecs as $spec){
$fonud_key = array_search($spec['InstanceType'], $spec_no_list);
if ($fonud_key !== false) {
$list[] = [
'area_id' => $item['id'],
'spec_id' => $specs[$fonud_key]['id'],
'spec_group_id' => $specs[$fonud_key]['group_id'],
'status' => 1,
'add_type' => 1,
];
}
}
}
return ['result' => true, 'list' => $list];
}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
area_id | int | 可用区ID |
spec_id | int | 规格ID |
spec_group_id | int | 规格组ID |
status | int | 状态1:启用 0:禁用 |
add_type | int | 添加类型 0:手动关联 1:同步 |
/**
*系统类别同步
* @param array $lines 线路数据
**/
public function syncSystemClass(array $lines){
$list = [];
$class_list = [];
foreach($lines as $item){
$system_class = (new QcloudApi())->syncSystemClass($item['line_no']);
//失败
if(){
//写入接口日志
Log::saveApiSendLog('', '弹性云', '腾讯云', '系统类别同步','','0',json_encode($system_class),'',2, UID);
return ['result' => false, 'text' => '系统类别同步失败'];
}
$plat_list = array_column($system_class,'Platform');
$class_list = array_merge($plat_list,$class_list);
}
//去重
$class_list = array_unique($class_list);
array_walk($class_list,function($name)use(&$list){
$type = 2;
if(strpos($name,'dow') !== false){
$type = 1;
}
$list[] = [
'name' => $name,
'type' => $type,
];
});
return ['result' => true, 'list' => $list];
}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
name | string | 类型名称 |
type | int | 类别 1:windows系统 2:linux系统 |
/**
*系统列表同步
* @param array $lines 线路数据
* @param array $system_class 系统类别数据
**/
public function syncSystems(array $lines, array $system_class){
$system_class_name = array_column($system_class,'name');
foreach($lines as $item){
$systems = (new QcloudApi())->syncSystems($item['line_no']);
if(){
//写入接口日志
Log::saveApiSendLog('', '弹性云', '腾讯云', '系统列表同步','','0',json_encode($systems),'',2, UID);
return ['result' => false, 'text' => '系统列表同步失败'];
}
foreach($systems as $os){
$system_no = $os['ImageId']; //系统编号
$name = $os['OsName']; //系统名称
$class_key = array_search($os['Platform'],$system_class_name);
if($class_key === false){
continue;
}
$list[$system_no] = [
'class_id' => $system_class[$class_key]['id'],
'system_no' => $system_no,
'name' => $name,
'memory_limit' => '',
'max_memory_limit' => '',
];
}
return ['result' => true, 'text' => array_values($list)];
}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
class_id | int | 系统类型名称 |
system_no | string | 操作系统编号 |
name | string | 操作系统名称 |
memory_limit | int | 最小内存限制 ,注:需要自行分析数据 |
max_memory_limit | int | 最大内存限制,注:需要自行分析数据 |
/**
*可用区关联操作系统
* @param array $zones 可用区数据
* @param array $systems 系统数据
**/
public function syncAreaSystems(array $zones, array $systems){
$system_no_list = array_column($systems,'system_no');
$list = [];
foreach($zones as $item){
//调用接口查询系统数据
$sync_systems = (new QcloudApi())->syncSystems($item['line_no']);
//失败
if(){
//写入接口日志
Log::saveApiSendLog('', '弹性云', '腾讯云', '可用区关联操作系统','','0',json_encode($sync_systems),'',2, UID);
return ['result' => false, 'text' => '可用区关联操作系统失败'];
}
foreach($sync_systems as $os){
$system_no = $os['ImageId']; //系统编号
$system_key = array_search($system_no,$system_no_list);
if($system_key === false){
continue;
}
$list[] = [
'area_id' => $item['id'],
'system_id' => $systems[$system_key]['id'],
'system_class_id' => $systems[$system_key]['class_id'],
'status' => 1,
'add_type' => 1,
];
}
}
return ['result' => true, 'text' => $list];
}
返回参数说明
参数名 | 类型 | 说明 |
---|---|---|
area_id | int | 可用区ID |
system_id | int | 操作系统ID |
system_class_id | int | 系统类别ID |
status | int | 状态1:启用 0:禁用 |
add_type | int | 添加类型 0:手动关联 1:同步 |