~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/virt/powervm/lpar.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 IBM
 
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
 
8
#
 
9
#         http://www.apache.org/licenses/LICENSE-2.0
 
10
#
 
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
 
15
#    under the License.
 
16
 
 
17
"""PowerVM Logical Partition (LPAR)
 
18
 
 
19
PowerVM LPAR configuration attributes.
 
20
"""
 
21
 
 
22
import shlex
 
23
 
 
24
from nova.openstack.common import log as logging
 
25
from nova.virt.powervm import exception
 
26
 
 
27
LOG = logging.getLogger(__name__)
 
28
 
 
29
 
 
30
def load_from_conf_data(conf_data):
 
31
    """LPAR configuration data parser.
 
32
 
 
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
 
36
    value format.
 
37
    Example format: name=lpar_name,lpar_id=1,lpar_env=aixlinux
 
38
 
 
39
    :param conf_data: string containing the LPAR configuration data.
 
40
    :returns: LPAR -- LPAR object.
 
41
    """
 
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
 
45
    # split them by ','.
 
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))
 
50
    lpar = LPAR()
 
51
    for (key, value) in attribs.items():
 
52
        lpar[key] = value
 
53
    return lpar
 
54
 
 
55
 
 
56
class LPAR(object):
 
57
 
 
58
    """
 
59
    Simple class representing a logical partition and the attributes
 
60
    for the partition and/or its selected profile.
 
61
    """
 
62
 
 
63
    # Attributes for all logical partitions
 
64
    LPAR_ATTRS = (
 
65
        'name',
 
66
        'lpar_id',
 
67
        'lpar_env',
 
68
        'state',
 
69
        'resource_config',
 
70
        'os_version',
 
71
        'logical_serial_num',
 
72
        'default_profile',
 
73
        'profile_name',
 
74
        'curr_profile',
 
75
        'work_group_id',
 
76
        'allow_perf_collection',
 
77
        'power_ctrl_lpar_ids',
 
78
        'boot_mode',
 
79
        'lpar_keylock',
 
80
        'auto_start',
 
81
        'uptime',
 
82
        'lpar_avail_priority',
 
83
        'desired_lpar_proc_compat_mode',
 
84
        'curr_lpar_proc_compat_mode',
 
85
        'virtual_eth_mac_base_value',
 
86
        'rmc_ipaddr'
 
87
    )
 
88
 
 
89
    # Logical partitions may contain one or more profiles, which
 
90
    # may have the following attributes
 
91
    LPAR_PROFILE_ATTRS = (
 
92
        'name',
 
93
        'lpar_name',
 
94
        'lpar_id',
 
95
        'os_type',
 
96
        'all_resources',
 
97
        'mem_mode',
 
98
        'min_mem',
 
99
        'desired_mem',
 
100
        'max_mem',
 
101
        'proc_mode',
 
102
        'min_proc_units',
 
103
        'desired_proc_units',
 
104
        'max_proc_units',
 
105
        'min_procs',
 
106
        'desired_procs',
 
107
        'max_procs',
 
108
        'sharing_mode',
 
109
        'uncap_weight',
 
110
        'io_slots',
 
111
        'lpar_io_pool_ids',
 
112
        'max_virtual_slots',
 
113
        'virtual_serial_adapters',
 
114
        'virtual_scsi_adapters',
 
115
        'virtual_eth_adapters',
 
116
        'boot_mode',
 
117
        'conn_monitoring',
 
118
        'auto_start',
 
119
        'power_ctrl_lpar_ids',
 
120
        'lhea_logical_ports',
 
121
        'lhea_capabilities',
 
122
        'lpar_proc_compat_mode',
 
123
        'virtual_fc_adapters'
 
124
    )
 
125
 
 
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())
 
134
 
 
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)
 
139
 
 
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
 
144
 
 
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
 
150
 
 
151
    def to_string(self, exclude_attribs=[]):
 
152
        conf_data = []
 
153
        for (key, value) in self.all_attrs.items():
 
154
            if key in exclude_attribs or value is None:
 
155
                continue
 
156
            conf_data.append('%s=%s' % (key, value))
 
157
 
 
158
        return ','.join(conf_data)