1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
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
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
"""PowerVM Logical Partition (LPAR)
19
PowerVM LPAR configuration attributes.
24
from nova.openstack.common import log as logging
25
from nova.virt.powervm import exception
27
LOG = logging.getLogger(__name__)
30
def load_from_conf_data(conf_data):
31
"""LPAR configuration data parser.
33
The configuration data is a string representation of
34
the attributes of a Logical Partition. The attributes
35
consists of name/value pairs, which are in command separated
37
Example format: name=lpar_name,lpar_id=1,lpar_env=aixlinux
39
:param conf_data: string containing the LPAR configuration data.
40
:returns: LPAR -- LPAR object.
42
# config_data can contain comma separated values within
43
# double quotes, example: virtual_serial_adapters
44
# and virtual_scsi_adapters attributes. So can't simply
46
cf_splitter = shlex.shlex(conf_data, posix=True)
47
cf_splitter.whitespace = ','
48
cf_splitter.whitespace_split = True
49
attribs = dict(item.split("=") for item in list(cf_splitter))
51
for (key, value) in attribs.items():
59
Simple class representing a logical partition and the attributes
60
for the partition and/or its selected profile.
63
# Attributes for all logical partitions
76
'allow_perf_collection',
77
'power_ctrl_lpar_ids',
82
'lpar_avail_priority',
83
'desired_lpar_proc_compat_mode',
84
'curr_lpar_proc_compat_mode',
85
'virtual_eth_mac_base_value',
89
# Logical partitions may contain one or more profiles, which
90
# may have the following attributes
91
LPAR_PROFILE_ATTRS = (
103
'desired_proc_units',
113
'virtual_serial_adapters',
114
'virtual_scsi_adapters',
115
'virtual_eth_adapters',
119
'power_ctrl_lpar_ids',
120
'lhea_logical_ports',
122
'lpar_proc_compat_mode',
123
'virtual_fc_adapters'
126
def __init__(self, **kwargs):
127
self.attributes = dict([k, None] for k in self.LPAR_ATTRS)
128
self.profile_attributes = dict([k, None] for k
129
in self.LPAR_PROFILE_ATTRS)
130
self.attributes.update(kwargs)
131
self.profile_attributes.update(kwargs)
132
self.all_attrs = dict(self.attributes.items()
133
+ self.profile_attributes.items())
135
def __getitem__(self, key):
136
if key not in self.all_attrs.keys():
137
raise exception.PowerVMLPARAttributeNotFound(key)
138
return self.all_attrs.get(key)
140
def __setitem__(self, key, value):
141
if key not in self.all_attrs.keys():
142
raise exception.PowerVMLPARAttributeNotFound(key)
143
self.all_attrs[key] = value
145
def __delitem__(self, key):
146
if key not in self.all_attrs.keys():
147
raise exception.PowerVMLPARAttributeNotFound(key)
148
# We set to None instead of removing the key...
149
self.all_attrs[key] = None
151
def to_string(self, exclude_attribs=[]):
153
for (key, value) in self.all_attrs.items():
154
if key in exclude_attribs or value is None:
156
conf_data.append('%s=%s' % (key, value))
158
return ','.join(conf_data)