1 # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
1 # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
2 |
2 |
3 # Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
3 # Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
4 # |
4 # |
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may |
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may |
6 # not use this file except in compliance with the License. You may obtain |
6 # not use this file except in compliance with the License. You may obtain |
7 # a copy of the License at |
7 # a copy of the License at |
8 # |
8 # |
25 DTD_URL = '/usr/share/lib/xml/dtd/service_bundle.dtd.1' |
25 DTD_URL = '/usr/share/lib/xml/dtd/service_bundle.dtd.1' |
26 DOCTYPE_STR = '<!DOCTYPE service_bundle SYSTEM "%s">' % DTD_URL |
26 DOCTYPE_STR = '<!DOCTYPE service_bundle SYSTEM "%s">' % DTD_URL |
27 |
27 |
28 |
28 |
29 def create_ncp_defaultfixed(addrtype, linkname, netid, ip_version, ip=None, |
29 def create_ncp_defaultfixed(addrtype, linkname, netid, ip_version, ip=None, |
30 route=None, nameservers=None): |
30 route=None, nameservers=None, host_routes=None): |
31 """ return an etree object representing fixed (static) networking |
31 """ return an etree object representing fixed (static) networking |
32 """ |
32 """ |
33 svcbundle = etree.Element("service_bundle", type="profile", |
33 svcbundle = etree.Element("service_bundle", type="profile", |
34 name="openstack") |
34 name="openstack") |
35 |
35 |
107 etree.SubElement(pg6, "propval", type="astring", |
107 etree.SubElement(pg6, "propval", type="astring", |
108 name="stateless", value="yes") |
108 name="stateless", value="yes") |
109 etree.SubElement(pg6, "propval", type="astring", |
109 etree.SubElement(pg6, "propval", type="astring", |
110 name="stateful", value="yes") |
110 name="stateful", value="yes") |
111 |
111 |
|
112 if host_routes: |
|
113 # create the host-routes profile |
|
114 for i, host_route in enumerate(host_routes): |
|
115 hr_dest = host_route['cidr'] |
|
116 hr_gw = host_route['gateway']['address'] |
|
117 hr_pg_name = "route_%d_%d" % (netid, i) |
|
118 hr_ip_version = host_route['gateway']['version'] |
|
119 if hr_ip_version == 4: |
|
120 hr_pg_type = "ipv4_route" |
|
121 hr_pval_type = "net_address_v4" |
|
122 else: |
|
123 hr_pg_type = "ipv6_route" |
|
124 hr_pval_type = "net_address_v6" |
|
125 pg = etree.SubElement(instance, "property_group", type=hr_pg_type, |
|
126 name=hr_pg_name) |
|
127 etree.SubElement(pg, "propval", type=hr_pval_type, |
|
128 name="destination", value=hr_dest) |
|
129 etree.SubElement(pg, "propval", type=hr_pval_type, |
|
130 name="gateway", value=hr_gw) |
|
131 |
112 # create DNS profile for static configurations |
132 # create DNS profile for static configurations |
113 if addrtype == "static" and nameservers is not None: |
133 if addrtype == "static" and nameservers is not None: |
114 dns = etree.SubElement(svcbundle, "service", version="1", |
134 dns = etree.SubElement(svcbundle, "service", version="1", |
115 type="service", name="network/dns/client") |
135 type="service", name="network/dns/client") |
116 etree.SubElement(dns, "instance", enabled="true", name="default") |
136 etree.SubElement(dns, "instance", enabled="true", name="default") |
131 etree.SubElement(search, "astring_list") |
151 etree.SubElement(search, "astring_list") |
132 |
152 |
133 return svcbundle |
153 return svcbundle |
134 |
154 |
135 |
155 |
136 def create_ncp_automatic(): |
|
137 """ return an etree object representing dynamic networking |
|
138 """ |
|
139 svcbundle = etree.Element("service_bundle", type="profile", |
|
140 name="openstack") |
|
141 |
|
142 # create the network/physical service profile |
|
143 physical = etree.SubElement(svcbundle, "service", version="1", |
|
144 type="service", name="network/physical") |
|
145 instance = etree.SubElement(physical, "instance", enabled="true", |
|
146 name="default") |
|
147 pg = etree.SubElement(instance, "property_group", type="application", |
|
148 name="netcfg") |
|
149 etree.SubElement(pg, "propval", type="astring", name="active_ncp", |
|
150 value="Automatic") |
|
151 |
|
152 return svcbundle |
|
153 |
|
154 |
|
155 def create_default_root_account(expire=None, sshkey=None, password=None): |
156 def create_default_root_account(expire=None, sshkey=None, password=None): |
156 """ return an etree object representing the root account |
157 """ return an etree object representing the root account |
157 """ |
158 """ |
158 svcbundle = etree.Element("service_bundle", type="profile", |
159 svcbundle = etree.Element("service_bundle", type="profile", |
159 name="openstack") |
160 name="openstack") |