Skip to content

Commit

Permalink
feature: 支持solaris操作系统安装(close #110)
Browse files Browse the repository at this point in the history
  • Loading branch information
v_axcwang authored and ZhuoZhuoCrayon committed Oct 30, 2021
1 parent 81bd7a9 commit ead7586
Show file tree
Hide file tree
Showing 16 changed files with 1,010 additions and 80 deletions.
26 changes: 15 additions & 11 deletions apps/backend/agent/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from apps.backend.api import constants as const
from apps.backend.exceptions import GenCommandsError
from apps.node_man import constants, models
from apps.node_man.models import aes_cipher
Expand Down Expand Up @@ -111,22 +112,21 @@ def choose_script_file(host: models.Host) -> str:
return constants.SetupScriptFileName.SETUP_PAGENT_PY.value

# 其它场景,按操作系统来区分
script_file_name_map = {
constants.OsType.LINUX: constants.SetupScriptFileName.SETUP_AGENT_SH.value,
constants.OsType.WINDOWS: constants.SetupScriptFileName.SETUP_AGENT_BAT.value,
constants.OsType.AIX: constants.SetupScriptFileName.SETUP_AGENT_KSH.value,
}
script_file_name = script_file_name_map[host.os_type]
script_file_name = constants.SCRIPT_FILE_NAME_MAP[host.os_type]
return script_file_name


def format_run_cmd_by_os_type(os_type: str, run_cmd: str) -> str:
if os_type == constants.OsType.WINDOWS:
def format_run_cmd_by_os_type(os_type: str, run_cmd=None) -> str:
os_type = os_type.lower()
if os_type == const.OS.WINDOWS and run_cmd:
return run_cmd
elif os_type == constants.OsType.AIX:
return f"nohup ksh {run_cmd} &"
suffix = const.SUFFIX_MAP[os_type]
if suffix != const.SUFFIX_MAP[const.OS.AIX]:
shell = "bash"
else:
return f"nohup bash {run_cmd} &"
shell = suffix
run_cmd = f"nohup {shell} {run_cmd} &" if run_cmd else shell
return run_cmd


def gen_commands(host: models.Host, pipeline_id: str, is_uninstall: bool) -> InstallationTools:
Expand Down Expand Up @@ -191,6 +191,7 @@ def gen_commands(host: models.Host, pipeline_id: str, is_uninstall: bool) -> Ins
host_identity = (
host.identity.key if host.identity.auth_type == constants.AuthType.KEY else host.identity.password
)
host_shell = format_run_cmd_by_os_type(host.os_type)
run_cmd_params.extend(
[
f"-HLIP {host.login_ip or host.inner_ip}",
Expand All @@ -202,6 +203,9 @@ def gen_commands(host: models.Host, pipeline_id: str, is_uninstall: bool) -> Ins
f"-HNT {host.node_type}",
f"-HOT {host.os_type.lower()}",
f"-HDD '{host_tmp_path}'",
f"-HPP '{settings.BK_NODEMAN_NGINX_PROXY_PASS_PORT}'",
f"-HSN '{constants.SCRIPT_FILE_NAME_MAP[host.os_type]}'",
f"-HS '{host_shell}'",
]
)

Expand Down
3 changes: 3 additions & 0 deletions apps/backend/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ class OS(object):
WINDOWS = "windows"
LINUX = "linux"
AIX = "aix"
SOLARIS = "solaris"


# 操作系统->系统账户映射表
ACCOUNT_MAP = {
OS.WINDOWS: settings.BACKEND_WINDOWS_ACCOUNT,
OS.LINUX: "root",
OS.AIX: "root",
OS.SOLARIS: "root",
}

# 操作系统->后缀映射表
SUFFIX_MAP = {
OS.WINDOWS: "bat",
OS.LINUX: "sh",
OS.AIX: "ksh",
OS.SOLARIS: "sh",
}


Expand Down
3 changes: 1 addition & 2 deletions apps/backend/components/collections/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def _execute(self, data, parent_data):
return True

def _agent_choose_ap(self, host):
is_linux = host.os_type in [constants.OsType.LINUX, constants.OsType.AIX]
is_linux = host.os_type in [constants.OsType.LINUX, constants.OsType.AIX, constants.OsType.SOLARIS]
ssh_man = None
if is_linux:
ssh_man = SshMan(host, self.logger)
Expand Down Expand Up @@ -983,7 +983,6 @@ def execute(self, data, parent_data):
package_name_tar=package_name.replace("tgz", "tar"),
)
else:

path = os.path.join(settings.PROJECT_ROOT, "script_tools", "upgrade_agent.sh.tpl")
with open(path, encoding="utf-8") as fh:
script = fh.read()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ def test_gen_pagent_command(self):
f" -O 48668 -E 58925 -A 58625 -V 58930 -B 10020 -S 60020 -Z 60030 -K 10030"
f' -e "1.1.1.1" -a "1.1.1.1" -k "1.1.1.1" -L /data/bkee/public/bknodeman/download'
f" -HLIP 127.0.0.1 -HIIP 127.0.0.1 -HA root -HP 22 -HI 'aes_str:::H4MFaqax' -HC 0 -HNT PAGENT"
f" -HOT linux -HDD '/tmp/' -p '/usr/local/gse' -I 1.1.1.1"
f" -HOT linux -HDD '/tmp/'"
f" -HPP '17981' -HSN 'setup_agent.sh' -HS 'bash'"
f" -p '/usr/local/gse' -I 1.1.1.1"
f" -o http://1.1.1.1:{settings.BK_NODEMAN_NGINX_DOWNLOAD_PORT}/ "
)
self.assertEqual(installation_tool.run_cmd, run_cmd)
Expand Down Expand Up @@ -521,7 +523,9 @@ def test_gen_install_channel_agent_command(self):
f" -O 48668 -E 58925 -A 58625 -V 58930 -B 10020 -S 60020 -Z 60030 -K 10030"
f' -e "127.0.0.1" -a "127.0.0.1" -k "127.0.0.1" -L /data/bkee/public/bknodeman/download'
f" -HLIP 127.0.0.1 -HIIP 127.0.0.1 -HA root -HP 22 -HI 'aes_str:::H4MFaqax' -HC 0 -HNT AGENT"
f" -HOT linux -HDD '/tmp/' -p '/usr/local/gse' -I 1.1.1.1"
f" -HOT linux -HDD '/tmp/'"
f" -HPP '17981' -HSN 'setup_agent.sh' -HS 'bash'"
f" -p '/usr/local/gse' -I 1.1.1.1"
f" -o http://1.1.1.1:{settings.BK_NODEMAN_NGINX_DOWNLOAD_PORT}/ "
)
self.assertEqual(installation_tool.run_cmd, run_cmd)
Expand Down
5 changes: 3 additions & 2 deletions apps/backend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,13 @@

def is_designated_upstream_servers(host: models.Host):
"""判断是否指定上游节点"""
without_zk_os = [constants.OsType.AIX, constants.OsType.SOLARIS]
# 非直连区域,使用proxy作为上游节点
if host.bk_cloud_id != constants.DEFAULT_CLOUD:
return True

# 直连区域 AIX不支持zk,因此直接指定上游节点
if host.bk_cloud_id == constants.DEFAULT_CLOUD and host.os_type == constants.OsType.AIX:
# 直连区域 AIX, SOLARIS不支持zk,因此直接指定上游节点
if host.bk_cloud_id == constants.DEFAULT_CLOUD and host.os_type in without_zk_os:
return True

# 指定了安装通道,直接使用安装通道的上游节点
Expand Down
22 changes: 17 additions & 5 deletions apps/node_man/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,25 @@ def get_optional_items(cls) -> List[str]:
AUTH_CHOICES = tuple_choices(AUTH_TUPLE)
AuthType = choices_to_namedtuple(AUTH_CHOICES)

OS_TUPLE = ("LINUX", "WINDOWS", "AIX")
OS_TUPLE = ("LINUX", "WINDOWS", "AIX", "SOLARIS")
OS_CHOICES = tuple_choices(OS_TUPLE)
OsType = choices_to_namedtuple(OS_CHOICES)
OS_CHN = {"WINDOWS": "Windows", "LINUX": "Linux", "AIX": "Aix"}
BK_OS_TYPE = {"LINUX": "1", "WINDOWS": "2", "AIX": "3"}
OS_CHN = {"WINDOWS": "Windows", "LINUX": "Linux", "AIX": "Aix", "SOLARIS": "Solaris"}
BK_OS_TYPE = {"LINUX": "1", "WINDOWS": "2", "AIX": "3", "SOLARIS": "5"}

# 操作系统->系统账户映射表
ACCOUNT_MAP = {
OsType.WINDOWS: settings.BACKEND_WINDOWS_ACCOUNT,
OsType.LINUX: "root",
OsType.AIX: "root",
OsType.SOLARIS: "root",
OsType.WINDOWS.lower(): settings.BACKEND_WINDOWS_ACCOUNT,
OsType.LINUX.lower: "root",
OsType.AIX.lower: "root",
OsType.SOLARIS.lower: "root",
}

OS_TYPE = {"1": "LINUX", "2": "WINDOWS", "3": "AIX"}
OS_TYPE = {"1": "LINUX", "2": "WINDOWS", "3": "AIX", "5": "SOLARIS"}

NODE_TUPLE = ("AGENT", "PROXY", "PAGENT")
NODE_CHOICES = tuple_choices(NODE_TUPLE)
Expand Down Expand Up @@ -439,13 +441,14 @@ def get_choices(cls):
PLUGIN_OS_CHOICES = tuple_choices(PLUGIN_OS_TUPLE)
PluginOsType = choices_to_namedtuple(PLUGIN_OS_CHOICES)

CPU_TUPLE = ("x86", "x86_64", "powerpc", "aarch64")
CPU_TUPLE = ("x86", "x86_64", "powerpc", "aarch64", "sparc")
CPU_CHOICES = tuple_choices(CPU_TUPLE)
CpuType = choices_to_namedtuple(CPU_CHOICES)
DEFAULT_OS_CPU_MAP = {
OsType.LINUX: CpuType.x86_64,
OsType.WINDOWS: CpuType.x86_64,
OsType.AIX: CpuType.powerpc,
OsType.SOLARIS: CpuType.sparc,
}

# TODO: 部署方式,后续确认
Expand Down Expand Up @@ -603,6 +606,7 @@ class SetupScriptFileName(Enum):
SETUP_AGENT_BAT = "setup_agent.bat"
SETUP_PAGENT_PY = "setup_pagent.py"
GSECTL_BAT = "gsectl.bat"
SETUP_AGENT_SOLARIS_SH = "setup_solaris_agent.sh"


class BkJobStatus(object):
Expand Down Expand Up @@ -745,3 +749,11 @@ class PolicyRollBackType:
"name": _("下发安装工具"),
},
]


SCRIPT_FILE_NAME_MAP = {
OsType.LINUX: SetupScriptFileName.SETUP_AGENT_SH.value,
OsType.WINDOWS: SetupScriptFileName.SETUP_AGENT_BAT.value,
OsType.AIX: SetupScriptFileName.SETUP_AGENT_KSH.value,
OsType.SOLARIS: SetupScriptFileName.SETUP_AGENT_SOLARIS_SH.value,
}
5 changes: 3 additions & 2 deletions apps/node_man/handlers/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
from django.conf import settings
from django.db import connection
from django.utils.translation import ugettext as _
from apps.node_man.handlers.install_channel import InstallChannelHandler

from apps.node_man import constants, models, tools
from apps.node_man.handlers.cloud import CloudHandler
from apps.node_man.handlers.cmdb import CmdbHandler
from apps.node_man.handlers.install_channel import InstallChannelHandler
from apps.utils import APIModel


Expand Down Expand Up @@ -351,7 +351,8 @@ def fetch_plugin_host_condition(self):
os_dict = {"name": _("操作系统"), "id": "os_type", "children": []}

for os_type in constants.OS_TUPLE:
if os_type == constants.OsType.AIX and settings.BKAPP_RUN_ENV == constants.BkappRunEnvType.CE.value:
special_os_type = [constants.OsType.AIX, constants.OsType.SOLARIS]
if os_type in special_os_type and settings.BKAPP_RUN_ENV == constants.BkappRunEnvType.CE.value:
continue
os_dict["children"].append(
{"id": os_type, "name": os_type if os_type == constants.OsType.AIX else os_type.capitalize()}
Expand Down
52 changes: 52 additions & 0 deletions apps/node_man/migrations/0027_auto_20210803_1421.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 2.2.8 on 2021-08-03 06:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("node_man", "0026_accesspoint_outer_callback_url"),
]

operations = [
migrations.AlterField(
model_name="host",
name="os_type",
field=models.CharField(
choices=[("LINUX", "LINUX"), ("WINDOWS", "WINDOWS"), ("AIX", "AIX"), ("SOLARIS", "SOLARIS")],
db_index=True,
default="LINUX",
max_length=45,
verbose_name="操作系统",
),
),
migrations.AlterField(
model_name="packages",
name="cpu_arch",
field=models.CharField(
choices=[
("x86", "x86"),
("x86_64", "x86_64"),
("powerpc", "powerpc"),
("aarch64", "aarch64"),
("sparc", "sparc"),
],
db_index=True,
default="x86_64",
max_length=32,
verbose_name="CPU类型",
),
),
migrations.AlterField(
model_name="pushfilerecord",
name="os_type",
field=models.CharField(
choices=[("LINUX", "LINUX"), ("WINDOWS", "WINDOWS"), ("AIX", "AIX"), ("SOLARIS", "SOLARIS")],
db_index=True,
default="LINUX",
max_length=45,
verbose_name="操作系统",
),
),
]
13 changes: 13 additions & 0 deletions apps/node_man/migrations/0054_merge_20210925_0031.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 2.2.6 on 2021-09-24 16:31

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("node_man", "0053_merge_20210910_1624"),
("node_man", "0027_auto_20210803_1421"),
]

operations = []
4 changes: 2 additions & 2 deletions apps/node_man/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ def install_channel(self):
@property
def agent_config(self):
os_type = self.os_type.lower()
# AIX与Linux共用配置
if self.os_type == constants.OsType.AIX:
# AIX、SOLARIS与Linux共用配置
if self.os_type in [constants.OsType.AIX, constants.OsType.SOLARIS]:
os_type = constants.OsType.LINUX.lower()
return self.ap.agent_config[os_type]

Expand Down
1 change: 1 addition & 0 deletions apps/node_man/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def test_fetch_plugin_list_condition_no_permission(self, *args, **kwargs):
{"id": "LINUX", "name": "Linux"},
{"id": "WINDOWS", "name": "Windows"},
{"id": "AIX", "name": "AIX"},
{"id": "SOLARIS", "name": "Solaris"},
],
},
)
Expand Down
2 changes: 2 additions & 0 deletions dev_log/2.1.348/xcwang_202109152020.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feature:
- "支持solaris操作系统安装(close #110)"
2 changes: 1 addition & 1 deletion frontend/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getSysOptions = () => {
{ id: 'LINUX', name: 'Linux' },
];
if (window.PROJECT_CONFIG.BKAPP_RUN_ENV !== 'ce') {
options.push({ id: 'AIX', name: 'AIX' });
options.push({ id: 'AIX', name: 'AIX' }, { id: 'SOLARIS', name: 'Solaris' });
}
return options;
};
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/agent/agent-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ export default class AgentList extends Mixins(pollMixin, TableHeaderMixins, auth
LINUX: 'Linux',
WINDOWS: 'Windows',
AIX: 'AIX',
SOLARIS: 'Solaris',
};
// 批量操作
private operate: IOperateItem[] = [
Expand Down
Loading

0 comments on commit ead7586

Please sign in to comment.