Beispiel #1
0
    def attach_vcenter(self,
                       vc_server_name,
                       vc_server_host,
                       vc_admin_user,
                       vc_admin_pwd,
                       is_enabled,
                       vc_root_folder=None,
                       nsx_server_name=None,
                       nsx_host=None,
                       nsx_admin_user=None,
                       nsx_admin_pwd=None):
        """Register (attach) a VirtualCenter server (also known as VimServer).

        :param str vc_server_name: vc server name (virtual center name).
        :param str vc_server_host: FQDN or IP address of vc host.
        :param str vc_admin_user: vc admin user.
        :param str vc_admin_pwd: vc admin password.
        :param str is_enabled: true if VC is to be enabled.
        :param str vc_root_folder: vc root folder.
        :param str nsx_server_name: NSX server name.
        :param str nsx_host: FQDN or IP address of NSX host.
        :param str nsx_admin_user: NSX admin user.
        :param str nsx_admin_pwd: NSX admin password.

        :return: an object containing REGISTER_VC_SERVER_PARAMS XML data that
            represents the newly registered (attached) VimServer.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        register_vc_server_params = E_VMEXT.RegisterVimServerParams()
        vc_server = E_VMEXT.VimServer(name=vc_server_name)
        vc_server.append(E_VMEXT.Username(vc_admin_user))
        vc_server.append(E_VMEXT.Password(vc_admin_pwd))
        vc_server_host_url = urlparse(vc_server_host)
        if vc_server_host_url.netloc is not '':
            vc_server.append(E_VMEXT.Url(vc_server_host))
        else:
            vc_server.append(E_VMEXT.Url('https://' + vc_server_host + ':443'))
        vc_server.append(E_VMEXT.IsEnabled(is_enabled))
        if vc_root_folder is not None:
            vc_server.append(E_VMEXT.rootFolder(vc_root_folder))
        register_vc_server_params.append(vc_server)
        if nsx_server_name is not None:
            nsx_manager = E_VMEXT.ShieldManager(name=nsx_server_name)
            nsx_manager.append(E_VMEXT.Username(nsx_admin_user))
            nsx_manager.append(E_VMEXT.Password(nsx_admin_pwd))
            nsx_host_url = urlparse(nsx_host)
            if nsx_host_url.netloc is not '':
                nsx_manager.append(E_VMEXT.Url(nsx_host))
            else:
                nsx_manager.append(E_VMEXT.Url('https://' + nsx_host + ':443'))
            register_vc_server_params.append(nsx_manager)

        return self.client.\
            post_linked_resource(resource=self.extension.get_resource(),
                                 rel=RelationType.ADD,
                                 media_type=EntityType.
                                 REGISTER_VC_SERVER_PARAMS.value,
                                 contents=register_vc_server_params)
Beispiel #2
0
    def attach_vcenter(self,
                       vc_server_name,
                       vc_server_host,
                       vc_admin_user,
                       vc_admin_pwd,
                       vc_root_folder=None,
                       nsx_server_name=None,
                       nsx_host=None,
                       nsx_admin_user=None,
                       nsx_admin_pwd=None,
                       is_enabled=None):
        """Register (attach) a VirtualCenter server (also known as VimServer).

        :param: vc_server_name: (str): vc server name (virtual center name).
        :param: vc_server_host: (str): FQDN or IP address of vc host.
        :param: vc_admin_user: (str): vc admin user.
        :param: vc_admin_pwd: (str): vc admin password.
        :param: vc_root_folder: (str): vc root folder.
        :param: nsx_server_name: (str): NSX server name.
        :param: nsx_host (str): FQDN or IP address of NSX host.
        :param: nsx_admin_user: (str): NSX admin user.
        :param: nsx_admin_pwd: (str): NSX admin password.
        :return: A :class:lxml.objectify.StringElement object describing the
        :        newly registered (attached) VimServer.
        """
        register_vc_server_params = E_VMEXT.RegisterVimServerParams()
        vc_server = E_VMEXT.VimServer(name=vc_server_name)
        vc_server.append(E_VMEXT.Username(vc_admin_user))
        vc_server.append(E_VMEXT.Password(vc_admin_pwd))
        vc_server.append(E_VMEXT.Url('https://' + vc_server_host + ':443'))
        if is_enabled is not None:
            vc_server.append(E_VMEXT.IsEnabled(is_enabled))
        if vc_root_folder is not None:
            vc_server.append(E_VMEXT.rootFolder(vc_root_folder))
        register_vc_server_params.append(vc_server)
        if nsx_server_name is not None:
            nsx_manager = E_VMEXT.ShieldManager(name=nsx_server_name)
            nsx_manager.append(E_VMEXT.Username(nsx_admin_user))
            nsx_manager.append(E_VMEXT.Password(nsx_admin_pwd))
            nsx_manager.append(E_VMEXT.Url('https://' + nsx_host + ':443'))
            register_vc_server_params.append(nsx_manager)

        return self.client.\
            post_linked_resource(resource=self.extension.get_resource(),
                                 rel=RelationType.ADD,
                                 media_type=EntityType.
                                 REGISTER_VC_SERVER_PARAMS.value,
                                 contents=register_vc_server_params)
Beispiel #3
0
    def update(self,
               name,
               new_name=None,
               url=None,
               username=None,
               password=None):
        """Update the connected NSX-T Manager.

        :param str name: name of the NSX-T Manager.
        :param str new_name: name of the NSX-T Manager
        :param str url: NSX-T Manager URL Endpoint
        :param str username: NSX-T Manager user name
        :param str password: NSX-T Manager password

        :rtype: lxml.objectify.ObjectifiedElement
        """
        nsxt_manager = self.get(name)
        new_name = new_name or name
        nsxtManagerParams = E_VMEXT.NsxTManager(name=new_name)
        if username:
            nsxtManagerParams['Username'] = E_VMEXT.Username(username)
        if password:
            nsxtManagerParams['Password'] = E_VMEXT.Password(password)
        if url:
            nsxtManagerParams['Url'] = E_VMEXT.Url(url)

        return self.client.put_linked_resource(nsxt_manager, RelationType.EDIT,
                                               EntityType.NSXT_MANAGER.value,
                                               nsxtManagerParams)
Beispiel #4
0
    def add(self, name, url, username, password):
        """Add NSX-T Manager with vCD.

        :param str name: name of the NSX-T Manager.
        :param str url: NSX-T Manager URL Endpoint
        :param str username: NSX-T Manager user name
        :param str password: NSX-T Manager password

        :rtype: lxml.objectify.ObjectifiedElement
        """
        nsxtManagerParams = E_VMEXT.NsxTManager(E_VMEXT.Username(username),
                                                E_VMEXT.Password(password),
                                                E_VMEXT.Url(url),
                                                name=name)
        return self.client.post_linked_resource(self.get_resource(),
                                                RelationType.ADD,
                                                EntityType.NSXT_MANAGER.value,
                                                nsxtManagerParams)
Beispiel #5
0
    def register_nsxt_manager(self,
                              nsxt_manager_name,
                              nsxt_manager_url,
                              nsxt_manager_username,
                              nsxt_manager_password,
                              nsxt_manager_description=None):
        """Register a NSX-T manager.

        :param str nsxt_manager_name: name of NSX-T manager.
        :param str nsxt_manager_url: URL of NSX-T manager server.
        :param str nsxt_manager_username: username of NSX-T manager admin.
        :param str nsxt_manager_password: password of NSX-T manager admin.
        :param str nsxt_manager_description: description of NSX-T manager.

        :return: an object containing XML data the newly registered NSX-T
            manager.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        payload = E_VMEXT.NsxTManager(name=nsxt_manager_name)
        if (nsxt_manager_description is not None):
            payload.append(E.Description(nsxt_manager_description))
        payload.append(E_VMEXT.Username(nsxt_manager_username))
        payload.append(E_VMEXT.Password(nsxt_manager_password))
        payload.append(E_VMEXT.Url(nsxt_manager_url))

        nsxt_manager_resource = self.client.get_linked_resource(
            resource=self.extension.get_resource(),
            rel=RelationType.DOWN,
            media_type=EntityType.NETWORK_MANAGERS.value)

        return self.client.\
            post_linked_resource(resource=nsxt_manager_resource,
                                 rel=RelationType.ADD,
                                 media_type=EntityType.NSXT_MANAGER.value,
                                 contents=payload)