Esempio n. 1
0
    def __init__(self, tenancy_name):
        self.identity = Identity(tenancy_name)
        self.config = self.identity.config
        self.tenancy_id = self.config["tenancy"]
        self.report = ReportNetwork(tenancy_name)
        self.compute_client = oci.core.ComputeClient(self.config)
        self.block_storage_client = oci.core.BlockstorageClient(self.config)
        self.object_storage_client = oci.object_storage.ObjectStorageClient(self.config)
        self.instances = list()
        self.boot_volumes = list()
        self.block_volumes = list()
        self.buckets = list()
        self.objects = list()
        self.compartments = self.identity.compartments

        self.block_volume_attachments = list()
        self.boot_volume_attachments = list()

        self.set_buckets()
        self.set_total_volumes()
        self.set_total_boot_volumes()
        self.set_total_volume_attachments()
        self.set_total_boot_volume_attachments()

        self.initialize_connector()
Esempio n. 2
0
	def	__init__(self, room, beg, end, map) :
		self.coordinates = []
		self.coordinates.append(Identity("coordinates",'X',beg.x,beg.y,1,1))

		tmp_x = tmp_y = -1
		
		while (not self.coordinates[len(self.coordinates) - 1].isIn(end)):
			last = self.coordinates[ len( self.coordinates ) - 1]

			r = random.randint(0, 1)
			r2 = random.uniform(0, 10)

			if  r == 0 :
				if r2 < 7	 :
					tmp_x = last.x + 1 * self.sign(end.x-tmp_x)
				else :
					tmp_x = last.x - 1 * self.sign(end.x - tmp_x)
				
				tmp_y = last.y

			else :
				
				if r2 < 7 :
					tmp_y = last.y + 1 * self.sign(end.y - tmp_y)
				else :
					tmp_y = last.y - 1 * self.sign(end.y - tmp_y)
				tmp_x = last.x

			new = Identity ("coordinates", 'X', tmp_x, tmp_y, 1, 1)
			print len(self.coordinates), new, beg, end, new.isInList(room)
			if (not new.isInList(room)  or new.isIn(end)):
				self.coordinates.append( Identity ( "coordinates", 'X', tmp_x, tmp_y, 1, 1))
Esempio n. 3
0
 def __init__(self, TNode=None):
     self.__NodeWeight = SharedCounter.WEIGHT_START
     self.__NodeInput = None
     self.__Bais = random.uniform( SharedCounter.INITIAL_BAIS, SharedCounter.alpha)
     self.TNode = TNode
     self.LocalMax_Index = 0
     self.LocalMin_Index = 0
     self.LocalMax_Activation = 0
     self.LocalMin_Activation = 1
     Properties.__init__(self)
     Identity.__init__(self)
Esempio n. 4
0
class Report:
    def __init__(self, tenancy_name):
        self.identity = Identity(tenancy_name)
        self.fingerprint = self.identity.fingerprint
        self.private_path = self.identity.key_file
        self.tenancy_id = self.identity.compartment_id
        self.admin_id = self.identity.admin_user_id
        self.report = dict()
        self.user = User()
        self.report["local"] = list()
        self.report["service"] = list()
        self.report["inValid"] = list()
        self.report["localWithoutMFA"] = list()
        self.report_local()
        self.report_service()
        self.report_invalid()
        self.local_without_MFA()
        # self.export_json()

    def local_without_MFA(self):
        temp = self.identity.get_local_users()
        for t in temp:
            if (not self.user.is_user_mfa(self.private_path, self.tenancy_id,
                                          self.admin_id, t.id,
                                          self.fingerprint)):
                temp2 = {"name": t.name, "user_id": t.id}
                self.report["localWithoutMFA"].append(temp2)

    def report_local(self):
        temp = self.identity.get_local_users()
        for t in temp:
            temp2 = {"name": t.name, "user_id": t.id}
            self.report["local"].append(temp2)

    def report_service(self):
        temp = self.identity.get_service_users()
        for t in temp:
            temp2 = {"name": t.name, "user_id": t.id}
            self.report["service"].append(temp2)

    def report_invalid(self):
        temp = self.identity.get_invalid_users()
        for t in temp:
            temp2 = {"name": t.name, "user_id": t.id}
            self.report["inValid"].append(temp2)

    def export_json(self):
        with open('result.json', 'w') as fp:
            json.dump(self.report,
                      fp,
                      ensure_ascii=False,
                      indent=2,
                      sort_keys=True)
    def __init__(self, **kwargs):
        Identity.__init__(self)
        Container.__init__(self)
        NodeGraph.__init__(self)
        Position.__init__(self)

        self.NumTNode = kwargs.get('NumTNode')
        self.pass_counter = 1

        attr = SharedCounter.Counter
        for _ in range(attr, self.NumTNode + 1):  # For all tensors
            newTensor = TNode(layer=self)  # Create a new instance of tensor
            self.add(newTensor)  # add tensor in Container
    def __init__(self, **kwargs):
        '''Pass NumLayer=?,NumTensor=?'''

        Identity.__init__(self)
        Container.__init__(self)
        Position.__init__(self)

        self.NumLayers = kwargs.get('NumLayer')
        self.NumTensor = kwargs.get('NumTensor')
        self._Data = None
        # Model Initilization by private functions
        self.__InitLayers()
        self.__ConnectLayers()
        self.__ConnectTensors()
        self.__ConnectWeightsOfTensor()
Esempio n. 7
0
def Jacobi(matrix, target, iteration=5):
    """
    iterate throught the jacobi method to solve the system
    """

    Id = Identity(len(matrix.matrix))

    #exctract the Diagonal from the matrix
    Diag = []
    for i in range(len(matrix.matrix)):
        line = []
        for j in range(len(matrix.matrix)):
            if i == j:
                line.append(matrix.matrix[i][j])
            else:
                line.append(R(0))
        Diag.append(line)
    Diag = Matrix.Matrix(Diag)

    inv_diag = Diag.reverse_diag()

    X_k = []
    for i in range(len(matrix.matrix)):
        X_k.append([0])
    X_k = Matrix.Matrix(X_k)

    for i in range(iteration):
        print(i)
        X_k = ((Id - inv_diag * matrix) * X_k) + (inv_diag * target)
        # (I - D^-1 * A) * X_k + D^-1 * Y
        #erreur potentielle de calcul, ou systeme insolvable.
        print(X_k)
    return (X_k)
Esempio n. 8
0
 def __init__(self, tenancy_name):
     self.identity = Identity(tenancy_name)
     self.fingerprint = self.identity.fingerprint
     self.private_path = self.identity.key_file
     self.tenancy_id = self.identity.compartment_id
     self.admin_id = self.identity.admin_user_id
     self.report = dict()
     self.user = User()
     self.report["local"] = list()
     self.report["service"] = list()
     self.report["inValid"] = list()
     self.report["localWithoutMFA"] = list()
     self.report_local()
     self.report_service()
     self.report_invalid()
     self.local_without_MFA()
 def __init__(self, layer=None):
     #id class
     Identity.__init__(self)
     #A wraped graph instance
     NodeGraph.__init__(self)
     #A position identifier
     Position.__init__(self)
     #A wraped weight dictionary
     WeightDict.__init__(self)
     #Node input class
     _Activation.__init__(self, SharedCounter.INITIAL_ACTIVATION)
     #Node Bais class
     _Bais.__init__(self, SharedCounter.INITIAL_BAIS)
     #Activation function , set at time of model init.
     _ActivationFn.__init__(self)
     #properties for each tnode, for different optimizing algorithms.
     Properties.__init__(self)
     self.Layer = layer
Esempio n. 10
0
 def shortcut(self, nInputPlane, nOutputPlane, stride):
     useConv = self.shortcutType == 'C' or (self.shortcutType == 'B' and nInputPlane != nOutputPlane)
     if useConv:
         # 1x1 convolution
         return nn.Sequential(
             Convolution(nInputPlane, nOutputPlane, kernel_size = (1, 1), stride = stride, bias = False),
             SBatchNorm(nOutputPlane)
             )
     elif nInputPlane != nOutputPlane:
        # Strided, zero-padded identity shortcut
        return nn.Sequential(
            nn.SpatialAveragePooling(1, 1, stride, stride),
            Concat(1, [
                    Identity(),
                    nn.MulConstant(0)
                    ])
            )
     else:
        return Identity()
Esempio n. 11
0
 def __init__(self, tenancy_name):
     self.identity = Identity(tenancy_name)
     self.config = self.identity.config
     self.network_client = oci.core.VirtualNetworkClient(self.config)
     self.compartments = self.identity.compartments
     self.vcns = list()
     self.subnets = list()
     self.security_lists = list()
     self.vulnerable_security_lists = list()
     self.initialize()
Esempio n. 12
0
 def __init__(self, tenancy_name):
     self.instances = list()
     self.vnic_attachments = list()
     self.vnics = list()
     self.active_vnic_attachments = list()
     self.identity = Identity(tenancy_name)
     self.config = self.identity.config
     self.compute_client = oci.core.ComputeClient(self.config)
     self.network_client = oci.core.VirtualNetworkClient(self.config)
     self.initialize()
def makeModel():

    # recHitsModel will be an nn.Sequential module
    recHitsModel = rechitmodelutils.makeRecHitsModel(nstates[:2], filtsize, poolsize)

    # create input 'networks' for additional variables (such as track isolation variables)
    # taking the global variable additionalVars specified in a dataset file or modified
    # on the command line

    # TODO: could use a single input layer for the additional variables
    #       instead of individual ones

    from Identity import Identity
    from ParallelTable import ParallelTable
    from JoinTable import JoinTable

    #----------
    # combine nn output from convolutional layers for
    # rechits with track isolation variables
    #----------
    layers = []

    layers.append(ParallelTable( [ recHitsModel, Identity() ]  ))
    layers.append(JoinTable(1))

    #----------
    # common output part
    #----------

    # to print the shape at this point
    # layers.append(PrintLayer())

    layers.append(nn.Linear(320 + len(additionalVars), nstates[2]))
    nn.init.xavier_uniform(layers[-1].weight.data)

    layers.append(nn.ReLU())


    # output
    layers.append(nn.Linear(nstates[2], 1))
    nn.init.xavier_uniform(layers[-1].weight.data)

    # TODO: we could use logits instead (also requires
    #       different loss function)

    layers.append(nn.Sigmoid())

    result = nn.Sequential(*layers)

    return result
Esempio n. 14
0
    def getIdentityByUUID(self, uuid):
        """API request to get an identity based on its uuid

        Arguments:
            uuid {[string]} -- [unique identifier for an identity, associated with Amazon Rekognition]

        Returns:
            [Identity] -- [The identity labeled with the given uuid]
        """
        self.getTokens()
        api_url = '{0}identities/uuid/{1}'.format(self.api_url_base, uuid)
        response = self.session.get(api_url)
        if response.status_code != 200:
            if response.status_code != 404:
                raise APIError(response.status_code)
            else:
                raise APIErrorNotFound(response.status_code)
        loaded_json = json.loads(response.text)
        foundIdentity = Identity(loaded_json.get('firstname'), loaded_json.get('lastname'),
                                 loaded_json.get('mail'), loaded_json.get('uuid'), loaded_json.get('id'))
        return foundIdentity
Esempio n. 15
0
def lower(matrix):
    #pas fini
    nb_line = len(matrix.matrix)
    En = Identity(nb_line)
    for k in range(nb_line - 1):  #E_{n-1} ... E_{1}
        #Create empty matrix
        E = []
        for i in range(nb_line):
            E.append([])

        #Create E_{n}^{-1} matrix
        for column in range(nb_line):
            for line in range(nb_line):
                if column == line:  #in the diagonal
                    E[line].append(R(1))

                elif k == column and column < line:
                    E[line].append(matrix[line][k] / matrix[k][k])
                else:
                    E[line].append(R(0))
        E = Matrix.Matrix(E)
        En = En * E
        #---------------------
        #multiply matrix by E
        #---------------------
        E = E.matrix

        #Create E_{n}^{-1} matrix
        for column in range(nb_line):
            for line in range(nb_line):
                if column == line:  #in the diagonal
                    pass
                else:
                    E[column][line] = R(0) - E[column][line]
        #AFAIRE ! matrix deviens matrix * E_{n}
        E = Matrix.Matrix(E)
        matrix = E * matrix
        #-------------------------

    return En
Esempio n. 16
0
    def postIdentity(self, identity):
        """API request to post a new Identity on the WiFace API

        Arguments:
            identity {[Identity]} -- [identity to post]

        Raises:
            APIError: [request error]

        Returns:
            [Identity] -- [Identity created on the server]
        """
        self.getTokens()
        api_url = '{0}identities'.format(self.api_url_base)
        identity_json = {'firstname': identity.firstname,
                         'lastname': identity.lastname, 'mail': identity.mail, 'uuid': identity.uuid}
        response = self.session.post(api_url, json=identity_json)
        if response.status_code != 201:
            raise APIError(response.status_code)
        loaded_json = json.loads(response.text)
        identity = Identity(loaded_json.get('firstname'), loaded_json.get('lastname'),
                            loaded_json.get('mail'), loaded_json.get('uuid'), loaded_json.get('id'))
        return identity
Esempio n. 17
0
class Count:
    def __init__(self, tenancy_name):
        self.identity = Identity(tenancy_name)
        self.config = self.identity.config
        self.tenancy_id = self.config["tenancy"]
        self.report = ReportNetwork(tenancy_name)
        self.compute_client = oci.core.ComputeClient(self.config)
        self.block_storage_client = oci.core.BlockstorageClient(self.config)
        self.object_storage_client = oci.object_storage.ObjectStorageClient(self.config)
        self.instances = list()
        self.boot_volumes = list()
        self.block_volumes = list()
        self.buckets = list()
        self.objects = list()
        self.compartments = self.identity.compartments

        self.block_volume_attachments = list()
        self.boot_volume_attachments = list()

        self.set_buckets()
        self.set_total_volumes()
        self.set_total_boot_volumes()
        self.set_total_volume_attachments()
        self.set_total_boot_volume_attachments()

        self.initialize_connector()

    def initialize_connector(self):
        self.connections = mysql.connector.MySQLConnection(host= '150.136.145.149',
            user= '******',
            password= '******',
            database= 'cloudautomation',
            port= '1521',
            autocommit=True)

    def get_boot_volume_attachment_from_boot_volume(self, boot_volume_id):
        """Get VCN details from vcn_id"""
        try:
            return [boot_volume_attachment
            for boot_volume_attachment in self.boot_volume_attachments
            if boot_volume_attachment.boot_volume_id == boot_volume_id][0]
        except:
            return False

    def get_block_volume_attachment_from_block_volume(self, block_volume_id):
        """Get VCN details from vcn_id"""
        try:
            return [block_volume_attachment
            for block_volume_attachment in self.block_volume_attachments
            if block_volume_attachment.volume_id == block_volume_id][0]
        except:
            return False

    def update_subnet(self):
        for compartment in self.compartments:
            for vcn in self.report.network.get_vcns(compartment.id):
                for subnet in self.report.network.get_subnets(compartment.id, vcn.id):



                    mycursor = self.connections.cursor()
                    sql = [datetime.date.today().strftime("%Y-%m-%d"),
                    self.tenancy_id,subnet.id ,
                    subnet.display_name,
                    "subnet",
                    subnet.cidr_block,
                    subnet.availability_domain,
                    subnet.prohibit_public_ip_on_vnic,
                    subnet.vcn_id
                    ]

                    mycursor.callproc('addnetworkresources',sql)

    def update_volume(self):
        for boot in self.boot_volumes:
            attached_instance = ""
            instance_id = ""
            if self.get_boot_volume_attachment_from_boot_volume(boot.id):
                boot_attachment = self.get_boot_volume_attachment_from_boot_volume(boot.id)
                instance_id = boot_attachment.instance_id
                attached_instance = self.report.computeObj.get_instance(instance_id).display_name

            compartment_name = self.identity.get_compartment_path_name(boot.compartment_id)
            mycursor = self.connections.cursor()
            sql = [datetime.date.today().strftime("%Y-%m-%d"),
            self.tenancy_id,
            'bootVolume',
            boot.id,
            boot.size_in_gbs,
            attached_instance,
            instance_id,
            compartment_name,
            boot.display_name]

            mycursor.callproc('addVolume',sql)

        for block in self.block_volumes:
            attached_instance = ""
            instance_id = ""
            if self.get_block_volume_attachment_from_block_volume(block.id):
                block_attachment = self.get_block_volume_attachment_from_block_volume(block.id)
                instance_id = block_attachment.instance_id
                attached_instance = self.report.computeObj.get_instance(instance_id).display_name

            compartment_name = self.identity.get_compartment_path_name(block.compartment_id)
            mycursor = self.connections.cursor()
            sql = [datetime.date.today().strftime("%Y-%m-%d"),
            self.tenancy_id,
            'block',
            block.id,
            block.size_in_gbs,
            attached_instance,
            instance_id,
            compartment_name,
            block.display_name]

            mycursor.callproc('addVolume',sql)

        self.connections.close()




    def get_compute_instances(self, compartment_id):
        return oci.pagination.list_call_get_all_results(self.compute_client.list_instances,compartment_id, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY).data



    def update_compute(self):
        for vnic_attachment in self.report.computeObj.active_vnic_attachments:
            subnet = self.report.network.get_subnet(vnic_attachment.subnet_id)
            instance = self.report.computeObj.get_instance(vnic_attachment.instance_id)
            try:
                image = self.report.computeObj.compute_client.get_image(instance.image_id).data.display_name
            except:
                image = "Error image"
            vcn = self.report.network.get_vcn(subnet.vcn_id)
            if instance.compartment_id == self.report.network.identity.compartment_id:
                compartment_name = "Root"
            else:
                compartment_name = [
                    compartment.name
                    for compartment in self.compartments
                    if compartment.id == instance.compartment_id
                ][0]
            mycursor = self.connections.cursor()
            sql = [datetime.date.today().strftime("%Y-%m-%d"),
            self.tenancy_id,instance.id ,
            instance.display_name,
            instance.region,
            instance.availability_domain,
            instance.shape,
            instance.time_created,
            vcn.id,
            vcn.display_name,
            image,
            self.report.computeObj.get_vnic(vnic_attachment.vnic_id).public_ip,
            self.report.computeObj.get_vnic(vnic_attachment.vnic_id).private_ip,
            instance.compartment_id,
            compartment_name,
            vnic_attachment.vnic_id,
            vnic_attachment.subnet_id,
            "",
            "",
            ""
            ]

            mycursor.callproc('addCompute',sql)

            # self.connections.close()


    def update_vcns(self):
        for compartment in self.identity.compartments:
            for vcn in self.report.network.get_vcns(compartment.id):

                mycursor = self.connections.cursor()
                sql = [datetime.date.today().strftime("%Y-%m-%d"),
                self.tenancy_id,vcn.id ,
                vcn.display_name,
                vcn.cidr_block,
                vcn.compartment_id,
                compartment.name
                ]

                mycursor.callproc('addvcn',sql)

                # self.connections.close()
    def set_total_vms(self):
        for i in self.identity.compartments:
            for j in self.get_compute_instances(i.id):
                self.instances.append(j)
        for j in self.get_compute_instances(self.identity.compartment_id):
            self.instances.append(j)

    def get_total_vms(self):
        return self.instances

    def get_boot_volumes(self, availability_domain, compartment_id):
        return oci.pagination.list_call_get_all_results(self.block_storage_client.list_boot_volumes, availability_domain, compartment_id, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY).data

    def set_total_boot_volumes(self):
        for i in self.identity.availability_domains:
            for j in self.identity.compartments:
                for k in self.get_boot_volumes(i.name, j.id):
                    self.boot_volumes.append(k)
        for i in self.identity.availability_domains:
            for k in self.get_boot_volumes(i.name, self.identity.compartment_id):
                self.boot_volumes.append(k)

    def get_total_boot_volumes(self):
        return self.boot_volumes

    def get_volumes(self, compartment_id):
        return oci.pagination.list_call_get_all_results(self.block_storage_client.list_volumes, compartment_id, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY).data

    def set_total_volumes(self):
        for j in self.identity.compartments:
            for k in self.get_volumes(j.id):
                self.block_volumes.append(k)
        for k in self.get_volumes(self.identity.compartment_id):
            self.block_volumes.append(k)

    def get_total_volumes(self):
        return self.block_volumes

    def get_volume_attachments(self, compartment_id):
        return oci.pagination.list_call_get_all_results(self.compute_client.list_volume_attachments, compartment_id, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY).data

    def set_total_volume_attachments(self):
        for j in self.identity.compartments:
            for k in self.get_volume_attachments(j.id):
                self.block_volume_attachments.append(k)
        for k in self.get_volume_attachments(self.identity.compartment_id):
            self.block_volume_attachments.append(k)

    def get_total_volume_attachments(self):
        return self.block_volume_attachments

    def get_boot_volume_attachments(self,availability_domain, compartment_id):
        return oci.pagination.list_call_get_all_results(self.compute_client.list_boot_volume_attachments,availability_domain, compartment_id, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY).data

    def set_total_boot_volume_attachments(self):
        for i in self.identity.availability_domains:
            for j in self.identity.compartments:
                for k in self.get_boot_volume_attachments(i.name,j.id):
                    self.boot_volume_attachments.append(k)
        for i in self.identity.availability_domains:
            for k in self.get_boot_volume_attachments(i.name, self.identity.compartment_id):
                self.boot_volume_attachments.append(k)

    def get_total_boot_volume_attachments(self):
        return self.boot_volume_attachments


    def get_total_compartments(self):
        return self.compartments

    def list_buckets(self, namespace_name, compartment_id):
        return oci.pagination.list_call_get_all_results(self.object_storage_client.list_buckets, namespace_name, compartment_id, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY).data

    def list_objects(self, namespace_name, bucket_name):
        return oci.pagination.list_call_get_all_results(self.object_storage_client.list_objects, namespace_name, bucket_name, retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY).data

    def set_buckets(self):
        for j in self.identity.compartments:
            for i in self.list_buckets("orasenatdhubsred01", j.id):
                self.buckets.append(i)
        for i in self.list_buckets("orasenatdhubsred01", self.identity.compartment_id):
            self.buckets.append(i)


    def update_objects(self):

        for j in self.buckets:
            self.connections = mysql.connector.MySQLConnection(host= '150.136.145.149',
                user= '******',
                password= '******',
                database= 'cloudautomation',
                port= '1521',
                autocommit=True)
            object = self.object_storage_client.get_bucket("orasenatdhubsred01", j.name).data
            compartment_name = self.identity.get_compartment_path_name(object.compartment_id)
            is_public = 1
            if object.public_access_type== "NoPublicAccess":
                is_public = 0
            # print(object)
            mycursor = self.connections.cursor()
            sql = [datetime.date.today().strftime("%Y-%m-%d"),
            object.name,
            len(self.list_objects("orasenatdhubsred01", j.name).objects),
            object.approximate_size,
            object.time_created,
            object.storage_tier,
            is_public,
            compartment_name,
            self.tenancy_id
            ]

            mycursor.callproc('add_object_storage',sql)

        self.connections.close()
Esempio n. 18
0
	def __init__ ( self, x, y, size_x, size_y) :
		Identity.__init__(self, "Room",'.', x, y, size_x, size_y)
		self.nbDoor = random.randint(1, 3)
		self.door = []
		self.generateDoors()
Esempio n. 19
0
	def __init__( self, type, character, x, y, nbLife) :
		Identity.__init__(self, type, character, x, y, 1, 1)
		self.nbLife = nbLife
 def refillIdentityPool(self):
     for i in range(IdentityProvider.BASE_IDENTITY_SIZE):
         self.identityPool.add(Identity(choice(UserAgentsFirefox.list)))        
Esempio n. 21
0
	def __init__( self, x , y) :
		Identity.__init__(self, "Door", '+',x, y, 1, 1)
		self.isConnected = False
Esempio n. 22
0
	def __init__(self, sz_x, sz_y):
		Identity.__init__(self, "Map", ' ', 0, 0, sz_x, sz_y)
		self.room = []
		self.corridor = []