예제 #1
0
 def vm_info(self,projects):
     dic_hosts = {}
     keystone = KeystoneClient()
     attr_host = 'OS-EXT-SRV-ATTR:host'
     host_statistics = self.metrics(projects[0])
     keys = host_statistics.keys()
     for host in keys:
         dic_hosts[host] = {'Total':host_statistics[host]['Total'],'Info_project':{}, 'Livre': [a - b for a,b in zip(host_statistics[host]['Total'],host_statistics[host]['Em uso']) ] , 'vms':{} , 'nomes':{} }
     for p in projects:
         from novaclient.v1_1 import client # nova client v3 raises exception for this
         nova = client.Client(self.__os_username, self.__os_password, p, self.__os_auth_url)
         flavors = self.flavor_information(p)
         project_id = keystone.get_tenant_id(p)
         vm_list =  self.project_instance(project_id)
         list_instances =[]
         for vm in vm_list:
             dic_hosts[vm['OS-EXT-SRV-ATTR:hypervisor_hostname']]['vms'][vm['id']] = flavors[vm['flavor']['id']]
             dic_hosts[vm['OS-EXT-SRV-ATTR:hypervisor_hostname']]['nomes'][vm['id']] = vm['name']
             list_instances.append(vm['id'])
             if(str(p) not in dic_hosts[vm['OS-EXT-SRV-ATTR:hypervisor_hostname']]['Info_project'].keys()):
                 dic_hosts[vm['OS-EXT-SRV-ATTR:hypervisor_hostname']]['Info_project'][str(p)] = [vm['id']]
             else:
                 dic_hosts[vm['OS-EXT-SRV-ATTR:hypervisor_hostname']]['Info_project'][str(p)].append(vm['id'])
     lista_ordenada = []
     dic_ord = sorted( dic_hosts.items(), key=lambda x: (  len( x[1]['vms'].keys() )==0, -x[1]['Livre'][0] ))
     for e in dic_ord:
         dic_aux = {}
         dic_aux[e[0]] = e[1]
         lista_ordenada.append(dic_aux)
     lista_ordenada2 = lista_ordenada[:]
     for dic in lista_ordenada:
         if len( dic[dic.keys()[0]]['vms'].keys()) == 0:
            lista_ordenada2.remove(dic)
            lista_ordenada2.insert(0,dic)
     return lista_ordenada2 
예제 #2
0
 def setup_clients(self):
     """
       A method to seting up authentication and necessary clients for the tool - Called by Constructor
       """
     auth = Authentication()
     self.novaclient = NovaClient(auth)
     self.keystoneclient = KeystoneClient(auth)
    def __init__(self, url, token, key):
        parsed_url = urlparse(url)
        server = '{}://{}'.format(parsed_url.scheme, parsed_url.netloc)

        self._umbrella_client = UmbrellaClient(server, token, key)

        self._keystone_client = KeystoneClient()
        self._keystone_client.set_resource_url(url)
예제 #4
0
    def __init__(self, url, credentials):
        parsed_url = urlparse(url)
        server = '{}://{}'.format(parsed_url.scheme, parsed_url.netloc)

        self._umbrella_client = UmbrellaClient(server, credentials['token'],
                                               credentials['key'])

        self._keystone_client = KeystoneClient()
        self._keystone_client.set_resource_url(url)
        self._keystone_client.set_app_id(credentials['app_id'])
예제 #5
0
파일: cluster.py 프로젝트: vhnuuh/pyutil
 def __init__(self, user, password, auth_url, az):
     self.nova_client = NovaClient(user, password, auth_url)
     self.cinder_client = CinderClient(user, password, auth_url)
     self.neutron_client = NeutronClient(user, password, auth_url)
     self.keystone_client = KeystoneClient(user, password, auth_url)
     self.az = az
     self._set_hostname()
예제 #6
0
class JointClient():
    def __init__(self, url, credentials):
        parsed_url = urlparse(url)
        server = '{}://{}'.format(parsed_url.scheme, parsed_url.netloc)

        self._umbrella_client = UmbrellaClient(server, credentials['token'],
                                               credentials['key'])

        self._keystone_client = KeystoneClient()
        self._keystone_client.set_resource_url(url)
        self._keystone_client.set_app_id(credentials['app_id'])

    def check_role(self, role):
        self._umbrella_client.check_role(role)
        self._keystone_client.check_role(role)

    def grant_permission(self, customer, role):
        self._umbrella_client.grant_permission(customer, role)
        self._keystone_client.grant_permission(customer, role)

    def revoke_permission(self, customer, role):
        self._umbrella_client.revoke_permission(customer, role)
        self._keystone_client.revoke_permission(customer, role)
class JointClient()

    def __init__(self, url, token, key):
        parsed_url = urlparse(url)
        server = '{}://{}'.format(parsed_url.scheme, parsed_url.netloc)

        self._umbrella_client = UmbrellaClient(server, token, key)

        self._keystone_client = KeystoneClient()
        self._keystone_client.set_resource_url(url)
    
    def check_role(self, role):
        self._umbrella_client.check_role(role)
        self._keystone_client.check_role(role)
    
    def grant_permission(self, customer, role):
        self._umbrella_client.grant_permission(customer, role)
        self._keystone_client.grant_permission(customer, role)
    
    def revoke_permission(self, customer, role):
        self._umbrella_client.revoke_permission(customer, role)
        self._keystone_client.revoke_permission(customer, role)
예제 #8
0
    def on_post_product_spec_validation(self, provider, asset):
        kc = KeystoneClient(asset.get_url(), is_url=True)
        kc.check_ownership(provider.name)
        mastermind = asset.meta_info['configuration_template']
        err_list = self._validate(mastermind, self._yaml_validator)

        if len(err_list):
            raise ValueError("Found errors in mastermind.yml: "
                             ' '.join(err_list))

        asset.meta_info.update({
            'api_url': kc.get_api_url(),
            'app_id': kc.get_app_id()
        })

        asset.save()
예제 #9
0
class VMsforHost(object):
    """
      A base class for the tool.
      """
    def __init__(self):
        """
          Constructor that validates arguments and setup necessary clients needed for the tool
          """
        self.check_arguments()
        self.setup_clients()

    def check_arguments(self):
        """
          A method to validate arguments - Called by Constructor
          """
        parser = ChildArgParser()
        parser.add_argument("--host", required=True, help='FQDN required!')
        self.args = parser.parse_args()
        parser.validate(self.args)

    def setup_clients(self):
        """
          A method to seting up authentication and necessary clients for the tool - Called by Constructor
          """
        auth = Authentication()
        self.novaclient = NovaClient(auth)
        self.keystoneclient = KeystoneClient(auth)

    def print_vms_for_host(self):
        """
          A method to print the VMs specific to the compute host
          """
        vms = self.novaclient.get_vms_for_host(self.args.host)
        users = self.keystoneclient.get_user_dict()
        for vm in vms:
            print "%-45s: %-15s" % (vm.name, users[vm.user_id].name)
예제 #10
0
    def _get_keystone_client(self, credentials):
        keystone_client = KeystoneClient()
        keystone_client.set_app_id(credentials['app_id'])

        return keystone_client
예제 #11
0
    def _get_keystone_client(self, url, credentials):
        keystone_client = KeystoneClient()
        keystone_client.set_resource_url(url)
        keystone_client.set_app_id(credentials['app_id'])

        return keystone_client
예제 #12
0
 def on_product_suspension(self, asset, contract, order):
     kc = KeystoneClient(asset.meta_info['app_id'])
     kc.revoke_permission(order.customer, 'owner')
예제 #13
0
 def on_product_acquisition(self, asset, contract, order):
     kc = KeystoneClient(asset.meta_info['app_id'])
     kc.grant_permission(order.customer, 'owner')
예제 #14
0
파일: cluster.py 프로젝트: vhnuuh/pyutil
class Cluster(object):
    def __init__(self, user, password, auth_url, az):
        self.nova_client = NovaClient(user, password, auth_url)
        self.cinder_client = CinderClient(user, password, auth_url)
        self.neutron_client = NeutronClient(user, password, auth_url)
        self.keystone_client = KeystoneClient(user, password, auth_url)
        self.az = az
        self._set_hostname()

    def _set_hostname(self):
        self.hostname = socket.gethostname()

    def list_all_instance_name(self):
        return self.nova_client.list_all_name()

    def list_local_instance(self):
        return self.nova_client.list_local(self.hostname)

    def delete(self, instance):
        self.nova_client.delete(instance.id)

    def pause(self, instance):
        self.nova_client.pause(instance.id)

    def unpause(self, instance):
        self.nova_client.unpause(instance.id)

    def boot(self, instance, image_mapping, volume_mappings, project):
        # create ports
        ports = []
        for port in instance.ports:
            ports.append(self.neutron_client.create_port(port['mac'], port['ip'], project))

        # create vm
        self.nova_client.boot(instance, image_mapping,
                              volume_mappings, ports, project, self.az)

    def get_project(self, id=None, name=None):
        if id:
            return self.keystone_client.get_project(id)

        projects = self.keystone_client.list_projects()
        project = filter(lambda x: x.name == name, projects)
        if project:
            return project[0]
        else:
            return None

    def create_project(self, name):
        return self.keystone_client.create_project(name)

    def get_local_image_file(self, instance):
        return os.path.join(IMAGE_DIR, instance.id, 'disk')

    def list_volume(self, instance):
        volumes = []
        attachments = self.nova_client.list_volumes(instance.id)
        for attachment in attachments:
            volume = self.cinder_client.get(attachment.id)
            volume.cluster = self
            volumes.append(volume)
        return volumes

    def clean(self, image_mapping, volume_mappings):
        try:
            if image_mapping:
                self.cinder_client.delete(image_mapping.dest_volume_uuid)
            for volume_mapping in volume_mappings:
                self.cinder_client.delete(volume_mapping.dest_volume_uuid)
        except Exception as ex:
            print ex
    def _get_keystone_client(self, url, token, key):
        keystone_client = KeystoneClient()
        keystone_client.set_resource_url(url)

        return keystone_client