def _ask_child_zone_to_create_instance(self, context, weighted_host, request_spec, kwargs): """Once we have determined that the request should go to one of our children, we need to fabricate a new POST /servers/ call with the same parameters that were passed into us. This request is always for a single instance. Note that we have to reverse engineer from our args to get back the image, flavor, ipgroup, etc. since the original call could have come in from EC2 (which doesn't use these things). """ instance_type = request_spec["instance_type"] instance_properties = request_spec["instance_properties"] name = instance_properties["display_name"] image_ref = instance_properties["image_ref"] meta = instance_properties["metadata"] flavor_id = instance_type["flavorid"] reservation_id = instance_properties["reservation_id"] files = kwargs["injected_files"] zone = db.zone_get(context.elevated(), weighted_host.zone) zone_name = zone.name url = zone.api_url LOG.debug( _("Forwarding instance create call to zone '%(zone_name)s'. " "ReservationID=%(reservation_id)s") % locals() ) nova = None try: # This operation is done as the caller, not the zone admin. nova = novaclient.Client( zone.username, zone.password, None, url, token=context.auth_token, region_name=zone_name ) nova.authenticate() except novaclient_exceptions.BadRequest, e: raise exception.NotAuthorized(_("Bad credentials attempting " "to talk to zone at %(url)s.") % locals())
def _ask_child_zone_to_create_instance(self, context, zone_info, request_spec, kwargs): """Once we have determined that the request should go to one of our children, we need to fabricate a new POST /servers/ call with the same parameters that were passed into us. Note that we have to reverse engineer from our args to get back the image, flavor, ipgroup, etc. since the original call could have come in from EC2 (which doesn't use these things). """ instance_type = request_spec["instance_type"] instance_properties = request_spec["instance_properties"] name = instance_properties["display_name"] image_ref = instance_properties["image_ref"] meta = instance_properties["metadata"] flavor_id = instance_type["flavorid"] reservation_id = instance_properties["reservation_id"] files = kwargs["injected_files"] ipgroup = None # Not supported in OS API ... yet child_zone = zone_info["child_zone"] child_blob = zone_info["child_blob"] zone = db.zone_get(context, child_zone) url = zone.api_url LOG.debug( _("Forwarding instance create call to child zone %(url)s" ". ReservationID=%(reservation_id)s") % locals() ) nova = None try: nova = novaclient.Client(zone.username, zone.password, None, url) nova.authenticate() except novaclient_exceptions.BadRequest, e: raise exception.NotAuthorized(_("Bad credentials attempting " "to talk to zone at %(url)s.") % locals())
def _ask_child_zone_to_create_instance(self, context, zone_info, request_spec, kwargs): """Once we have determined that the request should go to one of our children, we need to fabricate a new POST /servers/ call with the same parameters that were passed into us. Note that we have to reverse engineer from our args to get back the image, flavor, ipgroup, etc. since the original call could have come in from EC2 (which doesn't use these things). """ instance_type = request_spec['instance_type'] instance_properties = request_spec['instance_properties'] name = instance_properties['display_name'] image_ref = instance_properties['image_ref'] meta = instance_properties['metadata'] flavor_id = instance_type['flavorid'] reservation_id = instance_properties['reservation_id'] files = kwargs['injected_files'] child_zone = zone_info['child_zone'] child_blob = zone_info['child_blob'] zone = db.zone_get(context, child_zone) url = zone.api_url LOG.debug( _("Forwarding instance create call to child zone %(url)s" ". ReservationID=%(reservation_id)s") % locals()) nova = None try: nova = novaclient.Client(zone.username, zone.password, None, url) nova.authenticate() except novaclient_exceptions.BadRequest, e: raise exception.NotAuthorized( _("Bad credentials attempting " "to talk to zone at %(url)s.") % locals())
def zone_get(context, zone_id): return db.zone_get(context, zone_id)
def show(self, req, id): """Return data about the given zone id""" zone_id = int(id) zone = db.zone_get(req.environ['nova.context'], zone_id) return dict(zone=_scrub_zone(zone))