Beispiel #1
0
    def reassign():
        # NOTE(akscram): Initialization of fuelclient.
        fuel_config = flask.current_app.config["CLOUDS"]["fuel"]["endpoint"]
        os.environ["SERVER_ADDRESS"] = fuel_config["host"]
        os.environ["LISTEN_PORT"] = str(fuel_config["port"])
        os.environ["KEYSTONE_USER"] = fuel_config["username"]
        os.environ["KEYSTONE_PASS"] = fuel_config["password"]

        src_config = hooks.source.config()
        dst_config = hooks.destination.config()
        config = {
            "source": src_config["environment"],
            "destination": dst_config["environment"],
        }

        try:
            src = hooks.source.connect()
            dst = hooks.destination.connect()
            ctx = context.Context(config, src, dst)

            flow = node_tasks.reassign_node(ctx, host_id)
            LOG.debug("Reassigning flow: %s", flow)
            result = flows.run_flow(flow, ctx.store)
            LOG.debug("Result of migration: %s", result)
        except Exception:
            msg = ("Error is occured during reassigning host {}"
                   .format(host_id))
            LOG.exception(msg)
            events.emit("error", {
                "message": msg,
            }, namespace="/events")
Beispiel #2
0
 def created_event(self, flavor):
     LOG.info("Flavor created: %s", flavor.id)
     events.emit(
         "create",
         {"id": flavor.id, "type": "flavor", "cloud": self.cloud.name, "data": flavor.to_dict()},
         namespace="/events",
     )
Beispiel #3
0
 def unassign_start_event(self, node):
     events.emit("update", {
         "id": extract_hostname(node.data),
         "cloud": self.cloud.name,
         "type": "host",
         "action": "reassignment",
     }, namespace="/events")
Beispiel #4
0
 def delete_event(self, keypair_info):
     LOG.info("Deleted keypair: %s", keypair_info["name"])
     events.emit(
         "delete",
         {"id": keypair_info["name"], "type": "keypair", "cloud": self.cloud.name, "data": None},
         namespace="/events",
     )
Beispiel #5
0
 def create_event(self, keypair):
     LOG.info("Created keypair: %s", keypair.name)
     events.emit(
         "create",
         {"id": keypair.name, "type": "keypair", "cloud": self.cloud.name, "data": keypair.to_dict()},
         namespace="/events",
     )
Beispiel #6
0
 def created_event(self, secgroup_info):
     events.emit("create", {
         "id": secgroup_info["id"],
         "type": "secgroup",
         "cloud": self.cloud.name,
         "data": secgroup_info,
     }, namespace="/events")
Beispiel #7
0
 def upload_to_glance_event(self, image_info):
     LOG.info("Created: %s", image_info)
     events.emit("create", {
         "id": image_info["id"],
         "cloud": self.cloud.name,
         "type": "image",
         "data": dict(image_info)
     }, namespace="/events")
Beispiel #8
0
 def upload_to_glance_event(self, image_info):
     LOG.info("Created: %s", image_info)
     events.emit("volume snapshot create", {
         "cloud": self.cloud.name,
         "id": image_info["id"],
         "name": image_info["name"],
         "status": "active",
     }, namespace="/events")
Beispiel #9
0
 def created_event(self, floating_ip):
     events.emit("create", {
         "id": floating_ip.address,
         "type": "floating_ip",
         "cloud": self.cloud.name,
         "data": dict(floating_ip.to_dict(),
                      name=floating_ip.address),
     }, namespace="/events")
Beispiel #10
0
 def update_event(self, service):
     events.emit("update", {
         "id": service["host"],
         "cloud": self.cloud.name,
         "type": "host",
         "progress": None,
         "action": None,
     }, namespace="/events")
Beispiel #11
0
 def resume_event(self, server):
     LOG.info("Server resumed: %s", server["id"])
     events.emit("update", {
         "id": server["id"],
         "cloud": self.cloud.name,
         "type": "server",
         "data": server,
     }, namespace="/events")
Beispiel #12
0
 def execute(self, server_id):
     LOG.info("Migration of server %r started", server_id)
     events.emit("update", {
         "id": server_id,
         "cloud": self.cloud.name,
         "type": "server",
         "action": "migration",
     }, namespace="/events")
Beispiel #13
0
 def created_event(self, tenant):
     LOG.info("Tenant created: %s", tenant.id)
     events.emit("create", {
         "id": tenant.id,
         "type": "tenant",
         "cloud": self.cloud.name,
         "data": tenant.to_dict(),
     }, namespace="/events")
Beispiel #14
0
 def created_event(self, snapshot):
     events.emit("create", {
         "id": snapshot["id"],
         "type": "image",
         "cloud": self.cloud.name,
         "action": "uploading",
         "data": dict(snapshot),
     }, namespace="/events")
Beispiel #15
0
 def created_event(self, user):
     LOG.info("Created user: %s", user)
     events.emit("create", {
         "id": user.id,
         "type": "user",
         "cloud": self.cloud.name,
         "data": user.to_dict(),
     }, namespace="/events")
Beispiel #16
0
 def execute(self, volume, target_host):
     LOG.info("Evacuating volume %s to host %s...", volume.id, target_host)
     self.cloud.cinder.volumes.migrate_volume(volume, target_host, False)
     volume = utils.wait_for(volume.id, self.cloud.cinder.volumes.get,
                             get_volume_host, target_host)
     events.emit("update", event_from(self.cloud, volume),
                 namespace="/events")
     LOG.info("Evacuated volume %s to host %s", volume.id, target_host)
Beispiel #17
0
 def assigned_event(self, address, server_id):
     events.emit("update", {
         "id": address,
         "type": "floating_ip",
         "cloud": self.cloud.name,
         "data": {
             "server_id": server_id,
         }
     }, namespace="/events")
Beispiel #18
0
 def created_event(self, image):
     LOG.info("Image created: %s", image["id"])
     events.emit("create", {
         "id": image["id"],
         "type": "image",
         "cloud": self.dst_cloud.name,
         "action": "uploading",
         "data": dict(image),
     }, namespace="/events")
Beispiel #19
0
 def detach_event(self, volume_id):
     LOG.info("Volume updated: %s", volume_id)
     events.emit("update", {
         "id": volume_id,
         "cloud": self.cloud.name,
         "type": "volume",
         "action": "detach",
         "data": dict(server_ids=[]),
     }, namespace="/events")
Beispiel #20
0
 def uploaded_event(self, image):
     LOG.info("Image uploaded: %s", image["id"])
     events.emit("update", {
         "id": image["id"],
         "type": "image",
         "cloud": self.dst_cloud.name,
         "progress": None,
         "action": None,
         "data": dict(image),
     }, namespace="/events")
Beispiel #21
0
 def block_event(self, hostname):
     LOG.info("Service %r was blocked on host %r", self.binary, hostname)
     events.emit("update", {
         "id": hostname,
         "type": "host",
         "cloud": self.cloud.name,
         "data": {
             "status": "blocked",
         }
     }, namespace="/events")
Beispiel #22
0
 def create_volume_event(self, volume_info):
     LOG.info("Created: %s", volume_info)
     events.emit("volume create", {
         "cloud": self.cloud.name,
         "id": volume_info["id"],
         "status": "active",
         "display_name": volume_info["display_name"],
         "tenant_id": volume_info.get("os-vol-tenant-attr:tenant_id"),
         "host_id": volume_info.get("os-vol-host-attr:host"),
         "attachment_server_ids": [],
     }, namespace="/events")
Beispiel #23
0
 def assign_start_event(self, node):
     hostname = extract_hostname(node.data)
     events.emit("create", {
         "id": hostname,
         "cloud": self.cloud.name,
         "type": "host",
         "action": "reassignment",
         "data": {
             "name": hostname,
         }
     }, namespace="/events")
Beispiel #24
0
 def provisioning_event(self, progress, node):
     LOG.debug("Waiting for deploy: %r, %r", progress, node)
     events.emit("update", {
         "id": extract_hostname(node.data),
         "type": "host",
         "cloud": self.cloud.name,
         "progress": node.data["progress"],
         "data": {
             "status": node.data["status"],
         }
     }, namespace="/events")
Beispiel #25
0
 def terminate_event(self, server):
     LOG.info("Server terminated: %s", server["id"])
     events.emit("delete", {
         "id": server["id"],
         "type": "server",
         "cloud": self.cloud.name,
     }, namespace="/events")
     server_volumes = server.get("os-extended-volumes:volumes_attached",
                                 [])
     for volume in server_volumes:
         self.detach_event(volume["id"])
Beispiel #26
0
 def create_volume_event(self, volume_info):
     LOG.info("Created: %s", volume_info)
     events.emit("create", {
         "id": volume_info["id"],
         "cloud": self.cloud.name,
         "type": "volume",
         "data": dict(volume_info,
                      host_id=volume_info.get("os-vol-host-attr:host", None),
                      name=volume_info["display_name"],
                      server_ids=[att["server_id"]
                                  for att in volume_info["attachments"]]),
     }, namespace="/events")
Beispiel #27
0
 def report(self, absolute):
     cloud_name, src_image, dst_image = self.context
     LOG.info("Image %r uploaded on %3.2f%%",
              dst_image["id"], absolute * 100)
     events.emit("update", {
         "id": dst_image["id"],
         "type": "image",
         "cloud": cloud_name,
         "action": None,
         "progress": round(absolute * 100),
         "data": dict(dst_image),
     }, namespace="/events")
Beispiel #28
0
 def execute(self, attachment):
     self.cloud.nova.volumes.create_server_volume(
         attachment["server_id"],
         attachment["volume_id"],
         attachment["device"],
     )
     volume = utils.wait_for(
         attachment["volume_id"],
         self.cloud.cinder.volumes.get,
         value="in-use",
     )
     events.emit("update", event_from(self.cloud, volume),
                 namespace="/events")
     LOG.info("Reattached volume %(volume_id)s from server %(server_id)s",
              attachment)
Beispiel #29
0
 def revert(self, server_id, result, flow_failures):
     msg = ("Migration of server {} failed by reason {}"
            .format(server_id, result))
     LOG.warning(msg)
     events.emit("log", {
         "level": "error",
         "message": msg,
     }, namespace="/events")
     events.emit("update", {
         "id": server_id,
         "cloud": self.cloud.name,
         "type": "server",
         "progress": None,
         "action": None,
     }, namespace="/events")
Beispiel #30
0
 def spawn_event(self, server):
     LOG.info("Server spawned: %s", server)
     if HYPERVISOR_HOSTNAME_ATTR not in server:
         LOG.warning("Could not get %r attribute from server %r",
                     HYPERVISOR_HOSTNAME_ATTR, server)
         return
     hostname = server[HYPERVISOR_HOSTNAME_ATTR]
     events.emit("create", {
         "id": server["id"],
         "cloud": self.cloud.name,
         "type": "server",
         "action": "migration",
         "data": dict(server,
                      image_id=server["image"]["id"],
                      host_id=hostname),
     }, namespace="/events")