~soren/nova/doc-build-dir

« back to all changes in this revision

Viewing changes to nova/scheduler/manager.py

  • Committer: Tarmac
  • Author(s): Kei Masumoto, jaypipes at gmail
  • Date: 2011-03-14 18:11:30 UTC
  • mfrom: (439.1.55 live-migration)
  • Revision ID: tarmac-20110314181130-4d3yrklbdi8kilcm
NTT's live-migration branch, merged with trunk, conflicts resolved, and migrate file renamed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
                 {"method": method,
78
78
                  "args": kwargs})
79
79
        LOG.debug(_("Casting to %(topic)s %(host)s for %(method)s") % locals())
 
80
 
 
81
    # NOTE (masumotok) : This method should be moved to nova.api.ec2.admin.
 
82
    #                    Based on bexar design summit discussion,
 
83
    #                    just put this here for bexar release.
 
84
    def show_host_resources(self, context, host, *args):
 
85
        """Shows the physical/usage resource given by hosts.
 
86
 
 
87
        :param context: security context
 
88
        :param host: hostname
 
89
        :returns:
 
90
            example format is below.
 
91
            {'resource':D, 'usage':{proj_id1:D, proj_id2:D}}
 
92
            D: {'vcpus':3, 'memory_mb':2048, 'local_gb':2048}
 
93
 
 
94
        """
 
95
 
 
96
        compute_ref = db.service_get_all_compute_by_host(context, host)
 
97
        compute_ref = compute_ref[0]
 
98
 
 
99
        # Getting physical resource information
 
100
        compute_node_ref = compute_ref['compute_node'][0]
 
101
        resource = {'vcpus': compute_node_ref['vcpus'],
 
102
                    'memory_mb': compute_node_ref['memory_mb'],
 
103
                    'local_gb': compute_node_ref['local_gb'],
 
104
                    'vcpus_used': compute_node_ref['vcpus_used'],
 
105
                    'memory_mb_used': compute_node_ref['memory_mb_used'],
 
106
                    'local_gb_used': compute_node_ref['local_gb_used']}
 
107
 
 
108
        # Getting usage resource information
 
109
        usage = {}
 
110
        instance_refs = db.instance_get_all_by_host(context,
 
111
                                                    compute_ref['host'])
 
112
        if not instance_refs:
 
113
            return {'resource': resource, 'usage': usage}
 
114
 
 
115
        project_ids = [i['project_id'] for i in instance_refs]
 
116
        project_ids = list(set(project_ids))
 
117
        for project_id in project_ids:
 
118
            vcpus = db.instance_get_vcpu_sum_by_host_and_project(context,
 
119
                                                                 host,
 
120
                                                                 project_id)
 
121
            mem = db.instance_get_memory_sum_by_host_and_project(context,
 
122
                                                                 host,
 
123
                                                                 project_id)
 
124
            hdd = db.instance_get_disk_sum_by_host_and_project(context,
 
125
                                                               host,
 
126
                                                               project_id)
 
127
            usage[project_id] = {'vcpus': int(vcpus),
 
128
                                 'memory_mb': int(mem),
 
129
                                 'local_gb': int(hdd)}
 
130
 
 
131
        return {'resource': resource, 'usage': usage}