~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to nova/compute/instance_types.py

  • Committer: Tarmac
  • Author(s): termie
  • Date: 2011-04-12 14:32:03 UTC
  • mfrom: (975.1.1 docstring_cleanup)
  • Revision ID: tarmac-20110412143203-rv6rn10d8wb8uel0
Docstring cleanup and formatting. Minor style fixes as well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#    License for the specific language governing permissions and limitations
19
19
#    under the License.
20
20
 
21
 
"""
22
 
The built-in instance properties.
23
 
"""
 
21
"""Built-in instance properties."""
24
22
 
25
23
from nova import context
26
24
from nova import db
34
32
 
35
33
def create(name, memory, vcpus, local_gb, flavorid, swap=0,
36
34
           rxtx_quota=0, rxtx_cap=0):
37
 
    """Creates instance types / flavors
38
 
       arguments: name memory vcpus local_gb flavorid swap rxtx_quota rxtx_cap
39
 
    """
 
35
    """Creates instance types."""
40
36
    for option in [memory, vcpus, local_gb, flavorid]:
41
37
        try:
42
38
            int(option)
64
60
 
65
61
 
66
62
def destroy(name):
67
 
    """Marks instance types / flavors as deleted
68
 
    arguments: name"""
 
63
    """Marks instance types as deleted."""
69
64
    if name == None:
70
65
        raise exception.InvalidInputException(_("No instance type specified"))
71
66
    else:
77
72
 
78
73
 
79
74
def purge(name):
80
 
    """Removes instance types / flavors from database
81
 
    arguments: name"""
 
75
    """Removes instance types from database."""
82
76
    if name == None:
83
77
        raise exception.InvalidInputException(_("No instance type specified"))
84
78
    else:
90
84
 
91
85
 
92
86
def get_all_types(inactive=0):
93
 
    """Retrieves non-deleted instance_types.
94
 
    Pass true as argument if you want deleted instance types returned also."""
 
87
    """Get all non-deleted instance_types.
 
88
 
 
89
    Pass true as argument if you want deleted instance types returned also.
 
90
 
 
91
    """
95
92
    return db.instance_type_get_all(context.get_admin_context(), inactive)
96
93
 
97
94
 
98
 
def get_all_flavors():
99
 
    """retrieves non-deleted flavors. alias for instance_types.get_all_types().
100
 
    Pass true as argument if you want deleted instance types returned also."""
101
 
    return get_all_types(context.get_admin_context())
 
95
get_all_flavors = get_all_types
102
96
 
103
97
 
104
98
def get_default_instance_type():
 
99
    """Get the default instance type."""
105
100
    name = FLAGS.default_instance_type
106
101
    try:
107
102
        return get_instance_type_by_name(name)
110
105
 
111
106
 
112
107
def get_instance_type(id):
113
 
    """Retrieves single instance type by id"""
 
108
    """Retrieves single instance type by id."""
114
109
    if id is None:
115
110
        return get_default_instance_type()
116
111
    try:
121
116
 
122
117
 
123
118
def get_instance_type_by_name(name):
124
 
    """Retrieves single instance type by name"""
 
119
    """Retrieves single instance type by name."""
125
120
    if name is None:
126
121
        return get_default_instance_type()
127
122
    try:
131
126
        raise exception.ApiError(_("Unknown instance type: %s") % name)
132
127
 
133
128
 
 
129
# TODO(termie): flavor-specific code should probably be in the API that uses
 
130
#               flavors.
134
131
def get_instance_type_by_flavor_id(flavor_id):
135
 
    """retrieve instance type by flavor_id"""
 
132
    """Retrieve instance type by flavor_id."""
136
133
    if flavor_id is None:
137
134
        return get_default_instance_type()
138
135
    try: