예제 #1
0
    def Appliances(self, request, context):  # noqa: N802
        images = self.h.list_images()
        for i in images:
            appliance_image_list = self.h.image_dict_to_appliance_message(i)
            appliance_dict = appliance_image_list[0]
            appliance_dict["image"] = cloudkeeper_pb2.Image(
                **appliance_image_list[1])

            yield cloudkeeper_pb2.Appliance(**appliance_dict)
def run():
    # NOTE(gRPC Python Team): .close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    with grpc.insecure_channel('127.0.0.1:50051') as channel:
        # channel = grpc.insecure_channel('localhost:50051')
        stub = cloudkeeper_pb2_grpc.CommunicatorStub(channel)
        response = stub.AddAppliance(cloudkeeper_pb2.Appliance(identifier='2a5451eb-91f3-46a2-95a7-9cff7362d553',
                                                                description='simulated image for testing',
                                                                mpuri='asd',
                                                                group='group1',
                                                                ram=2048,
                                                                core=4,
                                                                version='0.0.5867',
                                                                architecture='x86_64',
                                                                operating_system='OpenSuse',
                                                                vo='some.dummy.vo',
                                                                expiration_date=1556582400,
                                                                image_list_identifier='76fdee70-8119-5d33-aaaa-3c57e1c60df1',
                                                                base_mpuri='',
                                                                appid='993',
                                                                digest='digest',
                                                                image=cloudkeeper_pb2.Image(
                                                                        mode=cloudkeeper_pb2.Image.LOCAL,
                                                                        format=cloudkeeper_pb2.Image.QCOW2,
                                                                        container_format=cloudkeeper_pb2.Image.AKI,
                                                                        location='tests/demo_images/cirros-0.4.0-x86_64-disk.img',
                                                                        digest='SHA',
                                                                        uri='https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img',
                                                                        checksum='checksumvalue',
                                                                        size=512,
                                                                        username='******',
                                                                        password='******',
                                                                        )
                                                                )
                                        )

        # response = stub.UpdateAppliance(cloudkeeper_pb2.Appliance(
        #                                                         identifier='9092cfcd-cd53-44aa-9f3b-88a6367dcb59',
        #                                                         image=cloudkeeper_pb2.Image(
        #                                                                 mode=cloudkeeper_pb2.Image.LOCAL,
        #                                                                 format=cloudkeeper_pb2.Image.QCOW2,
        #                                                                 container_format=cloudkeeper_pb2.Image.BARE,
        #                                                                 location='tests/demo_images/cirros-0.4.0-x86_64-disk.img',
        #                                                                 digest='SHA',
        #                                                                 uri='https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img',
        #                                                                 checksum='checksumvalue',
        #                                                                 size=512,
        #                                                                 username='******',
        #                                                                 password='******',
        #                                                                 )
        #                                                         )
        #                                 )
        # for i in stub.Appliances(cloudkeeper_pb2.ImageListIdentifier()):
        #         print(i)
        print("Greeter client received: " + str(response))
예제 #3
0
    def update_image(self, request, appliance_id):
        """
        Update image in Appliance
        """

        old_appliance = self.get_appliance(appliance_id)

        new_appliance_list = self.image_dict_to_appliance_message(old_appliance)

        self.remove_appliance(appliance_id)

        self.register_appliance(cloudkeeper_pb2.Appliance(**new_appliance_list[0], image=request))
def run():
    # NOTE(gRPC Python Team): .close() is possible on a channel and should be
    # used in circumstances in which the with statement does not fit the needs
    # of the code.
    with grpc.insecure_channel('127.0.0.1:50051') as channel:
        # channel = grpc.insecure_channel('localhost:50051')
        stub = cloudkeeper_pb2_grpc.CommunicatorStub(channel)

        #TODO: finish Appliances method in core_connector, so it could use find()

        name_in_list = True

        while name_in_list:
            gen_name = gen_rand_name()
            appliances_names = get_appliances_titles_list(stub)
            name_in_list = if_name_in_list(gen_name, appliances_names)

        print('Using name for testing: ' + str(gen_name))

        try:
            new_appliance = stub.AddAppliance(
                cloudkeeper_pb2.Appliance(**Appliance_dict,
                                          title=str(gen_name)))
            print(new_appliance)
        except Exception as err:
            print(
                'Error while creating appliance using AddAppliance method \n\n Error: '
                + str(err))
            exit()

        appliances_names = get_appliances_titles_list(stub)
        name_in_list = if_name_in_list(gen_name, appliances_names)

        if name_in_list:
            print('Added')
        else:
            print(
                'Error: Your AddAppliance method doesn\'t work well... Appliance wasn\'t added'
            )

        print('Description of appliance: ' +
              str(get_appliance(stub, gen_name).description))

        try:
            new_appliance = stub.UpdateApplianceMetadata(
                cloudkeeper_pb2.Appliance(identifier=str(
                    get_appliance(stub, gen_name).identifier),
                                          description='updated_testing_image'))
        except Exception as err:
            print(
                'Error while updating appliance using UpdateApplianceMetadata method \n\n Error: '
                + str(err))
            exit()

        if str(get_appliance(stub,
                             gen_name).description) == 'updated_testing_image':
            print('Updated, Description of appliance: ' +
                  str(get_appliance(stub, gen_name).description))
        else:
            print(
                'Error: Your UpdateApplianceMetadata method doesn\'t work well... Appliance wasn\'t updated'
            )

        # print('Container of image: ' + str(get_appliance(stub, gen_name).cloudkeeper_pb2.Image.Format.Value))

        Image_dict['container_format'] = cloudkeeper_pb2.Image.BARE

        try:
            new_appliance = stub.UpdateAppliance(
                cloudkeeper_pb2.Appliance(
                    identifier=str(get_appliance(stub, gen_name).identifier),
                    image=cloudkeeper_pb2.Image(**Image_dict)))
        except Exception as err:
            print(
                'Error while updating image using UpdateAppliance method \n\n Error: '
                + str(err))
            exit()

        if get_appliance(
                stub,
                gen_name).image.container_format == cloudkeeper_pb2.Image.BARE:
            print('Updated, Size of Image: ' +
                  str(get_appliance(stub, gen_name).image.size))
        else:
            print(
                'Error: Your UpdateAppliance method doesn\'t work well... Image wasn\'t updated'
            )

        try:
            new_appliance = stub.RemoveAppliance(
                cloudkeeper_pb2.Appliance(
                    identifier=str(get_appliance(stub, gen_name).identifier)))
        except Exception as err:
            print(
                'Error while removing appliance using RemoveAppliance method \n\n Error: '
                + str(err))
            exit()

        appliances_names = get_appliances_titles_list(stub)
        name_in_list = if_name_in_list(gen_name, appliances_names)

        if name_in_list:
            print(
                'Error: Your RemoveAppliance method doesn\'t work well... Appliance wasn\'t removed'
            )
            print('!!! DON\'T FORGET TO REMOVE TESTING APPLIANCE MANUALLY !!!')
        else:
            print('Removed')