Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
jijisa
/
porch
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f8e0246d
authored
Mar 28, 2017
by
Heechul Kim
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
added disk partition templates
parent
c87a379a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
5 deletions
porch/api/machine/bizlogic.py
porch/api/machine/endpoints/route.py
porch/api/machine/serializers.py
porch/templates/dpt-default.j2
porch/api/machine/bizlogic.py
View file @
f8e0246d
import
os
import
re
import
ast
import
glob
import
uuid
import
time
import
etcd
...
...
@@ -145,6 +147,25 @@ def provision_machine(name):
s_msg
=
'Fail to create pxelinuxcfg file: {}.'
.
format
(
s_pxelinuxcfg
)
return
(
False
,
s_msg
)
# Create Disk partition table
if
not
d
.
get
(
'dpt'
):
d
[
'dpt'
]
=
'default'
# default dpt assigned.
s_tmpl
=
'dpt-{}.j2'
.
format
(
d
[
'dpt'
])
if
not
os
.
path
.
isfile
(
APP_ROOT
+
'/templates/{}'
.
format
(
s_tmpl
)):
s_msg
=
'Cannot find disk template {}'
.
format
(
s_tmpl
)
log
.
error
(
s_msg
)
return
(
False
,
s_msg
)
s_out
=
render_template
(
s_tmpl
)
# no context needed.
dpt_file
=
FAI_DIR
+
'/config/dpt-{}'
.
format
(
d
[
'name'
])
try
:
with
open
(
dpt_file
,
'w'
)
as
f
:
f
.
write
(
s_out
)
except
:
s_msg
=
'Fail to create dpt file: {}'
.
format
(
dpt_file
)
log
.
error
(
s_msg
)
return
(
False
,
s_msg
)
# Create service network config file svc-interface if svc_nic exists.
svc_iface_file
=
''
if
'svc_nic'
in
d
and
d
.
get
(
'svc_nic'
):
...
...
@@ -213,13 +234,19 @@ def provision_machine(name):
# o_tar.add(s_pubkey_file, arcname='pubkeys/{}'.format(d['ip']))
if
svc_iface_file
:
o_tar
.
add
(
svc_iface_file
,
arcname
=
'svc-interface'
)
o_tar
.
add
(
dpt_file
,
arcname
=
'disk_config/{}'
.
format
(
d
[
'name'
]))
# clean up dpt_file
try
:
os
.
unlink
(
dpt_file
)
except
Exception
as
e
:
log
.
warn
(
e
)
# clean up svc_iface_file if exists.
if
svc_iface_file
:
try
:
os
.
unlink
(
svc_iface_file
)
except
Exception
as
e
:
log
.
error
(
e
)
log
.
warn
(
e
)
# finally update machine state = provisioned
update_machine
(
name
,
{
'state'
:
'Provisioned'
})
...
...
@@ -293,21 +320,34 @@ def delete_machine(name):
return
(
False
,
e
)
d
=
ast
.
literal_eval
(
r
.
value
)
s_mac
=
d
[
'mac'
]
# delete machine key
s_rsc
=
'{}/machine/{}'
.
format
(
etcdc
.
prefix
,
name
)
etcdc
.
delete
(
s_rsc
)
# delete macaddr key
s_rsc
=
'{}/macaddr/{}'
.
format
(
etcdc
.
prefix
,
s_mac
)
s_rsc
=
'{}/macaddr/{}'
.
format
(
etcdc
.
prefix
,
d
[
'mac'
]
)
etcdc
.
delete
(
s_rsc
)
# delete dhcp entry
s_cmd
=
"{} -r {}"
.
format
(
DHCPEDIT
,
d
[
'mac'
])
log
.
debug
(
s_cmd
)
cmd
(
s_cmd
,
b_sudo
=
True
)
# delete pxelinuxcfg entry
s_mac
=
'01-'
+
d
[
'mac'
]
.
replace
(
':'
,
'-'
)
s_pxelinuxcfg
=
"{}/{}"
.
format
(
PXELINUXCFG
,
s_mac
)
try
:
os
.
unlink
(
s_pxelinuxcfg
)
except
Exception
as
e
:
log
.
warn
(
e
)
# delete tarball
s_tarball
=
"{}/{}.tar"
.
format
(
TFTP_FAI_DIR
,
name
)
try
:
os
.
unlink
(
s_tarball
)
except
Exception
as
e
:
log
.
warn
(
e
)
return
(
True
,
'machine {} is deleted.'
.
format
(
name
))
def
install_machine
(
data
):
...
...
@@ -468,3 +508,16 @@ def close_console_machine(name):
log
.
info
(
'pid {} is killed.'
.
format
(
i_pid
))
return
True
def
dpt_machine
():
"""Get disk partition templates."""
l_dpt
=
list
()
# dpt-<name>.j2 in APP_ROOT + '/templates/'
l
=
glob
.
glob
(
APP_ROOT
+
'/templates/dpt-*.j2'
)
for
s
in
l
:
s_dpt
=
os
.
path
.
basename
(
s
)
m
=
re
.
match
(
r"^dpt-(.*)\.j2"
,
s_dpt
)
l_dpt
.
append
(
m
.
group
(
1
))
return
l_dpt
porch/api/machine/endpoints/route.py
View file @
f8e0246d
...
...
@@ -26,6 +26,7 @@ from porch.api.machine.bizlogic import provision_machine
from
porch.api.machine.bizlogic
import
install_machine
from
porch.api.machine.bizlogic
import
show_console_machine
from
porch.api.machine.bizlogic
import
close_console_machine
from
porch.api.machine.bizlogic
import
dpt_machine
log
=
logging
.
getLogger
(
'porch'
)
...
...
@@ -185,3 +186,14 @@ class MachineInstalled(Resource):
return
d_msg
,
i_ret_code
@ns.route
(
'/dpt'
)
@api.response
(
404
,
'App not found.'
)
class
MachineDPT
(
Resource
):
@jwt_required
def
get
(
self
):
"""Returns disk partition templates.
"""
l_dpt
=
list
()
l_dpt
=
dpt_machine
()
return
l_dpt
porch/api/machine/serializers.py
View file @
f8e0246d
...
...
@@ -9,6 +9,7 @@ machineSerializer = api.model('ListMachine', {
'section'
:
fields
.
String
(
required
=
True
,
default
=
'default'
,
description
=
'the section machine belongs to'
),
'os'
:
fields
.
String
(
required
=
True
,
description
=
'machine os'
),
'dpt'
:
fields
.
String
(
required
=
True
,
description
=
'machine disk partition'
),
'preseed'
:
fields
.
String
(
required
=
True
,
default
=
''
,
description
=
'machine preseed'
),
'mac'
:
fields
.
String
(
required
=
True
,
description
=
'machine mac'
),
...
...
@@ -30,8 +31,9 @@ machinePostSerializer = api.model('RegisterMachine', {
'name'
:
fields
.
String
(
required
=
True
,
description
=
'machine hostname'
),
'type'
:
fields
.
String
(
required
=
True
,
description
=
'type: PM or VM'
),
'desc'
:
fields
.
String
(
required
=
False
,
description
=
'machine description'
),
'dpt'
:
fields
.
String
(
required
=
True
,
description
=
'machine disk partition'
),
'os'
:
fields
.
String
(
required
=
True
,
description
=
'machine os'
),
'preseed'
:
fields
.
String
(
required
=
Tru
e
,
default
=
''
,
'preseed'
:
fields
.
String
(
required
=
Fals
e
,
default
=
''
,
description
=
'machine preseed'
),
'mac'
:
fields
.
String
(
required
=
True
,
description
=
'machine mac'
),
'ip'
:
fields
.
String
(
required
=
True
,
description
=
'machine ip address'
),
...
...
@@ -48,6 +50,7 @@ machinePatchSerializer = api.model('ModifyMachine', {
'section'
:
fields
.
String
(
required
=
False
,
description
=
'the section machine belongs to'
),
'os'
:
fields
.
String
(
required
=
False
,
description
=
'machine os'
),
'dpt'
:
fields
.
String
(
required
=
True
,
description
=
'machine disk partition'
),
'ipmi_ip'
:
fields
.
String
(
required
=
False
,
description
=
'machine ipmi ip'
),
'svc_nic'
:
fields
.
String
(
required
=
False
,
description
=
'machine svc nic'
),
'svc_ip'
:
fields
.
String
(
required
=
False
,
description
=
'machine svc ip'
),
...
...
porch/templates/dpt-default.j2
0 → 100644
View file @
f8e0246d
disk_config disk1 disklabel:msdos bootable:1 fstabkey:label
primary swap 1G swap sw
primary / 5G- ext4 rw,noatime,errors=remount-ro
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment