Beispiel #1
0
 def image_exist(self, image_name):
     """
     Verifies that the image id is available
     """
     try:
         service_vm = sdb.get_service_bindings(image_name)
         if service_vm:
             return True
         else:
             return False
     except Exception as exc:
         print exc
Beispiel #2
0
def connect_vm(tenant_id, vm_image_id, service_instance_id, *args):
    """
    Starts a VMs and is connected to southbound network
    """
    l2db.initialize()
    client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id)
    print (_("Connecting %(vm_image_id)s to Service "
             "%(service_instance_id)s") % locals())
    service_logic = servlogcs.ServicesLogistics()
    service_nets = sdb.get_service_bindings(service_instance_id)
    client.create_port(service_nets.mngnet_id)
    client.create_port(service_nets.nbnet_id)
    sb_port_id = client.create_port(service_nets.sbnet_id)
    LOG.debug(_("Operation 'create_port' executed."))
    new_port_id = sb_port_id[servconts.PORT][servconts.ID]
    try:
        create_vm_args = []
        create_vm_args.append(servconts.CREATE_VM_CMD)
        create_vm_args.append(vm_image_id)
        print _("Creating VM with image: %s") % (vm_image_id)
        process = utils.subprocess_popen(create_vm_args,
                                         stdout=subprocess.PIPE)
        result = process.stdout.readlines()
        tokens = re.search("i-[a-f0-9]*", str(result[1]))
        vm_name = tokens.group(0)
        print _("Image: %s instantiated successfully") % (vm_name)
    except Exception as exc:
        print exc

    service_logic.image_status(vm_name)
    print _("Completed")
    print _("Attaching Ports To VM Service interfaces")
    south_net = service_nets.sbnet_id
    attachment = client.show_port_attachment(south_net, new_port_id)
    attachment = attachment[servconts.ATTACHMENT][servconts.ID][:36]
    LOG.debug(_("Plugging virtual interface: %(attachment)s of VM "
                "%(vm_name)s into port: %(new_port_id)s on network: "
                "%(sbnet_id)s"), {'attachment': attachment,
                                  'vm_name': vm_name,
                                  'new_port_id': new_port_id,
                                  'sbnet_id': service_nets.sbnet_id})
    attach_data = {servconts.ATTACHMENT: {servconts.ID: '%s' % attachment}}
    client.attach_resource(service_nets.sbnet_id, new_port_id, attach_data)
    print _("Connect VM Ended")
def connect_vm(tenant_id, vm_image_id, service_instance_id, *args):
    """
    Starts a VMs and is connected to southbound network
    """
    l2db.initialize()
    client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id)
    print("Connecting %s to Service %s " % (vm_image_id, service_instance_id))
    service_logic = servlogcs.ServicesLogistics()
    service_nets = sdb.get_service_bindings(service_instance_id)
    client.create_port(service_nets.mngnet_id)
    client.create_port(service_nets.nbnet_id)
    sb_port_id = client.create_port(service_nets.sbnet_id)
    LOG.debug("Operation 'create_port' executed.")
    new_port_id = sb_port_id[servconts.PORT][servconts.ID]
    try:
        create_vm_args = []
        create_vm_args.append(servconts.CREATE_VM_CMD)
        create_vm_args.append(vm_image_id)
        print("Creating VM with image: %s" % (vm_image_id))
        process = utils.subprocess_popen(create_vm_args,
                                         stdout=subprocess.PIPE)
        result = process.stdout.readlines()
        tokens = re.search("i-[a-f0-9]*", str(result[1]))
        vm_name = tokens.group(0)
        print("Image: %s instantiated successfully" % (vm_name))
    except Exception as exc:
        print exc

    service_logic.image_status(vm_name)
    print "Completed"
    print "Attaching Ports To VM Service interfaces"
    south_net = service_nets.sbnet_id
    attachment = client.show_port_attachment(south_net, new_port_id)
    attachment = attachment[servconts.ATTACHMENT][servconts.ID][:36]
    LOG.debug(("Plugging virtual interface: %s of VM %s "
               "into port: %s on network: %s") %
              (attachment, vm_name, new_port_id, service_nets.sbnet_id))
    attach_data = {servconts.ATTACHMENT: {servconts.ID: '%s' % attachment}}
    client.attach_resource(service_nets.sbnet_id, new_port_id, attach_data)
    print("Connect VM Ended")
Beispiel #4
0
def delete_service(tenant_id, service_instance_id, *args):
    """
    Removes a service and all the network configuration
    """
    l2db.initialize()
    print("Terminating Service VM")
    service_logic = servlogcs.ServicesLogistics()
    vms_list = []
    vms_list.append(servconts.DELETE_VM_CMD)
    vms_list.append(service_instance_id)

    if not service_logic.image_exist(service_instance_id):
        print("Service VM does not exist")
        sys.exit()

    result = subprocess.call(vms_list)
    service_logic.image_shutdown_verification(service_instance_id)

    client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id)
    service_nets = sdb.get_service_bindings(service_instance_id)
    print("Terminating Ports and Networks")
    network_name = db.network_get(service_nets.mngnet_id)
    port_id_net = db.port_list(service_nets.mngnet_id)
    for ports_uuid in port_id_net:
        client.delete_port(service_nets.mngnet_id, ports_uuid.uuid)
    client.delete_network(service_nets.mngnet_id)
    network_name = db.network_get(service_nets.nbnet_id)
    port_id_net = db.port_list(service_nets.nbnet_id)
    for ports_uuid in port_id_net:
        client.delete_port(service_nets.nbnet_id, ports_uuid.uuid)
    client.delete_network(service_nets.nbnet_id)
    network_name = db.network_get(service_nets.sbnet_id)
    port_id_net = db.port_list(service_nets.sbnet_id)
    for ports_uuid in port_id_net:
        client.delete_port(service_nets.sbnet_id, ports_uuid.uuid)
    client.delete_network(service_nets.sbnet_id)
    service_list = sdb.remove_services_binding(service_instance_id)
    print("Configuration Removed Successfully")
Beispiel #5
0
def delete_service(tenant_id, service_instance_id, *args):
    """
    Removes a service and all the network configuration
    """
    l2db.initialize()
    print ("Terminating Service VM")
    service_logic = servlogcs.ServicesLogistics()
    vms_list = []
    vms_list.append(servconts.DELETE_VM_CMD)
    vms_list.append(service_instance_id)

    if not service_logic.image_exist(service_instance_id):
        print ("Service VM does not exist")
        sys.exit()

    result = subprocess.call(vms_list)
    service_logic.image_shutdown_verification(service_instance_id)

    client = Client(HOST, PORT, USE_SSL, format='json', tenant=tenant_id)
    service_nets = sdb.get_service_bindings(service_instance_id)
    print ("Terminating Ports and Networks")
    network_name = db.network_get(service_nets.mngnet_id)
    port_id_net = db.port_list(service_nets.mngnet_id)
    for ports_uuid in port_id_net:
        client.delete_port(service_nets.mngnet_id, ports_uuid.uuid)
    client.delete_network(service_nets.mngnet_id)
    network_name = db.network_get(service_nets.nbnet_id)
    port_id_net = db.port_list(service_nets.nbnet_id)
    for ports_uuid in port_id_net:
        client.delete_port(service_nets.nbnet_id, ports_uuid.uuid)
    client.delete_network(service_nets.nbnet_id)
    network_name = db.network_get(service_nets.sbnet_id)
    port_id_net = db.port_list(service_nets.sbnet_id)
    for ports_uuid in port_id_net:
        client.delete_port(service_nets.sbnet_id, ports_uuid.uuid)
    client.delete_network(service_nets.sbnet_id)
    service_list = sdb.remove_services_binding(service_instance_id)
    print ("Configuration Removed Successfully")