Skip to content

Commit 1f1acf7

Browse files
authored
Merge pull request #1548 from swordqiu/hotfix/qj-support-arch-linux
fix: support archlinxu
2 parents 0417ccb + b2f4ef1 commit 1f1acf7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+720
-128
lines changed

lib/add_node.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,7 @@
77
from .service import AddNodeService, AddNodesConfig
88
from .cluster import construct_cluster
99
from .parser import inject_add_nodes_runtime_options
10-
11-
12-
def is_ipv4(addr):
13-
try:
14-
socket.inet_pton(socket.AF_INET, addr)
15-
return True
16-
except (OSError, AttributeError, socket.error):
17-
return False
18-
19-
20-
def is_ipv6(addr):
21-
try:
22-
socket.inet_pton(socket.AF_INET6, addr)
23-
return True
24-
except (OSError, AttributeError, socket.error):
25-
return False
10+
from .utils import is_ipv4, is_ipv6
2611

2712

2813
class AddWorkerNodeService(AddNodeService):

lib/service.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .parser import inject_ssh_hosts_options
1313
from . import utils
1414
from . import ansible
15+
from . import consts
1516
from .cluster import construct_cluster
1617
from .ocboot import WorkerConfig, Config
1718
from .ocboot import get_ansible_global_vars
@@ -164,13 +165,40 @@ def do_action(self, args):
164165
args.ssh_private_file,
165166
args.ssh_port)
166167

168+
if args.ip_type == '':
169+
if utils.is_ipv4(args.primary_master_host):
170+
args.ip_type = consts.IP_TYPE_IPV4
171+
elif utils.is_ipv6(args.primary_master_host):
172+
args.ip_type = consts.IP_TYPE_IPV6
173+
else:
174+
raise ValueError("ip type is not set and cannot be determined from primary master host")
175+
176+
# 处理双栈配置
177+
kwargs = {
178+
'ip_dual_conf': getattr(args, 'ip_dual_conf', None),
179+
'ip_type': args.ip_type,
180+
'offline_data_path': args.offline_data_path,
181+
}
182+
183+
# 如果是双栈配置,需要处理IPv4和IPv6地址
184+
if args.ip_type == consts.IP_TYPE_DUAL_STACK and hasattr(args, 'ip_dual_conf') and args.ip_dual_conf:
185+
# 确定哪个是IPv4,哪个是IPv6
186+
if utils.is_ipv4(args.target_node_hosts[0]):
187+
# 主IP是IPv4,ip_dual_conf是IPv6
188+
kwargs['node_ip_v4'] = args.target_node_hosts[0]
189+
kwargs['node_ip_v6'] = args.ip_dual_conf
190+
else:
191+
# 主IP是IPv6,ip_dual_conf是IPv4
192+
kwargs['node_ip_v4'] = args.ip_dual_conf
193+
kwargs['node_ip_v6'] = args.target_node_hosts[0]
194+
167195
config = AddNodesConfig(cluster,
168196
args.target_node_hosts,
169197
args.ssh_user,
170198
args.ssh_private_file,
171199
args.ssh_port,
172200
args.ssh_node_port,
173-
False, True)
201+
enable_host_on_vm=False, enable_lbagent=True, **kwargs)
174202
return config.run()
175203

176204

lib/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,16 @@ def generage_random_string(N=12):
115115
random.choice(string.ascii_uppercase + string.digits)
116116
for _ in range(N))
117117

118+
def is_ipv4(addr):
119+
try:
120+
socket.inet_pton(socket.AF_INET, addr)
121+
return True
122+
except (OSError, AttributeError, socket.error):
123+
return False
124+
125+
def is_ipv6(addr):
126+
try:
127+
socket.inet_pton(socket.AF_INET6, addr)
128+
return True
129+
except (OSError, AttributeError, socket.error):
130+
return False

onecloud/roles/common/tasks/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
# include_role:
44
# name: utils/misc-check
55

6+
- name: Verify OS is not debian based when lbagent is enabled
7+
fail:
8+
msg: "Cannot deploy lbagent on Debian based OS (AppArmor enabled OS)"
9+
when:
10+
- enable_lbagent
11+
- ansible_os_family == 'Debian'
12+
613
# 这里设置 primary_master_node_ip ,如果 primary_master_node_ip 不存在,则使用 hostvars[groups['primary_master_node'][0]]['node_ip']
714
- name: set primary_master_node_ip if not defined
815
set_fact:
@@ -218,3 +225,8 @@
218225
- name: Include cronjobs
219226
include_role:
220227
name: utils/cronjobs
228+
229+
- name: Install ceph and openvswitch scripts
230+
include_tasks: "symlink.yml"
231+
when:
232+
- onecloud_version is version('v4.0', '>=')
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
- name: Online pacman repo
2+
ansible.builtin.blockinfile:
3+
path: /etc/pacman.conf
4+
block: |
5+
[yunion]
6+
SigLevel = Optional TrustAll
7+
Server = https://iso.yunion.cn/archlinux/$repo/$arch/
8+
marker: "# {mark} ANSIBLE MANAGED BLOCK - yunion repo"
9+
insertafter: EOF
10+
create: true
11+
mode: '0600'
12+
become: yes
13+
when:
14+
- online_status is defined
15+
- online_status == 'online'
16+
17+
- name: ensure pacman repo synchronized
18+
shell: |
19+
pacman -Syy
20+
become: true
21+
22+
- name: Install Common Packages Via Loop
23+
package:
24+
name: "{{ package_item }}"
25+
retries: 3
26+
delay: 3
27+
with_items:
28+
- "{{ common_packages }}"
29+
loop_control:
30+
index_var: item_index
31+
label: "[{{ '%02d'|format(item_index + 1) }}/{{ common_packages|length }}] {{ package_item }}"
32+
loop_var: package_item
33+
become: yes
34+
tags:
35+
- package
36+
37+
- name: Install Latest Packages Via Loop {{ onecloud_version_abbr }}
38+
package:
39+
name: "{{ package_item }}"
40+
state: latest
41+
with_items:
42+
- "{{ latest_packages }}"
43+
become: yes
44+
retries: 6
45+
delay: 10
46+
register: latest_pkg_result
47+
until: latest_pkg_result.rc == 0
48+
ignore_errors: yes
49+
when:
50+
- latest_packages is defined
51+
loop_control:
52+
index_var: item_index
53+
label: "[{{ item_index + 1 }}/{{ latest_packages | length }}] {{ package_item | regex_replace('\\[.*|[*]', '') }}"
54+
loop_var: package_item
55+
tags:
56+
- package

onecloud/roles/common/tasks/os/debian_family.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,23 @@
6969
- onecloud_version is defined
7070
- onecloud_version is version('v3.10', '<=')
7171

72-
- name: install common packages via loop for Debian Family
72+
- name: Append ovs_packages to common_packages if ovs_packages is defined
73+
set_fact:
74+
common_packages: "{{ common_packages + ovs_packages }}"
75+
when:
76+
- ovs_packages is defined
77+
- common_packages is defined
78+
- onecloud_version is version('v4.0', '<')
79+
80+
- name: Append ceph_packages to common_packages if ceph_packages is defined
81+
set_fact:
82+
common_packages: "{{ common_packages + ceph_packages }}"
83+
when:
84+
- ceph_packages is defined
85+
- common_packages is defined
86+
- onecloud_version is version('v4.0', '<')
87+
88+
- name: Install common packages via loop for Debian Family
7389
package:
7490
name: "{{ package_item }}"
7591
become: true

onecloud/roles/common/tasks/os/redhat-general-repo.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@
3434
- online_status is defined
3535
- online_status == 'offline'
3636

37+
- name: Append ovs_preinstall_packages to preinstall_packages if ovs_preinstall_packages is defined
38+
set_fact:
39+
preinstall_packages: "{{ preinstall_packages + ovs_preinstall_packages }}"
40+
when:
41+
- ovs_preinstall_packages is defined
42+
- preinstall_packages is defined
43+
- onecloud_version is version('v4.0', '<')
44+
45+
- name: Append ceph_preinstall_packages to preinstall_packages if ceph_preinstall_packages is defined
46+
set_fact:
47+
preinstall_packages: "{{ preinstall_packages + ceph_preinstall_packages }}"
48+
when:
49+
- ceph_preinstall_packages is defined
50+
- preinstall_packages is defined
51+
- onecloud_version is version('v4.0', '<')
52+
3753
- name: Install Preinstall Packages Via Loop
3854
package:
3955
name: "{{ package_item }}"
@@ -54,7 +70,23 @@
5470
- preinstall_packages is defined
5571
- online_status == 'online'
5672

57-
- name: Install additional repos
73+
- name: Append ovs_imported_repos to imported_repos if ovs_imported_repos is defined
74+
set_fact:
75+
imported_repos: "{{ imported_repos + ovs_imported_repos }}"
76+
when:
77+
- ovs_imported_repos is defined
78+
- imported_repos is defined
79+
- onecloud_version is version('v4.0', '<')
80+
81+
- name: Append ceph_imported_repos to imported_repos if ceph_imported_repos is defined
82+
set_fact:
83+
imported_repos: "{{ imported_repos + ceph_imported_repos }}"
84+
when:
85+
- ceph_imported_repos is defined
86+
- imported_repos is defined
87+
- onecloud_version is version('v4.0', '<')
88+
89+
- name: Import additional repos
5890
shell: |
5991
REPO_NAME="yunion-repo-extra-{{ item_index }}"
6092
REPO_FILE="/etc/yum.repos.d/yunion-extra.repo"

onecloud/roles/common/tasks/os/redhat.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@
1414
- extra_packages is defined
1515
- common_packages is defined
1616

17+
- name: Append ovs_packages to common_packages if ovs_packages is defined
18+
set_fact:
19+
common_packages: "{{ common_packages + ovs_packages }}"
20+
when:
21+
- ovs_packages is defined
22+
- common_packages is defined
23+
- onecloud_version is version('v4.0', '<')
24+
25+
- name: Append ceph_packages to common_packages if ceph_packages is defined
26+
set_fact:
27+
common_packages: "{{ common_packages + ceph_packages }}"
28+
when:
29+
- ceph_packages is defined
30+
- common_packages is defined
31+
- onecloud_version is version('v4.0', '<')
32+
1733
- name: Install Common Packages Via Loop
1834
package:
1935
name: "{{ package_item }}"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
- name: install ceph scripts
3+
template:
4+
src: ceph.sh.j2
5+
dest: /opt/yunion/bin/ceph.sh
6+
mode: '0755'
7+
8+
- name: install openvswitch scripts
9+
template:
10+
src: ovs.sh.j2
11+
dest: /opt/yunion/bin/ovs.sh
12+
mode: '0755'
13+
14+
- name: install ceph
15+
file:
16+
src: /opt/yunion/bin/ceph.sh
17+
dest: /usr/local/bin/ceph
18+
state: link
19+
force: yes
20+
become: true
21+
22+
- name: install ovs-vsctl
23+
file:
24+
src: /opt/yunion/bin/ovs.sh
25+
dest: /usr/local/bin/ovs-vsctl
26+
state: link
27+
force: yes
28+
become: true
29+
30+
- name: install ovs-ofctl
31+
file:
32+
src: /opt/yunion/bin/ovs.sh
33+
dest: /usr/local/bin/ovs-ofctl
34+
state: link
35+
force: yes
36+
become: true
37+
38+
- name: install ovs-appctl
39+
file:
40+
src: /opt/yunion/bin/ovs.sh
41+
dest: /usr/local/bin/ovs-appctl
42+
state: link
43+
force: yes
44+
become: true
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
IMG={{ insecure_registry | default('registry.cn-beijing.aliyuncs.com') }}/{{ registry | default('yunionio') }}/ceph:v16.2.14
4+
5+
{% if k8s_or_k3s | default('k3s') == 'k3s' %}
6+
k3s ctr images list name==$IMG -q | grep $IMG > /dev/null
7+
if [ $? -ne 0 ]; then
8+
k3s ctr images pull $IMG
9+
fi
10+
11+
k3s ctr run --rm --net-host -t \
12+
--mount type=bind,src=/tmp,dst=/tmp,options=rbind \
13+
$IMG \
14+
ceph-common \
15+
/usr/bin/$(basename $0) $@
16+
{% else %}
17+
docker run --rm --network host \
18+
-v /tmp:/tmp \
19+
$IMG \
20+
/usr/bin/$(basename $0) $@
21+
{% endif %}
22+

0 commit comments

Comments
 (0)